Skip to content

Instantly share code, notes, and snippets.

@ericksoa
Created March 20, 2023 01:40
Show Gist options
  • Select an option

  • Save ericksoa/a24fe88952af022e8cd46b82cc98db4b to your computer and use it in GitHub Desktop.

Select an option

Save ericksoa/a24fe88952af022e8cd46b82cc98db4b to your computer and use it in GitHub Desktop.
Chrome Plug In Block By Regex - content.js
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