Created
July 11, 2021 21:03
-
-
Save VonLatvala/d81d8ad00eccd8b055ffe6436556a8f9 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 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