Last active
December 14, 2024 18:06
-
-
Save mia-z/4b571aba2156c1ec2563f802eb163973 to your computer and use it in GitHub Desktop.
Hide promoted Twitter posts
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 Twitter-Promoted-Hider | |
// @description Removes posts marked as promoted from your feed | |
// @match *://twitter.com/* | |
// @run-at document-end | |
// ==/UserScript== | |
setInterval(() => { | |
const queryEls = document.querySelectorAll("[data-testid='placementTracking']"); | |
queryEls.forEach((el, key) => { | |
recurseParentAndCheck(el); | |
}); | |
}, 500); | |
const recurseParentAndCheck = (element) => { | |
const attr = element.getAttribute("data-testid"); | |
if (attr && attr === "cellInnerDiv") { | |
element.style.display = "none"; | |
return; | |
} | |
const parent = element.parentElement; | |
if (!!parent) { | |
recurseParentAndCheck(parent); | |
} else { | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment