X/Twitter Clean-up & Wide Layout Display

Hide unnecessary X menu items on the left (Bookmarks, Jobs, Communities, Premium, Verified Organizations, Monetization, Ads) and right (Subscribe to Premium, Footer), and apply horizontal translation to widen the content area (supports Traditional Chinese, Simplified Chinese, English, Japanese).

2025-05-01 기준 버전입니다. 최신 버전을 확인하세요.

// ==UserScript==
// @name         X/Twitter Clean-up & Wide Layout Display
// @name:zh-TW   X/Twitter 乾淨化 & 加寬版面顯示
// @name:zh-CN   X/Twitter 干净化 & 加宽版面显示
// @name:JA      X/Twitter クリーンアップ & ワイドレイアウト表示
// @namespace    https://www.tampermonkey.net/
// @version      2.5
// @description  Hide unnecessary X menu items on the left (Bookmarks, Jobs, Communities, Premium, Verified Organizations, Monetization, Ads) and right (Subscribe to Premium, Footer), and apply horizontal translation to widen the content area (supports Traditional Chinese, Simplified Chinese, English, Japanese).
// @description:zh-TW  隱藏 X 多餘選單項目,左側(書籤、工作機會、社群、Premium、已認證組織、營利、廣告)、右側(訂閱 Premium、頁尾欄目),並左右平移加寬內容區塊 (支援繁中、簡中、英文、日文)
// @description:zh-CN  隐藏 X 多余选单项目,左侧(书签、工作机会、社群、Premium、已认证组织、营利、广告)、右侧(订阅 Premium、页尾栏目),并左右平移加宽内容区块 (支援繁中、简中、英文、日文)
// @description:JA  Xの不要なメニュー項目を左側(ブックマーク、求人、コミュニティ、Premium、認証済み組織、収益化、広告)および右側(Premiumの購読、フッター)で非表示にし、コンテンツ領域を左右に平行移動して広げる(繁体字中国語、簡体字中国語、英語、日本語に対応)。
// @author       ChatGPT
// @match        https://x.com/*
// @match        https://twitter.com/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// @license MIT
// ==/UserScript==

(function () {
  'use strict';

  // 🔧 設定項目:預設時間軸寬度(單位:px)
  let timelineWidth = GM_getValue('timelineWidth', 1200);

  // 提供使用者調整寬度的介面
  GM_registerMenuCommand('設定:時間軸推文寬度', () => {
    const input = prompt('請輸入時間軸推文寬度(單位 px,預設為 1200):', timelineWidth);
    if (input !== null) {
      const val = parseInt(input);
      if (!isNaN(val) && val >= 600 && val <= 3000) {
        GM_setValue('timelineWidth', val);
        location.reload(); // 設定後自動重新整理頁面
      } else {
        alert('請輸入合理的數值(600 ~ 3000)');
      }
    }
  });

  const targetLabels = [
    '書籤', 'Bookmarks', 'ブックマーク', '书签',
    '工作機會', 'Careers', '求人', '工作机会',
    '社群', 'Communities', 'コミュニティ', '社区',
    'Premium', 'プレミアム',
    '已認證組織', 'Verified Orgs', '認証済み組織', '认证组织',
    '營利', 'Monetization', '収益化', '营利',
    '廣告', 'Ads', '広告', '广告',
  ];

  const observer = new MutationObserver(() => {
    try {
      // 隱藏左側選單項目
      document.querySelectorAll('nav[role="navigation"] div[dir="ltr"]').forEach(item => {
        const label = item.innerText?.trim();
        if (targetLabels.includes(label)) {
          const topLevel = item.closest('a, div[role="link"]');
          if (topLevel) topLevel.style.display = 'none';
        }
      });

      // 隱藏右側 Premium 欄位
      const premiumCard = document.querySelector('.css-175oi2r[data-testid="super-upsell-UpsellCardRenderProperties"]');
      if (premiumCard) premiumCard.style.display = 'none';

      // 隱藏頁尾欄目
      const footerLabels = ['頁尾', 'Footer', '页脚', 'フッター'];
      document.querySelectorAll('nav[role="navigation"]').forEach(nav => {
        const label = nav.getAttribute('aria-label')?.trim();
        if (label && footerLabels.includes(label)) {
          nav.style.display = 'none';
        }
      });

      // 主內容容器加寬
      const mainContent = document.querySelector('main.css-175oi2r.r-16y2uox.r-1wbh5a2.r-1habvwh');
      if (mainContent) {
        Object.assign(mainContent.style, {
          width: '100%',
          maxWidth: 'none',
          marginLeft: 'auto',
          marginRight: 'auto',
        });
      }

      // 加寬多層推文容器
      const containers = document.querySelectorAll([
        'div.r-1oszu61.r-1niwhzg.r-18u37iz.r-16y2uox.r-2llsf.r-13qz1uu.r-1wtj0ep',
        'div.r-kemksi.r-1kqtdi0.r-1ua6aaf.r-th6na.r-1phboty.r-16y2uox.r-184en5c.r-1abdc3e.r-1lg4w6u.r-f8sm7e.r-13qz1uu.r-1ye8kvj',
        'div.r-f8sm7e.r-13qz1uu.r-1ye8kvj'
      ].join(', '));

      containers.forEach(el => {
        Object.assign(el.style, {
          width: `${timelineWidth}px`,
          maxWidth: 'none',
          marginLeft: 'auto',
          marginRight: 'auto',
        });
      });

    } catch (e) {
      console.error('腳本執行錯誤:', e);
    }
  });

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