Greasy Fork

Greasy Fork is available in English.

JeetDelete X.com

Hides posts on X written in Hindi, other Indian languages, Arabic, Japanese, or Thai

当前为 2025-07-11 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         JeetDelete X.com
// @namespace    http://tampermonkey.net/
// @version      1.4.4
// @description  Hides posts on X written in Hindi, other Indian languages, Arabic, Japanese, or Thai
// @author       xechostormx, hearing_echoes
// @match        https://x.com/*
// @match        https://www.x.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    // Detect target language scripts
    function isTargetLanguage(text) {
        if (!text || typeof text !== 'string') return false;
        const ranges = [
            /[\u0900-\u097F]/, // Devanagari
            /[\u0B80-\u0BFF]/, // Tamil
            /[\u0C00-\u0C7F]/, // Telugu
            /[\u0980-\u09FF]/, // Bengali
            /[\u0A80-\u0AFF]/, // Gujarati
            /[\u0B00-\u0B7F]/, // Odia
            /[\u0A00-\u0A7F]/, // Gurmukhi
            /[\u0C80-\u0CFF]/, // Kannada
            /[\u0D00-\u0D7F]/, // Malayalam
            /[\u0600-\u06FF\u0750-\u077F\uFB50-\uFDFF\uFE70-\uFEFF]/, // Arabic
            /[\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF]/, // Japanese
            /[\u0E00-\u0E7F]/  // Thai
        ];
        // Require at least 20% of characters to match target scripts
        const totalChars = text.length;
        const targetChars = ranges.reduce((count, rx) => count + (text.match(rx) || []).length, 0);
        return targetChars / totalChars >= 0.2;
    }

    // Hide matching posts
    function hideTargetLanguagePosts() {
        const selector = 'div[data-testid="tweetText"]';
        const tweetTexts = document.querySelectorAll(selector);
        if (!tweetTexts.length) {
            console.warn('No tweet text elements found with selector:', selector);
            return;
        }
        console.log(`Scanning ${tweetTexts.length} tweet texts`);
        tweetTexts.forEach((textEl) => {
            const tweet = textEl.closest('article[data-testid="tweet"]') || textEl.closest('div[data-testid="cellInnerDiv"]');
            if (!tweet) return;
            const txt = textEl.textContent || '';
            if (isTargetLanguage(txt)) {
                tweet.style.display = 'none';
                console.log('Hid tweet:', txt.trim().slice(0, 50));
            }
        });
    }

    console.log('X-HideLang script initialized @', new Date().toLocaleTimeString());

    // Wait for timeline to load
    function waitForTimeline() {
        const timeline = document.querySelector('div[aria-label*="Timeline"]');
        if (timeline) {
            hideTargetLanguagePosts();
            observeTimeline(timeline);
        } else {
            requestAnimationFrame(waitForTimeline);
        }
    }

    // Observe timeline for new tweets
    function observeTimeline(timeline) {
        let debounceTimer;
        const observer = new MutationObserver(() => {
            clearTimeout(debounceTimer);
            debounceTimer = setTimeout(hideTargetLanguagePosts, 200);
        });
        observer.observe(timeline, { childList: true, subtree: true });
        console.log('Observer attached to timeline');

        // Cleanup on page unload
        window.addEventListener('unload', () => {
            clearTimeout(debounceTimer);
            observer.disconnect();
        });
    }

    // Start when ready
    requestAnimationFrame(waitForTimeline);
})();