Skip to content

Instantly share code, notes, and snippets.

@felipenmoura
Last active January 3, 2019 17:15
Show Gist options
  • Save felipenmoura/fb8d0c7ce6d1fa1da6c290b5839c4de0 to your computer and use it in GitHub Desktop.
Save felipenmoura/fb8d0c7ce6d1fa1da6c290b5839c4de0 to your computer and use it in GitHub Desktop.
/**
* Tired of those "we detected you have ads blocked, white-list us to continue reading"?
* Then, your problems are over!
*
* PS.: Help me improve it, and as soon as it gets really stable and working in most sites,
* let's ship it as a browser extension :)
*/
function closeAnnoyingModal () {
w = document.body.offsetWidth + 'px';
h = window.innerHeight + 'px';
bd = null;
main = null;
Array.from(document.querySelectorAll('body>*')).forEach(el => {
if (window.getComputedStyle(el).position === 'fixed') {
if (window.getComputedStyle(el).width >= w && window.getComputedStyle(el).height >= h) {
// this is probably the backdrop
bd = el;
// let's look for the main block of the modal
if (window.getComputedStyle(el.previousElementSibling).position === 'fixed') {
main = el.previousElementSibling;
} else if (window.getComputedStyle(el.nextElementSibling).position === 'fixed') {
main = el.nextElementSibling;
}
}
}
});
console.log('Hiding modal elements:', bd, main);
if (bd) {
bd.style.display = 'none';
}
if (main) {
main.style.display = 'none';
}
document.scrollingElement.style.overflow = 'auto';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment