X/Twitter 乾淨化 & 加寬版面顯示

隐藏 X 多余选单项目,左侧(书签、工作机会、社群、Premium、已认证组织、营利、广告)、右侧(订阅 Premium、页尾栏目),并左右平移加宽内容区块 (支援繁中、简中、英文、日文)

当前为 2025-05-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name X/Twitter Clean-up & Wide Layout Display
  3. // @name:zh-TW X/Twitter 乾淨化 & 加寬版面顯示
  4. // @name:zh-CN X/Twitter 乾淨化 & 加寬版面顯示
  5. // @name:JA X/Twitter クリーンアップ & ワイドレイアウト表示
  6. // @namespace https://www.tampermonkey.net/
  7. // @version 1.6
  8. // @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).
  9. // @description:zh-TW 隱藏 X 多餘選單項目,左側(書籤、工作機會、社群、Premium、已認證組織、營利、廣告)、右側(訂閱 Premium、頁尾欄目),並左右平移加寬內容區塊 (支援繁中、簡中、英文、日文)
  10. // @description:zh-CN 隐藏 X 多余选单项目,左侧(书签、工作机会、社群、Premium、已认证组织、营利、广告)、右侧(订阅 Premium、页尾栏目),并左右平移加宽内容区块 (支援繁中、简中、英文、日文)
  11. // @description:JA Xの不要なメニュー項目を左側(ブックマーク、求人、コミュニティ、Premium、認証済み組織、収益化、広告)および右側(Premiumの購読、フッター)で非表示にし、コンテンツ領域を左右に平行移動して広げる(繁体字中国語、簡体字中国語、英語、日本語に対応)。
  12. // @author ChatGPT
  13. // @match https://x.com/*
  14. // @match https://twitter.com/*
  15. // @grant none
  16. // @license MIT
  17. // ==/UserScript==
  18.  
  19. (function () {
  20. 'use strict';
  21.  
  22. const targetLabels = [
  23. // 書籤 / Bookmarks
  24. '書籤', 'Bookmarks', 'ブックマーク', '书签',
  25.  
  26. // 工作機會 / Careers
  27. '工作機會', 'Careers', '求人', '工作机会',
  28.  
  29. // 社群 / Communities
  30. '社群', 'Communities', 'コミュニティ', '社区',
  31.  
  32. // Premium
  33. 'Premium', 'プレミアム',
  34.  
  35. // 已認證組織 / Verified Orgs
  36. '已認證組織', 'Verified Orgs', '認証済み組織', '认证组织',
  37.  
  38. // 營利 / Monetization
  39. '營利', 'Monetization', '収益化', '营利',
  40.  
  41. // 廣告 / Ads
  42. '廣告', 'Ads', '広告', '广告',
  43. ];
  44.  
  45. const observer = new MutationObserver(() => {
  46. try {
  47. // 🔹 隱藏左側選單項目
  48. document.querySelectorAll('nav[role="navigation"] div[dir="ltr"]').forEach(item => {
  49. const label = item.innerText?.trim();
  50. if (targetLabels.includes(label)) {
  51. const topLevel = item.closest('a, div[role="link"]');
  52. if (topLevel) topLevel.style.display = 'none';
  53. }
  54. });
  55.  
  56. // 🔹 隱藏右側「訂閱 Premium」欄位
  57. const premiumCard = document.querySelector('.css-175oi2r[data-testid="super-upsell-UpsellCardRenderProperties"]');
  58. if (premiumCard) premiumCard.style.display = 'none';
  59.  
  60. // 🔹 隱藏頁尾欄目
  61. const footerLabels = ['頁尾', 'Footer', '页脚', 'フッター'];
  62. document.querySelectorAll('nav[role="navigation"]').forEach(nav => {
  63. const label = nav.getAttribute('aria-label')?.trim();
  64. if (label && footerLabels.includes(label)) {
  65. nav.style.display = 'none';
  66. }
  67. });
  68.  
  69. // 🔹 主內容容器加寬並居中
  70. const mainContent = document.querySelector('main.css-175oi2r.r-16y2uox.r-1wbh5a2.r-1habvwh');
  71. if (mainContent) {
  72. Object.assign(mainContent.style, {
  73. width: '100%',
  74. maxWidth: 'none',
  75. marginLeft: 'auto',
  76. marginRight: 'auto',
  77. });
  78. }
  79.  
  80. // 🔹 推文容器加寬並居中
  81. const containers = document.querySelectorAll([
  82. 'div.r-1oszu61.r-1niwhzg.r-18u37iz.r-16y2uox.r-2llsf.r-13qz1uu.r-1wtj0ep',
  83. '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'
  84. ].join(', '));
  85. containers.forEach(el => {
  86. Object.assign(el.style, {
  87. width: '1200px',
  88. maxWidth: 'none',
  89. marginLeft: 'auto',
  90. marginRight: 'auto',
  91. });
  92. });
  93.  
  94. // 🔹 向右平移右側區塊
  95. const moveTargetRight = document.querySelector('div.r-aqfbo4.r-10f7w94.r-1hycxz.r-1udh08x');
  96. if (moveTargetRight) {
  97. moveTargetRight.style.transform = 'translateX(10px)';
  98. }
  99.  
  100. // 🔹 向左平移 header 區塊
  101. const moveTargetLeft = document.querySelector('header.r-lrvibr.r-1g40b8q.r-obd0qt.r-16y2uox div.r-o96wvk.r-pt392 div.r-aqfbo4.r-1pi2tsx.r-1xcajam.r-ipm5af');
  102. if (moveTargetLeft) {
  103. moveTargetLeft.style.transform = 'translateX(-30px)';
  104. }
  105.  
  106. } catch (e) {
  107. console.error('腳本執行錯誤:', e);
  108. }
  109. });
  110.  
  111. observer.observe(document.body, { childList: true, subtree: true });
  112. })();