Skip to content

Instantly share code, notes, and snippets.

@rzymek
Last active August 24, 2024 14:08
Show Gist options
  • Save rzymek/75e7071beb6dc6e1358e80b7aca57c3b to your computer and use it in GitHub Desktop.
Save rzymek/75e7071beb6dc6e1358e80b7aca57c3b to your computer and use it in GitHub Desktop.
fb feed cleaner
(function(){
removed=0;
document.title="0";
document.querySelectorAll("[role='complementary']").forEach(it=>it.remove())
setInterval(() => {
rm=(e2d)=>{
if(!e2d)return;
e2d.remove();
removed++;
document.title=`${removed}`;
}
findParent = (eP, predicate) => {
for (; ;) {
eP = eP.parentElement;
if (!eP || predicate(eP)) {
return eP;
}
}
}
xp = (xpath) => {
const result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
return Array.from({ length: result.snapshotLength }, (_, index) => result.snapshotItem(index));
}
{/*sponsored*/
xp(`//span[text()='Sponsored']`)
.map(it => it.id)
.filter(it=>it)
.flatMap(id => Array.from(document.querySelectorAll(`[aria-labelledby="${id}"]`)))
.map(x => findParent(x, e5 => e5.getAttribute('aria-describedby')))
.forEach(rm)
Array.from(document.querySelectorAll('a[href^="/ads/about"]'))
.map(x => findParent(x, e5 => e5.getAttribute('aria-describedby'))).forEach(rm)
}
{
suggested = xp(
['Suggested for you','People You May Know','Reels and short videos','Suggested events',
'Proponowana dla Ciebie','Osoby, które możesz znać','Follow','Join']
.map(h=>`//span[text()='${h}']`)
.join("|"))
.forEach(x2 => {
rm(findParent(x2, eq => eq.getAttribute('aria-describedby')));
})
}
}, 100);
})();
@rzymek
Copy link
Author

rzymek commented Oct 23, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment