Skip to content

Instantly share code, notes, and snippets.

@derekdreery
Created October 5, 2016 08:04
Show Gist options
  • Save derekdreery/a0462e8c6963a727954aacf4406f8128 to your computer and use it in GitHub Desktop.
Save derekdreery/a0462e8c6963a727954aacf4406f8128 to your computer and use it in GitHub Desktop.
Remove facebook sponsored posts
// I find the inline sponsored posts on fb really annoying, and the ad-blockers don't seem to be able to keep
// up these days, so I wrote a script that takes a different approach. This js just needs to be run somewhere on the page
// Note that this javascript is written in modern ES2015, so you might need to change some of it in an older browser
function isSmall(el, minWidth, minHeight) {
const bbox = el.getBoundingClientRect();
return bbox.width < minWidth || bbox.height < minHeight;
}
function removeSponsoredPosts(text="Sponsored", minWidth=200, minHeight=200) {
const sponsored = Array.from(document.getElementsByTagName('a'))
.filter(el => el.textContent === text)
sponsored.forEach(el => {
while (isSmall(el, minWidth, minHeight)) {
el = el.parentNode;
}
console.log("removing", el)
el.parentNode.removeChild(el)
})
}
setInterval(removeSponsoredPosts, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment