Last active
March 12, 2021 18:06
-
-
Save shyndman/82a8caf636d98188ec4de312d91a8c27 to your computer and use it in GitHub Desktop.
Attempt to automate the re-enabling of a site after AdBlock has been detected
This file contains hidden or 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
| const viewportWidth = document.documentElement.clientWidth; | |
| const viewportHeight = document.documentElement.clientHeight; | |
| removeObscuringFixeds(document.body.querySelectorAll(':scope *')); | |
| enableScroll(); | |
| function removeObscuringFixeds(elements) { | |
| elements = Array.from(elements); | |
| for (var el of elements) { | |
| const style = getComputedStyle(el); | |
| if (style.position != 'fixed' || style.position != 'absolute') { | |
| continue; | |
| } | |
| const rect = el.getBoundingClientRect(); | |
| if (rect.left <= 0 && | |
| rect.top <= 0 && | |
| rect.right >= viewportWidth && | |
| rect.bottom >= viewportHeight) { | |
| el.remove(); | |
| } | |
| } | |
| } | |
| function enableScroll() { | |
| enableScrollOnElement(document.documentElement); | |
| enableScrollOnElement(document.body); | |
| } | |
| function enableScrollOnElement(element) { | |
| if (getComputedStyle(element).overflow == 'hidden') { | |
| const style = element.getAttribute('style') || ''; | |
| element.setAttribute('style', `${style}; overflow: auto !important;`); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment