Skip to content

Instantly share code, notes, and snippets.

@JAffleck
Forked from kbauer/Adblock Simple.js
Created June 16, 2021 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JAffleck/8712e7019aa63c2318311331ddf7fa3e to your computer and use it in GitHub Desktop.
Save JAffleck/8712e7019aa63c2318311331ddf7fa3e to your computer and use it in GitHub Desktop.
A simple adblocker bookmarklet, removing suspicious iframes. To install, copy-paste the source to a bookmark (will automatically remove newline characters). Extend the array ``exceptOrigins`` in order to create new exceptions. Careful: If bookmarklets get too long, they might stop working. This methods provides on-demand adblocking (as opposed t…
javascript:/* Adblock Simple */
(function(){
const exceptOrigins = [
'https://disqus.com',
document.origin
];
function remIF(e){
try{
var orgn = new URL(e.src || 'http://unknown-src').origin;
if( ! exceptOrigins.includes(orgn)){
e.parentElement.removeChild(e);
console.log('REMOVE IFRAME',orgn);
}
} catch(err) {
console.log('REMOVE ERROR',err);
}
}
function remIFs(){
for(var e of document.getElementsByTagName('iframe')){
remIF(e);
}
}
/* Must repeat to catch recurring frames. */
window.setInterval(remIFs,500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment