<h1>
JS bookmarklet: remove all ad iframes and containers.
</h1>
<p>
Note the logic is fairly basic, and there will be false positives and misses.<br>
Uses only native JS, no jQuery or other plugin required.
</p>
Removes:
<ul>
<li>all iframe and video tags with a src domain different from the current page domain, but keeps whitelisted domains,</li>
<li>all iframes that look like a flat bar, or slim and high (very low or very high width/height ratio),</li>
<li>and a set of custom listed elements.</li>
</ul>
<p>
See script panel for original (non minified) code.
</p>
<p>
Drag link to bookmarks:<br>
<a href="javascript:(function(window,document){var domain = (''+document.location.host).split('.').slice(-2).join('.');if(domain.length < 6){domain = (''+document.location.host).split('.').slice(-3).join('.');}function RegExpEscape(s){return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');}var log = window.console && window.console.log ? window.console.log : function(){};function removeElement(el){try{el.remove();}catch(e){log('Problem removing element:', el);log(e);}}function getsize(el){var w = parseInt(el.offsetWidth || el.width, 10);var h = parseInt(el.offsetHeight || el.height, 10);return {width:w, height:h};}var re = RegExp('^.{0,8}(\\w+\\.)*' + RegExpEscape(domain) + '/', 'i');[].slice.apply(document.querySelectorAll('iframe,video')).forEach(function(el){if( typeof el.src === 'string' && el.src && ! el.src.match( re )){removeElement(el);}});var q = `.adsbygoogle, .everyonelovesstackoverflow, .jpx-pa-wrapper, .jpx-pu-wrapper, .jpx-sa-wrapper, .jpx-as-wrapper, [class*="jpx-"][class*="-wrapper"], [class*="adzerk"], [class$="_ads"], [id*="adzerk"], [id*="google_ad"], ins[id*="aswift"], [href*="buysellads.com"], img[src*="buysellads.com"], #TOP_LEADERBOARD_AB, iframe[src*="/ads/"], iframe[id*="google_ads_iframe"], [href*="adclick"],...
// TIP: I used my jsfiddle to minify js below to one line for bookmarklet:
// https://jsfiddle.net/ElMoonLite/ndg24dso/
// TODO: Clean up a bit.
// TODO: custom elements: purge, update, remove?
// The list of custom elements selector is very old, it needs purging and updating.
// Perhaps even remove it altogether, as the domain and size methods seems to catch most things.
// Intentional error to prevent running code below in this jsfiddle:
throw new Error();
(function(window,document){
var domain = (''+document.location.host).split('.').slice(-2).join('.');
if(domain.length < 6){
domain = (''+document.location.host).split('.').slice(-3).join('.');
}
function RegExpEscape(s){
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
var log = window.console && window.console.log ?
window.console.log.bind(window.console) : function(){};
function findSameSizeParentRoot(el, max_delta_width, max_delta_height){
var el_size = getsize(el), p, p_size, target = el;
if (!el_size.width || el_size.width < 10 || ! el_size.height || el_size.height < 10) {
return target;
}
while (true) {
p = target.parentNode;
if (!p || p === el) {
break;
}
p_size = getsize(p);
if (!p_size.width || !p_size.height) {
break;
}
if (Math.abs(el_size.width - p_size.width) > max_delta_width) {
break;
}
if (Math.abs(el_size.height - p_size.height) > max_delta_height) {
break;
}
target = p;
}
return target;
}
function removeElement(el){
el = findSameSizeParentRoot(el, 30, 30) || el;
try{
el.remove();
}catch(e){
log('Problem removing element:', el);
log(e);
}
}
function getsize(el){
var w = parseInt(el.offsetWidth || el.width, 10);
var h = parseInt(el.offsetHeight || el.height, 10);
return {width:w, height:h};
}
var whitelist_domains = ['youtube','youtu.be','youtube-nocookie.com','googlevideo.com','ytimg.com','apis.google.com'];
function isWhitelistUrl(src){
try {
var...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.