Hide replies and reposts (retweets) on X.com home timeline
当前为
// ==UserScript==
// @name Hide Replies and Reposts on X.com
// @namespace http://tampermonkey.net/
// @version 1.4
// @description Hide replies and reposts (retweets) on X.com home timeline
// @author
// @match https://x.com/*
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// Selectors for tweets and reposts
const tweetCSS = '[data-testid="cellInnerDiv"]';
const repostCSS = '[data-testid="socialContext"]';
const alreadyHiddenCSS = '[style*="display: none;"]';
function hideRepostsAndReplies() {
// Select tweets that are either replies or reposts
const tweetsToHide = document.querySelectorAll(`${tweetCSS}:has(${repostCSS}):not(${alreadyHiddenCSS})`);
tweetsToHide.forEach(tweet => {
tweet.style.display = 'none';
console.debug("Hid a repost or reply.");
});
}
// Initial call to hide replies and reposts
window.addEventListener('scroll', hideRepostsAndReplies);
hideRepostsAndReplies();
// Optional: Menu command to disable the script
if (typeof GM_registerMenuCommand !== "undefined") {
GM_registerMenuCommand("Disable script for this page", () => window.removeEventListener("scroll", hideRepostsAndReplies), "h");
}
})();