Greasy Fork

Greasy Fork is available in English.

X Timeline Cleaner - Only Followed Accounts

Hide tweets from users you don't follow on X.com timeline

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         X Timeline Cleaner - Only Followed Accounts
// @namespace    https://x.com/
// @version      2.9
// @description  Hide tweets from users you don't follow on X.com timeline
// @match        https://twitter.com/*
// @match        https://x.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function hideUnfollowedTweets() {
        var tweets = document.querySelectorAll('article');

        tweets.forEach(tweet => {
            // Check if the tweet contains a "Follow" button
            var followButton = tweet.querySelector('div[role="button"][data-testid$="-follow"]');

            // If the "Follow" button is present, hide the tweet
            if (followButton) {
                tweet.style.display = 'none';
                return;
            }

            // Additional check for promoted content
            var isPromoted = tweet.innerText.includes('Promoted');
            if (isPromoted) {
                tweet.style.display = 'none';
                return;
            }

            // Optional: Hide replies, reposts, and threads from followed accounts if desired
            // Uncomment the following lines if you want to hide them as well

            /*
            var isRepost = tweet.querySelector('[data-testid="socialContext"]');
            var replyPhrases = ['Replying to', 'Respondiendo a', 'Répondre à', 'Antwort an', 'Rispondendo a', 'Responder a'];
            var isReply = replyPhrases.some(phrase => tweet.innerText.includes(phrase));
            var threadPhrases = ['Show this thread', 'Mostrar este hilo', 'Afficher ce fil', 'Diesen Thread anzeigen', 'Mostra questo thread'];
            var isThread = threadPhrases.some(phrase => tweet.innerText.includes(phrase));

            if (isRepost || isReply || isThread) {
                tweet.style.display = 'none';
            }
            */
        });
    }

    // Observe dynamic content loading
    const observer = new MutationObserver(() => {
        hideUnfollowedTweets();
    });
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial call
    hideUnfollowedTweets();
})();