Created
March 20, 2023 01:40
-
-
Save ericksoa/a24fe88952af022e8cd46b82cc98db4b to your computer and use it in GitHub Desktop.
Chrome Plug In Block By Regex - content.js
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 regexPattern = /your-regex-pattern/; | |
| function hideTweet(tweet) { | |
| tweet.style.display = 'none'; | |
| } | |
| function processTweets() { | |
| const tweets = document.querySelectorAll('[data-testid="tweet"]'); | |
| for (const tweet of tweets) { | |
| const tweetText = tweet.textContent; | |
| if (regexPattern.test(tweetText)) { | |
| hideTweet(tweet); | |
| } | |
| } | |
| } | |
| // Process tweets initially | |
| processTweets(); | |
| // Process new tweets as they are loaded | |
| const observer = new MutationObserver(processTweets); | |
| observer.observe(document.querySelector('body'), { | |
| childList: true, | |
| subtree: true, | |
| characterData: true, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment