Skip to content

Instantly share code, notes, and snippets.

@VonLatvala
Created July 11, 2021 21:03
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 VonLatvala/d81d8ad00eccd8b055ffe6436556a8f9 to your computer and use it in GitHub Desktop.
Save VonLatvala/d81d8ad00eccd8b055ffe6436556a8f9 to your computer and use it in GitHub Desktop.
const clearVisibleAds = () => document.querySelectorAll('div[role=feed]>div[data-pagelet]').forEach(postDomEl => {
try {
Array.from(postDomEl.querySelectorAll('a[role=link]')[3].querySelectorAll(':scope>span>span')[1].children).forEach((el) => {
// Clear mock span text items to be able to read the actual text below
if(el.style.position == 'absolute') el.remove()
});
if(postDomEl.querySelectorAll('a[role=link]')[3].text == 'Sponsored') {
postDomEl.remove()
console.info('Cleared an ad');
}
}
catch(err) { /* noop, if above doesn't work then we most probably aren't seeing a sponsored post */}
});
// Run the cleaner every 250th ms, and store the interval timer id under window if somebody wants to clear it
window.fbAdClearer = window.setInterval(clearVisibleAds, 250);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment