Last active
February 7, 2020 04:25
-
-
Save kenbellows/689f91f3433745879309687b54a215ea to your computer and use it in GitHub Desktop.
JavaScript code and bookmarklet to cancel annoying "Please disable ad blocker" overlays that cover the page and disable scrolling
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
// find the element in the body with max z-index | |
// adapted from this StackOverflow answer by Jimmy Chandra: | |
// https://stackoverflow.com/a/1118216/470925 | |
let max, maxVal = 0 | |
document.querySelectorAll('body *').forEach(el => { | |
// get position and zIndex style values for the element | |
const {position, zIndex} = document.defaultView.getComputedStyle(el) | |
// skip statically positioned elements | |
if (position !== 'static') { | |
// parse the string value of zIndex into an integer, defaulting to 1, | |
// e.g. if the value is "auto" and parseInt produces NaN | |
const z = parseInt(zIndex) || 1 | |
// if this is the largest zIndex we've seen, store it | |
if (z > maxVal) { | |
maxVal = z | |
max = el | |
} | |
} | |
}) | |
// chances are, max now holds the overlay element; delete it | |
max.remove() | |
// most of these overlay tricks also set body and html overflowY to "hidden", | |
// so reset both back to "auto" as they should be so you can scroll the page | |
document.body.style.overflowY = document.body.parentElement.style.overflowY = 'auto' |
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
// create a new bookmark with this in the URL field; it's the same code as above, just minified | |
javascript:(_=>{let d=document,b=d.body,v=0,m;d.querySelectorAll('body *').forEach(e=>{let {position:p,zIndex:i}=d.defaultView.getComputedStyle(e);if(p!=='static'){let z=parseInt(i)||1;if(z>v){v=z;m=e}}});m.remove();b.style.overflowY=b.parentElement.style.overflowY='auto'})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment