Greasy Fork is available in English.
Hide replies, self-replies, and threads instantly on X.com home timeline
当前为
// ==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);
});
})();