X/Twitter Clean menu and sidebar (Supports multiple language)

hidden Menu,Grok,Premium subscription,Verified Orgs,other,Explore,Notifications,Messages,Communities,Bookmarks and Customizable Settings

ของเมื่อวันที่ 27-02-2025 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         X/Twitter Clean menu and sidebar (Supports multiple language)
// @name:ja      X/Twitter きれいなメニューとサイドバー(多言語対応)
// @name:zh-TW   X/Twitter 乾淨的選單和側邊欄(支持多種語言)
// @name:zh-cn   X/Twitter 干净的选单和侧边栏(支持多种语言)
// @version      2.1
// @description  hidden Menu,Grok,Premium subscription,Verified Orgs,other,Explore,Notifications,Messages,Communities,Bookmarks and Customizable Settings
// @description:ja    清潔なメニュー、Grok、高度なサブスクリプション、認証済み組織、他の、探索、通知、メッセージ、コミュニティ、ブックマーク、およびカスタム設定
// @description:zh-tw 乾淨的 選單、Grok、高級訂閱、已認證組織、其他、探索、通知、訊息、社群、書籤和可自訂設定
// @description:zh-cn 干净的 选单、Grok、高级订阅、已认证组织、其他、探索、通知、私信、书签、书签和可自订设定
// @license      MIT
// @author       movwei
// @match        https://x.com/*
// @match        https://twitter.com/*
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_addStyle
// @namespace https://greatest.deepsurf.us/users/1041101
// ==/UserScript==

