Forked from christophercalm/block-fb-sponsored-tampermonkey.js
Created
July 2, 2022 18:39
-
-
Save extratone/9190c112dee24791bc3696d433a88193 to your computer and use it in GitHub Desktop.
Finds all html elements with fbclid in them to block ads.
This file contains hidden or 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
// ==UserScript== | |
// @name Remove Facebook Sponsored Elements | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1.1 | |
// @description Remove Facebook Sponsored Elements | |
// @author You | |
// @match https://www.facebook.com/ | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net | |
// @grant none | |
// @run-at document-idle | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Your code here... | |
// get all elements with href that container fbclid | |
const getFbAdElementsAndBlock = () =>{ | |
const elements = document.getElementsByTagName('a'); | |
const adElements = []; | |
for (const element of elements) { | |
if (element.href.indexOf('fbclid') > -1 || element.href.indexOf('l.php') > -1) { | |
adElements.push(element); | |
} | |
const isMainPageSponsored = (element) => element.href.indexOf('fbclid') > -1; | |
const isMarketplaceSponsored = (element) => window.location.href.indexOf('marketplace/') > -1 && element.href.indexOf('l.php') > -1; | |
if (isMainPageSponsored(element) || isMarketplaceSponsored(element)) { | |
adElements.push(element); | |
} | |
} | |
for (const element of adElements) { | |
element.style.display = 'none'; | |
} | |
setTimeout(getFbAdElementsAndBlock, 3000); | |
} | |
getFbAdElementsAndBlock(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment