Greasy Fork

Greasy Fork is available in English.

Hide Replies, Self-Replies, and Threads on X.com

Hide replies, self-replies, and threads instantly on X.com home timeline

当前为 2024-09-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Hide Replies, Self-Replies, and Threads on X.com
// @namespace    http://tampermonkey.net/
// @version      1.7
// @description  Hide replies, self-replies, and threads instantly on X.com home timeline
// @author       
// @match        https://x.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const tweetCSS = '[data-testid="cellInnerDiv"]';
    const replyIndicatorCSS = 'div[aria-label^="Replying to"]'; // Targets reply threads and self-replies

    // 1. Function to hide replies, self-replies, and threads
    function hideRepliesAndThreads() {
        const tweets = document.querySelectorAll(tweetCSS);
        tweets.forEach((tweet) => {
            // Check for reply indicators
            const isReply = tweet.querySelector(replyIndicatorCSS);
            if (isReply) {
                tweet.style.display = 'none';
                console.debug('Hid a reply or thread');
            }
        });
    }

    // 2. Run hiding function on load and dynamically with MutationObserver
    function initiateObserver() {
        // Call the function initially to hide existing replies and threads
        hideRepliesAndThreads();

        // Use MutationObserver to monitor DOM changes and apply the function dynamically
        const observer = new MutationObserver(hideRepliesAndThreads);
        observer.observe(document.body, { childList: true, subtree: true });
    }

    // 3. Use requestAnimationFrame to ensure the script executes before rendering
    window.addEventListener('load', () => {
        requestAnimationFrame(initiateObserver);
    });

})();