Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name ad block facebook
- // @version 3.4
- // @description UPDATED 12/12/2021
- // @updateURL https://pastebin.com/raw/vmaiA8jJ
- // @downloadURL https://pastebin.com/raw/vmaiA8jJ
- // @include https://*.facebook.*
- // @icon https://www.google.com/s2/favicons?domain=facebook.com
- // @icon64URL https://www.google.com/s2/favicons?domain=facebook.com
- // @run-at document-idle
- // ==/UserScript==
- (function () { var title = "ad block facebook";
- alert('please use the new updated script https://pastebin.com/azwkJETT')
- return
- const REGIONAL_SPONSORED_TEXT = "Sponsored" /* !!!!!!!!!!!!!!!! Change this to your regional language "Sponsored" text !!!!!!!!!!!!!!!! */
- const DEBUG_MODE = false; // Use this if you think it is blocking stuff that isn't adverts.
- // It will make all detected adds appear completely different
- // instead of removing them, change to true to see if it's working
- const CHECK_RATE_MS = 100;
- var add_count = 0;
- var detectedElements = []
- function mainScript() {
- function advertHandler(element){
- var timeOut = 28;
- var count = 0;
- while(count < timeOut) {
- var attribute = element.getAttribute("data-pagelet");
- if(attribute){
- if(attribute.contains('FeedUnit')) {
- if(DEBUG_MODE) {
- if(!detectedElements.includes(element)) {
- element.setAttribute('style','background:#FFFFFF !important;color:#000000 !important;width:50% !important;');
- console.log(element, count);
- detectedElements.push(element);
- }
- } else {
- add_count++;
- console.warn(title, 'Found', add_count, 'Adverts');
- element.parentNode.removeChild(element);
- }
- }
- return;
- } else {
- count++;
- element=element.parentNode;
- }
- }
- };
- Array.from(document.querySelectorAll('[role=feed]>div a[href="#"]')).forEach(
- e => {
- var advert = false;
- var link_text = e.parentNode.parentNode.parentNode.innerText.split('\n').join('');
- var sponsored = REGIONAL_SPONSORED_TEXT.toLowerCase().split('');
- var link_sponsored_check = 0;
- link_text.toLowerCase().split('').forEach(l => {link_sponsored_check += sponsored.includes(l)})
- advert = (link_sponsored_check >= sponsored.length);
- if(advert) advert = !link_text.includes(':');
- if(advert) advert = !link_text.contains('Shared with');
- if(advert) advert = link_text.length <= 35;
- if(advert) {
- if(!e.pathname.contains("/posts/")) advertHandler(e);
- }
- }
- );
- };
- const callback = function () {
- try {
- mainScript();
- } catch (e) {
- console.error("============================================================");
- console.error(title, e);
- console.error("============================================================");
- }
- };
- setInterval(callback, CHECK_RATE_MS);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement