Last active
January 3, 2019 17:15
-
-
Save felipenmoura/fb8d0c7ce6d1fa1da6c290b5839c4de0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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