Skip to content

Instantly share code, notes, and snippets.

@jeffwesson
Created March 5, 2020 03:25
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/5e457e514ce9cd24b8afb6192fa3b38d to your computer and use it in GitHub Desktop.
Save jeffwesson/5e457e514ce9cd24b8afb6192fa3b38d to your computer and use it in GitHub Desktop.
const config = { childList: true, subtree: true };
const $target = document.querySelector('body');
const removeAds = () => {
[...document.querySelectorAll('[href="#"]')]
.filter(e => e.innerText === 'Sponsored')
.forEach(e => {
var parent = e.closest('[id^="substream_"]');
console.log('Another ad bites the dust!');
parent.parentElement.removeChild(parent);
});
var adsPanel = document.querySelector('#pagelet_ego_pane');
adsPanel.innerHTML = '';
};
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