Last active
April 18, 2025 01:20
-
-
Save wernsey/a69341cffe3efcec2aacec6d9d18d7a4 to your computer and use it in GitHub Desktop.
Ad-B-Gone: Bookmarklet that removes obnoxious ads from pages
This file contains hidden or 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
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); | |
} | |
} | |
})(); |
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 })
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
I believe it can. I'm just not familiar with that API myself.