Last active
March 1, 2024 06:22
-
-
Save jcguu95/60c757f806e43b12c723f3b1f23d14d1 to your computer and use it in GitHub Desktop.
Remove Facebook Unfollowed Content
This file contains 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 Unfollowed Content | |
// @version 2024-03-02 | |
// @author Jin-Cheng Guu | |
// @match https://www.facebook.com/* | |
// @description Remove unfollowed content from the Facebook main page. | |
// ==/UserScript== | |
(function() { | |
let postClassName = 'x1lliihq' | |
let flaggedContents = ['Suggested for you', 'Follow'] | |
let config = { attributes: true, childList: true, subtree: true }; | |
function checkForSpan(div) { | |
// Check if the div contains a span with content "Suggested for you" | |
const spans = div.querySelectorAll('span'); | |
for (let i = 0; i < spans.length; i++) { | |
if (flaggedContents.includes(spans[i].textContent)) { | |
return true; | |
} | |
} | |
// Recursively check child elements | |
const children = div.children; | |
for (let i = 0; i < children.length; i++) { | |
if (checkForSpan(children[i])) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function makeObserver() { | |
let callback = (mutationList, observer) => { | |
for (const mutation of mutationList) { | |
if (mutation.type === "childList" && | |
mutation.addedNodes.length>0) { | |
let addedNode = mutation.addedNodes[0] | |
if (checkForSpan(addedNode) && | |
addedNode.tagName.toLowerCase() === 'div' && | |
addedNode.classList.value === postClassName) { | |
mutation.addedNodes[0].remove() | |
} | |
} | |
} | |
}; | |
return new MutationObserver(callback); | |
} | |
let observer = makeObserver() | |
observer.observe(document.body, config); | |
// observer.disconnect(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment