Hide Replies and Reposts on X.com

Hide replies and reposts (retweets) on X.com home timeline

目前為 2024-09-19 提交的版本,檢視 最新版本

// ==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");
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址