Created
October 2, 2023 04:59
-
-
Save d3cline/7dd28808e45d1bb1d7fb01d4f3b6830a to your computer and use it in GitHub Desktop.
Kill 'Suggested for you' from FB
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
function changeColorOfSuggestedForYou(parentLevels = 0) { | |
let spans = document.querySelectorAll('span[dir="auto"]'); | |
for (let span of spans) { | |
if (span.textContent.trim() === 'Suggested for you') { | |
span.style.color = 'red'; | |
let parent = span; | |
for (let i = 0; i < parentLevels; i++) { | |
parent = parent.parentElement; | |
if (parent && parent.tagName.toLowerCase() === 'div') { | |
parent.style.display = 'none'; | |
} else { | |
break; // stop if no parent or it's not a div | |
} | |
} | |
} | |
} | |
} | |
// Start observing the document with the configured parameters | |
function startObserving() { | |
const config = { | |
childList: true, | |
subtree: true, | |
characterData: true | |
}; | |
const observer = new MutationObserver(function() { | |
changeColorOfSuggestedForYou(10); | |
}); | |
observer.observe(document.body, config); | |
} | |
// Also, set an interval to check periodically, this is a fallback in case the MutationObserver misses some changes | |
setInterval(changeColorOfSuggestedForYou(10), 5000); // check every 5 seconds | |
// Initial checks and setup | |
changeColorOfSuggestedForYou(22); // initial check | |
startObserving(); // start observing for DOM changes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment