Last active
October 7, 2022 16:17
-
-
Save wappenull/e5216bcf299a11bba35a84a432280abf to your computer and use it in GitHub Desktop.
Wappen FB Blocker, blocks suggested post, reel, sponsored post in simple scripting.
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 Wappen FBlock | |
// @namespace http://tampermonkey.net/ | |
// @version 0.4 | |
// @description Disable brain cell damaging content. | |
// @author Wappen | |
// @match https://www.facebook.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=facebook.com | |
// @grant none | |
// ==/UserScript== | |
const CHECK_INTERVAL_MS = 2000; | |
const REEL_HEADER = "Reels and short videos"; | |
const SUGGESTED_HEADER = "Suggested for you"; | |
function _GetParent( node, upLevel ) | |
{ | |
let i = upLevel; | |
while( i-- > 0 && node != null ) | |
{ | |
node = node.parentNode; | |
} | |
return node; | |
} | |
function _IsBusted( el ) | |
{ | |
return el.getAttribute( "wappenrekted" ) == 1; | |
} | |
function _FoundNode( el, reason, rootLevel ) | |
{ | |
let contentRoot = _GetParent( el, rootLevel ); | |
contentRoot.childNodes.forEach( function (el, i) | |
{ | |
el.hidden = true; | |
} ); | |
//el.outerText = "XXX"; | |
el.setAttribute( "wappenrekted", 1 ); | |
let span = document.createElement('span'); | |
span.innerHTML = "Wappen FBlock - " + reason; | |
contentRoot.appendChild( span ); | |
console.log( `Wappen FBlock found '${reason}'` ); | |
} | |
function _SimplifyFbLink( link ) | |
{ | |
let a = link.split("__cft__",2); | |
return a[0]; | |
} | |
function Validate() | |
{ | |
'use strict'; | |
NodeList.prototype.forEach = Array.prototype.forEach; | |
let foundSomeData = false; | |
// Find div>span to search for certain work | |
document.querySelectorAll( "div > span" ).forEach( function (el, i) | |
{ | |
if( el.innerText == REEL_HEADER && !_IsBusted( el ) ) // This is part of Reels and short video | |
{ | |
// Up some level to root div | |
_FoundNode( el, "REELZ", 8 ); | |
foundSomeData = true; | |
} | |
else if( el.outerText.includes( SUGGESTED_HEADER ) && !_IsBusted( el ) ) // Stupid suggested post | |
{ | |
const ROOT_DEPTH = 8; | |
let link2 = ""; | |
let linkNode = _GetParent(el,18).querySelector("h4 > span > a"); | |
if( linkNode != null ) | |
{ | |
link2 = _SimplifyFbLink( linkNode.href ); | |
} | |
_FoundNode( el, `Suggested ${link2}`, ROOT_DEPTH ); | |
foundSomeData = true; | |
} | |
} ); | |
document.querySelectorAll( "span > a" ).forEach( function (el, i) | |
{ | |
// Ads will not have comment form visible on start by default | |
const ADS_DEPTH = 18; | |
if( el.href.includes("#") && !_IsBusted( el ) ) | |
{ | |
let root = _GetParent( el, ADS_DEPTH ); | |
if( root.querySelector("form") == null ) | |
{ | |
let linkNode = root.querySelector("h4 > span > a"); | |
if( linkNode == null ) // Sometimes link is under strong node | |
linkNode = root.querySelector("strong > span > a"); | |
if( linkNode == null ) return; | |
let link = linkNode.href; | |
if( link.length > 300 ) // Ads usually has exceptionally long tracking | |
{ | |
let link2 = _SimplifyFbLink( link ); | |
_FoundNode( el, `Sponzored ${link2} (len=${link.length})`, ADS_DEPTH ); | |
foundSomeData = true; | |
} | |
} | |
} | |
} ); | |
// In-page nav will not refresh the page, so use periodic check | |
let nextInterval = CHECK_INTERVAL_MS; | |
if( foundSomeData ) | |
nextInterval /= 3; // Faster next check | |
setTimeout( Validate, nextInterval ); | |
} | |
// It needs some delay before data-is_bought will popup | |
setTimeout( Validate, CHECK_INTERVAL_MS ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
INSTALL
https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo