Skip to content

Instantly share code, notes, and snippets.

@eiiot
Last active May 15, 2023 22:15
Show Gist options
  • Save eiiot/996311279c99c7da5e8db84e1267fb90 to your computer and use it in GitHub Desktop.
Save eiiot/996311279c99c7da5e8db84e1267fb90 to your computer and use it in GitHub Desktop.
Twitter Improved
// ==UserScript==
// @name Twitter Improved
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Hide tweets with over 5k likes.
// @author eiioth
// @match *://*.twitter.com/home
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const threshold = 5000;
console.log("Tweet Hider is running. Like threshold is", threshold);
function handleMutation(mutations) {
try {
for (const mutation of mutations) {
for (const elem of mutation.addedNodes) {
const tweets = elem.querySelectorAll('[data-testid="tweet"]');
for (const tweet of tweets) {
const likeContainer = tweet.querySelector('[data-testid="like"]');
const ariaLabel = likeContainer.getAttribute("aria-label");
const likes = ariaLabel.split(" ")[0];
if (likes > threshold) {
console.log("Hiding tweet with", likes, "likes");
tweet.style.display = "none";
}
}
}
}
} catch (e) {
console.error(e);
}
}
const observer = new MutationObserver(handleMutation);
observer.observe(document, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment