Skip to content

Instantly share code, notes, and snippets.

@jeffwesson
Created February 22, 2020 07:43
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 jeffwesson/261bed672cb1b5aba56fe04eefcdb2a9 to your computer and use it in GitHub Desktop.
Save jeffwesson/261bed672cb1b5aba56fe04eefcdb2a9 to your computer and use it in GitHub Desktop.
const config = { childList: true, subtree: true };
const $target = document.querySelector('body');
const removeAds = () => {
const selector = '[data-testid="placementTracking"]';
document.querySelectorAll(selector).forEach(e => {
console.log('Another ad bites the dust!');
e.parentElement.removeChild(e);
});
};
removeAds();
const observer = new MutationObserver(mutations => {
for (let mutation of mutations) {
if (mutation.type === 'childList') {
if ([...mutation.addedNodes].length) {
removeAds();
}
}
}
});
observer.observe($target, config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment