Hide Replies and Reposts on X.com

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

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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