Skip to content

Instantly share code, notes, and snippets.

@wernsey
Last active April 18, 2025 01:20
Show Gist options
  • Select an option

  • Save wernsey/a69341cffe3efcec2aacec6d9d18d7a4 to your computer and use it in GitHub Desktop.

Select an option

Save wernsey/a69341cffe3efcec2aacec6d9d18d7a4 to your computer and use it in GitHub Desktop.
Ad-B-Gone: Bookmarklet that removes obnoxious ads from pages
javascript:(function(){
/* Ad-B-Gone: Bookmarklet that removes obnoxious ads from pages */
var selectors = [
/* By ID: */
'#sidebar-wrap', '#advert', '#xrail', '#middle-article-advert-container',
'#sponsored-recommendations', '#around-the-web', '#sponsored-recommendations',
'#taboola-content', '#taboola-below-taboola-native-thumbnails', '#inarticle_wrapper_div',
'#rc-row-container', '#ads', '#at-share-dock', '#at4-share', '#at4-follow', '#right-ads-rail',
'div#ad-interstitial', 'div#advert-article', 'div#ac-lre-player-ph',
/* By Class: */
'.ad', '.avert', '.avert__wrapper', '.middle-banner-ad', '.advertisement',
'.GoogleActiveViewClass', '.advert', '.cns-ads-stage', '.teads-inread', '.ad-banner',
'.ad-anchored', '.js_shelf_ads', '.ad-slot', '.antenna', '.xrail-content',
'.advertisement__leaderboard', '.ad-leaderboard', '.trc_rbox_outer', '.ks-recommended',
'.article-da', 'div.sponsored-stories-component', 'div.addthis-smartlayers',
'div.article-adsponsor', 'div.signin-prompt', 'div.article-bumper', 'div.video-placeholder',
'div.top-ad-container', 'div.header-ad', 'div.ad-unit', 'div.demo-block', 'div.OUTBRAIN',
'div.ob-widget', 'div.nwsrm-wrapper', 'div.announcementBar', 'div.partner-resources-block',
'div.arrow-down', 'div.m-ad', 'div.story-interrupt', 'div.taboola-recommended',
'div.ad-cluster-container', 'div.ctx-sidebar', 'div.incognito-modal', '.OUTBRAIN', '.subscribe-button',
'.ads9', '.leaderboards', '.GoogleActiveViewElement', '.mpu-container', '.ad-300x600', '.tf-ad-block',
'.sidebar-ads-holder-top', '.ads-one', '.FullPageModal__scroller',
'.content-ads-holder', '.widget-area', '.social-buttons', '.ac-player-ph',
/* Other: */
'script', 'iframe', 'video', 'aside#sponsored-recommendations', 'aside[role="banner"]', 'aside',
'amp-ad', 'span[id^=ad_is_]', 'div[class*="indianapolis-optin"]', 'div[id^=google_ads_iframe]',
'div[data-google-query-id]', 'section[data-response]', 'ins.adsbygoogle', 'div[data-google-query-id]',
'div[data-test-id="fullPageSignupModal"]', 'div[data-test-id="giftWrap"]' ];
for(let i in selectors) {
let nodesList = document.querySelectorAll(selectors[i]);
for(let i = 0; i < nodesList.length; i++) {
let el = nodesList[i];
if(el && el.parentNode)
el.parentNode.removeChild(el);
}
}
})();
@wernsey

wernsey commented Feb 4, 2019

Copy link
Copy Markdown
Author

While I appreciate that some of my favourite websites have to run adds in order to pay for all the content they so generously provide, some websites take it to a whole new level with animated banners, pop-ups and autoplaying videos.

This bookmarklet will run through all the selectors in the list and remove those elements from the webpage you're currently looking at.

I've used it under Firefox and Chrome without any issues. I add new selectors to the list as I find new annoying websites.

ghost commented Nov 6, 2019

Copy link
Copy Markdown

What is interesting about this is I believe that companies will still generate ad revenue (the add loaded onto the page afterall), but this script basically hides them from the viewer. Nice script though! My previous bookmarklet just targeted iframes.

@wernsey

wernsey commented Nov 7, 2019

Copy link
Copy Markdown
Author

@backentrancehacker Yes, the purpose is to allow me to whitelist some sites that I use regularly in my ad blocker, and then remove all the annoyances.

@AhmedRahmi

Copy link
Copy Markdown

could this be attached to a MutationObserver to run every time an add is injected

@wernsey

wernsey commented Dec 6, 2021

Copy link
Copy Markdown
Author

I believe it can. I'm just not familiar with that API myself.

ghost commented Dec 6, 2021

Copy link
Copy Markdown

I'm still getting notifications about this a year later ๐Ÿ˜‚
Here's some untested code you could try out:

const observer = new MutationObserver(mutations => {
    // the DOM was modified, run the ad-b-gone.js script here
})

observer.observe(document.body, { subtree: true, childList: true })

@tiagozip

tiagozip commented Sep 11, 2022

Copy link
Copy Markdown

I've included this in this bookmarklet, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment