Skip to content

Instantly share code, notes, and snippets.

@thekalinga
Created March 25, 2021 11:26
Show Gist options
  • Save thekalinga/922998ecffc31895b48e80f45862c16f to your computer and use it in GitHub Desktop.
Save thekalinga/922998ecffc31895b48e80f45862c16f to your computer and use it in GitHub Desktop.
Scroll.in ad remover
// ==UserScript==
// @name Scroll ad remover
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://scroll.in/article/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function undo() {
removeClass(document.getElementsByTagName('body')[0], 'toggle');
toggle.src = showNavIcon;
}
function apply() {
addClass(document.getElementsByTagName('body')[0], 'toggle');
toggle.src = hideNavIcon;
}
var showing = false;
var hideNavIcon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+DQo8c3ZnDQogICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciDQogICB3aWR0aD0iMTAwJSINCiAgIGhlaWdodD0iMTAwJSINCiAgIHZpZXdCb3g9IjAgMCAyMDQ4IDE3OTIiPg0KICA8cGF0aA0KICAgICBkPSJNMCA4OTZxMC0xMzAgNTEtMjQ4LjV0MTM2LjUtMjA0IDIwNC0xMzYuNSAyNDguNS01MWg3NjhxMTMwIDAgMjQ4LjUgNTF0MjA0IDEzNi41IDEzNi41IDIwNCA1MSAyNDguNS01MSAyNDguNS0xMzYuNSAyMDQtMjA0IDEzNi41LTI0OC41IDUxaC03NjhxLTEzMCAwLTI0OC41LTUxdC0yMDQtMTM2LjUtMTM2LjUtMjA0LTUxLTI0OC41ek0xNDA4IDE0MDhxMTA0IDAgMTk4LjUtNDAuNXQxNjMuNS0xMDkuNSAxMDkuNS0xNjMuNSA0MC41LTE5OC41LTQwLjUtMTk4LjUtMTA5LjUtMTYzLjUtMTYzLjUtMTA5LjUtMTk4LjUtNDAuNS0xOTguNSA0MC41LTE2My41IDEwOS41LT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wIDAgMjQ4LjUgNTF0MjA0IDEzNi41IDEzNi41IDIwNCA1MSAyNDguNXoiLz48L3N2Zz4=';
var toggle = document.createElement('img');
toggle.src = hideNavIcon;
toggle.style.position = 'fixed';
toggle.style.bottom = "10px";
toggle.style.right = "10px";
toggle.style.width = "20px";
toggle.style.height = "20px";
toggle.style.cursor = "pointer";
toggle.style.zIndex = "9999";
toggle.addEventListener("click", function() {
if (!showing) {
apply();
} else {
undo();
}
showing = !showing;
});
document.getElementsByTagName('body')[0].appendChild(toggle);
var newStyleToBeApplied = document.createElement('style');
newStyleToBeApplied.type= 'text/css';
newStyleToBeApplied.innerHTML = `
.toggle .scroll-article-content,
.toggle header
{
width: 80% !important;
max-width: none;
}
.toggle .scroll-article-content,
.toggle figcaption,
.toggle h1,
.toggle h2,
.toggle h3
{
font-family: Crimson Pro Light;
line-height: 1.5em;
letter-spacing: normal;
}
.toggle .in-article-adx,
.toggle .global-navigation,
.toggle .below-navigation-banner-wrapper,
.toggle .notification-alert-banner,
.toggle .scroll-navigation-container
{
display: none !important;
}
`;
document.getElementsByTagName('head')[0].appendChild(newStyleToBeApplied);
apply();
showing = !showing;
function hasClass(el, className) {
if (el.classList) {
return el.classList.contains(className);
} else {
return !!el.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'));
}
}
function addClass(el, className) {
if (el.classList) {
el.classList.add(className);
}
else if (!hasClass(el, className)) {
el.className += " " + className;
}
}
function removeClass(el, className) {
if (el.classList) {
el.classList.remove(className);
} else if (hasClass(el, className)) {
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
el.className=el.className.replace(reg, ' ');
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment