Twitter/X UI Improvements

Improves Twitter/X layout by adjusting widths and removing grok and stuff

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Twitter/X UI Improvements
// @namespace    https://twitter.com/
// @version      1.1
// @description  Improves Twitter/X layout by adjusting widths and removing grok and stuff
// @author       Minoa
// @match        https://twitter.com/*
// @match        https://x.com/*
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Add custom CSS styles
    const customStyles = `
        .r-1ye8kvj { max-width: 680px !important; }
        .r-o96wvk { width: 230px !important; }
        .r-ttdzmv { padding-top: 8px !important; }
        .r-1hycxz { width: 280px !important; }
        .r-1jte41z { min-width: 250px !important; }
    `;
    
    GM_addStyle(customStyles);

    // Function to remove unwanted elements
    function removeElements() {
        const selectors = [
            '[data-testid="GrokDrawer"]',
            'a[href="/i/grok"]',
            'a[href="/i/verified-orgs-signup"]',
            'a[href="/i/premium_sign_up"]',
            'aside[aria-label="Subscribe to Premium"]',
            '[data-testid="grokImgGen"]',
            '.r-18u37iz.r-1h0z5md button[aria-label="Grok actions"]'
        ];

        selectors.forEach(selector => {
            const elements = document.querySelectorAll(selector);
            elements.forEach(element => element.remove());
        });
    }

    // Create and run mutation observer to handle dynamically loaded content
    const observer = new MutationObserver(() => {
        removeElements();
    });

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

    // Initial cleanup
    removeElements();
})();