(function() {
    'use strict';

    const defaultSettings = {
        hideGrok: true,
        hidePremiumSignUp: true,
        hideSelectors: true,
        hideVerifiedOrgs: true,
        hideother: true,
        hideExplore: false,
        hideNotifications: false,
        hideBookmarks: false,
        hideMessages: false,
        hideCommunities: false,
    };

    const settings = {
        hideGrok: GM_getValue('hideGrok', defaultSettings.hideGrok),
        hidePremiumSignUp: GM_getValue('hidePremiumSignUp', defaultSettings.hidePremiumSignUp),
        hideSelectors: GM_getValue('hideSelectors', defaultSettings.hideSelectors),
        hideVerifiedOrgs: GM_getValue('hideVerifiedOrgs', defaultSettings.hideVerifiedOrgs),
        hideother: GM_getValue('hideother', defaultSettings.hideother),
        hideExplore: GM_getValue('hideExplore', defaultSettings.hideExplore),
        hideNotifications: GM_getValue('hideNotifications', defaultSettings.hideNotifications),
        hideBookmarks: GM_getValue('hideBookmarks', defaultSettings.hideBookmarks),
        hideCommunities: GM_getValue('hideCommunities', defaultSettings.hideCommunities),
        hideMessages: GM_getValue('hideMessages', defaultSettings.hideMessages),
    };

    // 多語言支持
    const language = navigator.language || navigator.userLanguage;
    const languages = {
        'en': {
            'hideGrok': 'Hide Grok',
            'hidePremiumSignUp': 'Hide Premium Sign-up',
            'hideSelectors': 'Hide Subscribe Message',
            'hideVerifiedOrgs': 'Hide Verified Orgs',
            'hideExplore': 'Hide Explore',
            'hideNotifications': 'Hide Notifications',
            'hideMessages': 'Hide Messages',
            'hideCommunities': 'Hide Communities',
            'hideother': 'Hide other',
            'settings': 'Settings',
            'saveRefresh': 'Save & refresh',
            'close': 'Close'
        },
        'zh-TW': {
            'hideGrok': '隱藏 Grok',
            'hidePremiumSignUp': '隱藏 高級訂閱',
            'hideSelectors': '隱藏 訂閱訊息',
            'hideVerifiedOrgs': '隱藏 已認證組織',
            'hideExplore': '隱藏 探索',
            'hideNotifications': '隱藏 通知',
            'hideMessages': '隱藏 訊息',
            'hideCommunities': '隱藏 社群',
            'hideBookmarks': '隱藏 書籤',
            'hideother': '隱藏 其他',
            'settings': '設定',
            'saveRefresh': '保存並刷新',
            'close': '關閉'
        },
        'zh-CN': {
            'hideGrok': '隐藏 Grok',
            'hidePremiumSignUp': '隐藏 高级订阅',
            'hideSelectors': '隐藏 订阅消息',
            'hideVerifiedOrgs': '隐藏 已认证组织',
            'hideExplore': '隐藏 探索',
            'hideNotifications': '隐藏 通知',
            'hideMessages': '隐藏 私信',
            'hideCommunities': '隐藏 社群',
            'hideBookmarks': '隐藏 书签',
            'hideother': '隐藏 其他',
            'settings': '设置',
            'saveRefresh': '保存并刷新',
            'close': '关闭'
        },
        'ja': {
            'hideGrok': 'Grokを非表示',
            'hidePremiumSignUp': 'プレミアムサインアップを非表示',
            'hideSelectors': 'サブスクライブメッセージを非表示',
            'hideVerifiedOrgs': '認証済み組織を非表示',
            'hideExplore': '話題を検索を非表示',
            'hideNotifications': '通知を非表示',
            'hideMessages': 'メッセージを非表示',
            'hideCommunities': 'コミュニティを非表示',
            'hideBookmarks': 'ブックマークを非表示',
            'hideother': '他のを非表示',
            'settings': '設定',
            'saveRefresh': '保存してリフレッシュ',
            'close': '閉じる'
        },
    };

    const currentLanguage = languages[language] || languages['en'];

    function createSettingsPanel() {
        const panel = document.createElement('div');
        panel.id = 'settingsPanel';
        panel.innerHTML = `
            <div id="settingsPanelContent">
                <h2>${currentLanguage['settings']}</h2>
                <label><input type="checkbox" id="hideGrokCheckbox" ${settings.hideGrok ? 'checked' : ''}> ${currentLanguage['hideGrok']}</label><br>
                <label><input type="checkbox" id="hidePremiumSignUpCheckbox" ${settings.hidePremiumSignUp ? 'checked' : ''}> ${currentLanguage['hidePremiumSignUp']}</label><br>
                <label><input type="checkbox" id="hideSelectorsCheckbox" ${settings.hideSelectors ? 'checked' : ''}> ${currentLanguage['hideSelectors']}</label><br>
                <label><input type="checkbox" id="hideVerifiedOrgsCheckbox" ${settings.hideVerifiedOrgs ? 'checked' : ''}> ${currentLanguage['hideVerifiedOrgs']}</label><br>
                <label><input type="checkbox" id="hideotherCheckbox" ${settings.hideother ? 'checked' : ''}> ${currentLanguage['hideother']}</label><br>
                <label><input type="checkbox" id="hideExploreCheckbox" ${settings.hideExplore ? 'checked' : ''}> ${currentLanguage['hideExplore']}</label><br>
                <label><input type="checkbox" id="hideNotificationsCheckbox" ${settings.hideNotifications ? 'checked' : ''}> ${currentLanguage['hideNotifications']}</label><br>
                <label><input type="checkbox" id="hideMessagesCheckbox" ${settings.hideMessages ? 'checked' : ''}> ${currentLanguage['hideMessages']}</label><br>
                <label><input type="checkbox" id="hideCommunitiesCheckbox" ${settings.hideCommunities ? 'checked' : ''}> ${currentLanguage['hideCommunities']}</label><br>
                <label><input type="checkbox" id="hideBookmarksCheckbox" ${settings.hideBookmarks ? 'checked' : ''}> ${currentLanguage['hideBookmarks']}</label><br>
                <button id="saveSettingsButton">${currentLanguage['saveRefresh']}</button>
                <button id="closeSettingsButton">${currentLanguage['close']}</button>
            </div>
        `;
        document.body.appendChild(panel);

        document.getElementById('saveSettingsButton').addEventListener('click', saveSettings);

        document.getElementById('closeSettingsButton').addEventListener('click', () => {
            document.getElementById('settingsPanel').style.display = 'none';
        });
    }

    function saveSettings() {
        settings.hideGrok = document.getElementById('hideGrokCheckbox').checked;
        settings.hidePremiumSignUp = document.getElementById('hidePremiumSignUpCheckbox').checked;
        settings.hideSelectors = document.getElementById('hideSelectorsCheckbox').checked;
        settings.hideVerifiedOrgs = document.getElementById('hideVerifiedOrgsCheckbox').checked;
        settings.hideExplore = document.getElementById('hideExploreCheckbox').checked;
        settings.hideNotifications = document.getElementById('hideNotificationsCheckbox').checked;
        settings.hideBookmarks = document.getElementById('hideBookmarksCheckbox').checked;
        settings.hideMessages = document.getElementById('hideMessagesCheckbox').checked;
        settings.hideCommunities = document.getElementById('hideCommunitiesCheckbox').checked;
        settings.hideother = document.getElementById('hideotherCheckbox').checked;

        GM_setValue('hideGrok', settings.hideGrok);
        GM_setValue('hidePremiumSignUp', settings.hidePremiumSignUp);
        GM_setValue('hideSelectors', settings.hideSelectors);
        GM_setValue('hideVerifiedOrgs', settings.hideVerifiedOrgs);
        GM_setValue('hideExplore', settings.hideExplore);
        GM_setValue('hideNotifications', settings.hideNotifications);
        GM_setValue('hideBookmarks', settings.hideBookmarks);
        GM_setValue('hideMessages', settings.hideMessages);
        GM_setValue('hideCommunities', settings.hideCommunities);
        GM_setValue('hideother', settings.hideother);
        location.reload();
    }

    GM_addStyle(`
        #settingsPanel {
            width: 250px;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: white;
            border: 1px solid #ccc;
            padding: 20px;
            z-index: 10000;
            display: none;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            border-radius: 8px;
        }

        #settingsPanelContent {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            width: 100%;
        }

        #settingsPanel h2 {
            margin: 0 0 15px 0;
            font-size: 18px;
            color: #333;
            text-align: center;
            width: 100%;
        }

        #settingsPanel label {
            margin: 5px 0;
            font-size: 14px;
            color: #333;
        }

        #settingsPanel button {
            margin-top: 10px;
            padding: 8px 15px;
            font-size: 14px;
            color: white;
            background-color: #007BFF;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
        }

        #settingsPanel button#closeSettingsButton {
            background-color: #6c757d;
        }
    `);

    createSettingsPanel();
    GM_registerMenuCommand(currentLanguage['settings'], () => {
        const panel = document.getElementById('settingsPanel');
        panel.style.display = 'block';
    });

    function addGlobalStyle(css) {
        var head, style;
        head = document.getElementsByTagName('head')[0];
        if (!head) { return; }
        style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = css;
        head.appendChild(style);
    }

    var cssRules = '';

    if (settings.hideSelectors) {
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            const elements = document.querySelectorAll('.css-175oi2r.r-1habvwh.r-eqz5dr.r-uaa2di.r-1mmae3n.r-3pj75a.r-bnwqim');
            elements.forEach(element => {
                const parentDiv = element.closest('div');
                if (parentDiv) {
                    parentDiv.remove();
                }
            });
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });
    }

    if (settings.hideGrok) {
        const targetPathD = "M2.205 7.423L11.745 21h4.241L6.446 7.423H2.204zm4.237 7.541L2.2 21h4.243l2.12-3.017-2.121-3.02zM16.957 0L9.624 10.435l2.122 3.02L21.2 0h-4.243zm.767 6.456V21H21.2V1.51l-3.476 4.946z";
        const targetGrokImageGenPathD = "M12.745 20.54l10.97-8.19c.539-.4 1.307-.244 1.564.38 1.349 3.288.746 7.241-1.938 9.955-2.683 2.714-6.417 3.31-9.83 1.954l-3.728 1.745c5.347 3.697 11.84 2.782 15.898-1.324 3.219-3.255 4.216-7.692 3.284-11.693l.008.009c-1.351-5.878.332-8.227 3.782-13.031L33 0l-4.54 4.59v-.014L12.743 20.544M10.48 22.531c-3.837-3.707-3.175-9.446.1-12.755 2.42-2.449 6.388-3.448 9.852-1.979l3.72-1.737c-.67-.49-1.53-1.017-2.515-1.387-4.455-1.854-9.789-.931-13.41 2.728-3.483 3.523-4.579 8.94-2.697 13.561 1.405 3.454-.899 5.898-3.22 8.364C1.49 30.2.666 31.074 0 32l10.478-9.466";
        const observer = new MutationObserver(mutations => {
            mutations.forEach(mutation => {
                const svgs = document.querySelectorAll('svg[aria-hidden="true"].r-4qtqp9');
                svgs.forEach(svg => {
                    const path = svg.querySelector('path');
                    if (path && path.getAttribute('d') === targetPathD) {
                        const container = svg.closest('button') || svg.closest('div');
                        if (container) {
                            container.remove();
                        }
                    }
                });

                const grokImgGenButtons = document.querySelectorAll('button[data-testid="grokImgGen"]');
                grokImgGenButtons.forEach(button => {
                    button.remove();
                });
            });
        });
        observer.observe(document.body, { childList: true, subtree: true });

        GM_addStyle(`
            a[href="/i/grok"] {
                display: none !important;
            }
            .css-175oi2r.r-1867qdf.r-xnswec.r-13awgt0.r-1ce3o0f.r-1udh08x.r-u8s1d.r-13qz1uu.r-173mn98.r-1e5uvyk.r-ii8lfi.r-40lpo0.r-rs99b7.r-12jitg0 {
                display: none;
            }
        `);
    }
    if (settings.hideCommunities) {
        const targetCommunitiesPathD = "M7.501 19.917L7.471 21H.472l.029-1.027c.184-6.618 3.736-8.977 7-8.977.963 0 1.95.212 2.87.672-.444.478-.851 1.03-1.212 1.656-.507-.204-1.054-.329-1.658-.329-2.767 0-4.57 2.223-4.938 6.004H7.56c-.023.302-.05.599-.059.917zm15.998.056L23.528 21H9.472l.029-1.027c.184-6.618 3.736-8.977 7-8.977s6.816 2.358 7 8.977zM21.437 19c-.367-3.781-2.17-6.004-4.938-6.004s-4.57 2.223-4.938 6.004h9.875zm-4.938-9c-.799 0-1.527-.279-2.116-.73-.836-.64-1.384-1.638-1.384-2.77 0-1.93 1.567-3.5 3.5-3.5s3.5 1.57 3.5 3.5c0 1.132-.548 2.13-1.384 2.77-.589.451-1.317.73-2.116.73zm-1.5-3.5c0 .827.673 1.5 1.5 1.5s1.5-.673 1.5-1.5-.673-1.5-1.5-1.5-1.5.673-1.5 1.5zM7.5 3C9.433 3 11 4.57 11 6.5S9.433 10 7.5 10 4 8.43 4 6.5 5.567 3 7.5 3zm0 2C6.673 5 6 5.673 6 6.5S6.673 8 7.5 8 9 7.327 9 6.5 8.327 5 7.5 5z";

        const observerCommunities = new MutationObserver(mutations => {
            mutations.forEach(() => {
                const svgs = document.querySelectorAll('svg[aria-hidden="true"].r-4qtqp9');
                svgs.forEach(svg => {
                    const path = svg.querySelector('path');
                    if (path && path.getAttribute('d') === targetCommunitiesPathD) {
                        const container = svg.closest('a') || svg.closest('div');
                        if (container) {
                            container.remove();
                        }
                    }
                });
            });
        });
        observerCommunities.observe(document.body, { childList: true, subtree: true });
    }
    if (settings.hidePremiumSignUp) {
        cssRules += 'a[href="/i/premium_sign_up"] { display: none !important; }';
    }
    if (settings.hideVerifiedOrgs) {
        cssRules += 'a[href="/i/verified-orgs-signup"] { display: none !important; }';
    }
    if (settings.hideother) {
        cssRules += 'a[href="/jobs"] { display: none !important; }';
        cssRules += '.css-175oi2r.r-l00any.r-109y4c4.r-kuekak { display: none; }';
        cssRules += 'a.css-175oi2r.r-5oul0u.r-knv0ih.r-faml9v.r-2dysd3.r-13qz1uu.r-o7ynqc.r-6416eg.r-1ny4l3l.r-1loqt21 { display: none; }';
        cssRules += 'a.css-175oi2r.r-5oul0u.r-1wzrnnt.r-1c4vpko.r-1c7gwzm.r-13qz1uu.r-o7ynqc.r-6416eg.r-1ny4l3l.r-1loqt21 { display: none; }';
    }
    if (settings.hideExplore) {
        cssRules += 'a[href="/explore"] { display: none !important; }';
    }
    if (settings.hideNotifications) {
        cssRules += 'a[href="/notifications"] { display: none !important; }';
    }
    if (settings.hideBookmarks) {
        cssRules += 'a[href="/i/bookmarks"] { display: none !important; }';
    }
    if (settings.hideMessages) {
        cssRules += 'a[href="/messages"] { display: none !important; }';
    }

    addGlobalStyle(cssRules);
})();