Last active
June 22, 2023 15:26
-
-
Save shreve/cb3fc124d6a04e034fd465842f173fcd to your computer and use it in GitHub Desktop.
Twitter Trending Topics Cleaner
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
const blocklist = ["Matt Walsh", "Musk", "Joe Rogan", "Biden", "Rowling"]; | |
let cleanseListener = null; | |
const cleanseTopics = () => { | |
let topics = document.querySelectorAll("[data-testid='trend']"); | |
if (topics.length == 0) return; | |
topics = Array.prototype.slice.apply(topics); | |
badTopics = topics.filter((el) => { | |
return blocklist.filter((str) => { | |
return el.innerText.includes(str); | |
}).length > 0; | |
}) | |
badTopics.forEach((el) => { | |
el.parentNode.removeChild(el); | |
console.log("Removed trend:", el.innerText); | |
}) | |
clearInterval(cleanseListener); | |
} | |
const start = () => { | |
cleanseListener = setInterval(cleanseTopics, 100); | |
}; | |
start(); | |
navigation.addEventListener('navigate', () => { | |
start(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment