Hide Replies and Retweets from Timeline on X.com

Hide replies and retweets in your X.com (Twitter) home timeline.

目前为 2024-09-19 提交的版本。查看 最新版本

// ==UserScript==
// @name         Hide Replies and Retweets from Timeline on X.com
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Hide replies and retweets in your X.com (Twitter) home timeline.
// @author       
// @match        https://x.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    /**
     * Function to hide reply tweets and retweets from the home timeline.
     */
    function hideRepliesAndRetweets() {
        // Select all tweets in the timeline
        const tweets = document.querySelectorAll('div[data-testid="cellInnerDiv"]');
        tweets.forEach((tweet) => {
            // Check if the tweet is a reply
            const isReply = tweet.querySelector('div[aria-label="Replying to"]') !== null;

            // Check if the tweet is a retweet
            const isRetweet = tweet.querySelector('svg[aria-label="Retweeted"]') !== null ||
                              tweet.innerText.includes('Retweeted');

            if (isReply || isRetweet) {
                // Hide the tweet if it's a reply or retweet
                tweet.style.display = 'none';
            }
        });
    }

    // Run the function once the DOM content is loaded
    document.addEventListener('DOMContentLoaded', hideRepliesAndRetweets);

    // Observe changes to the timeline to hide new replies and retweets
    const observer = new MutationObserver(hideRepliesAndRetweets);
    observer.observe(document.body, { childList: true, subtree: true });
})();

QingJ © 2025

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