Created
March 5, 2020 03:25
-
-
Save jeffwesson/5e457e514ce9cd24b8afb6192fa3b38d to your computer and use it in GitHub Desktop.
This file contains 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
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