Skip to content

Instantly share code, notes, and snippets.

@AoDev
Created July 10, 2017 12:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AoDev/178c68aa464865bf38e1b750afe86c35 to your computer and use it in GitHub Desktop.
Remove facebook ads from timeline
// Remove the ads in your Facebook timeline.
// Depending on the language you use in FB, you will need to update the keyWord.
// The keyWord is the title used in facebook ads. Everytime this title is found,
// the corresponding content will be removed from the timeline.
// You can also adjust the check interval, it depends on how fast you scroll
// the content usually.
// How to use:
// - You can use a browser extension that injects that script into the page.
// Eg: https://chrome.google.com/webstore/detail/css-and-javascript-inject/ckddknfdmcemedlmmebildepcmneakaa
// Copy paste this whole script so it is applied on FB page.
const keyWord = 'publicidad'
function findElements(selector) {
return [].slice.call(document.querySelectorAll(selector))
}
function findParent(node, cssClass) {
if (node.nodeName === '#document') {
return null
}
if (node.className.includes(cssClass)) {
return node
}
return findParent(node.parentNode, cssClass)
}
function findAdLinks() {
var links = findElements('a')
return links.filter((link) => link.innerText.toLowerCase() === keyWord)
}
setInterval(() => {
var adLinks = findAdLinks()
adLinks.forEach((link) => {
const parent = findParent(link, 'fbUserContent')
if (parent) {
parent.remove()
}
})
}, 5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment