Skip to content

Instantly share code, notes, and snippets.

@shyndman
Last active March 12, 2021 18:06
Show Gist options
  • Select an option

  • Save shyndman/82a8caf636d98188ec4de312d91a8c27 to your computer and use it in GitHub Desktop.

Select an option

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
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