Skip to content

Instantly share code, notes, and snippets.

@darcyclarke
Last active March 24, 2020 15:52
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 darcyclarke/68cd3abf282ad8b68aba08bdbfef7ea1 to your computer and use it in GitHub Desktop.
Save darcyclarke/68cd3abf282ad8b68aba08bdbfef7ea1 to your computer and use it in GitHub Desktop.
Facebook Sponsored Ad Filter - Use this w/ your preferred script injector (ex. "CJS" on Chrome or "Code Injector" on FF)
// Updated & working as of March 24th, 2020
;(() => {
function removeAds() {
Array.from(document.querySelectorAll('[id^=feed_sub_title], [data-testid^=story-subtilte], [data-pagelet^=FeedUnit]'))
.map(e => {
let content = e.innerText
let dynamic = Array.from(e.querySelectorAll('span:not([data-content=""])'))
.filter(e => e.style.display != 'none')
.map(e => {
let hidden = window.getComputedStyle(e, ':before').getPropertyValue('content')
return (hidden && hidden !== 'none' ? hidden : '') + e.innerText
})
.join('')
.replace(/['"]+/g, '')
if ((content + dynamic).toLowerCase().includes('sponsored')) {
e.closest('[data-pagelet^=FeedUnit]').remove()
}
})
setTimeout(removeAds, 200) // change to whatever interval you want...
}
removeAds()
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment