Hide unnecessary X menu items on the left (Bookmarks, Jobs, Communities, Business, Premium, Verified Organizations, Monetization, Ads) and right (Subscribe to Premium, Footer), Bottom right (floating message bar, Grok), Enlarge and customize the width of the tweet timeline, Custom Script Loading Speed (supports Traditional Chinese, Simplified Chinese, English, Japanese).
// ==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 5.2
// @description Hide unnecessary X menu items on the left (Bookmarks, Jobs, Communities, Business, Premium, Verified Organizations, Monetization, Ads) and right (Subscribe to Premium, Footer), Bottom right (floating message bar, Grok), Enlarge and customize the width of the tweet timeline, Custom Script Loading Speed (supports Traditional Chinese, Simplified Chinese, English, Japanese).
// @description:zh-TW 隱藏 X 多餘選單項目,左側(書籤、工作機會、社群、商業、Premium、已認證組織、營利、廣告)、右側(訂閱 Premium、頁尾欄目)、右下(浮動訊息欄、Grok),加大、自定義推文時間軸的寬度,自定義腳本加載速度 (支援繁中、簡中、英文、日文)
// @description:zh-CN 隐藏 X 多余选单项目,左侧(书签、工作机会、社群、商业、Premium、已认证组织、营利、广告)、右侧(订阅 Premium、页尾栏目)、右下(浮动讯息栏、Grok),加大、自定义推文时间轴的宽度,自定义脚本加载速度 (支援繁中、简中、英文、日文)
// @description:JA Xの不要なメニュー項目を左側(ブックマーク、求人、コミュニティ、ビジネス、Premium、認証済み組織、収益化、広告)および右側(Premiumの購読、フッター) 右下(フローティングメッセージバー、Grok)で非表示にし、 ツイートのタイムラインの幅を拡大し、カスタマイズする、カスタムスクリプトの読み込み速度(繁体字中国語、簡体字中国語、英語、日本語に対応)。
// @author Hzbrrbmin + ChatGPT
// @match https://x.com/*
// @match https://twitter.com/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @license MIT
// ==/UserScript==
(function () {
'use strict';
// ===【0】排除特定頁面(訊息與設定頁)===
const excludedPaths = ['/messages', '/settings'];
if (excludedPaths.some(path => location.pathname.startsWith(path))) {
return;
}
// ===【1】預設參數設定 ===
const defaultWidth = 1200; // 推文時間軸預設寬度
const defaultDebounce = 0; // 防抖延遲預設為 0(即關閉)
// ===【2】讀取使用者已儲存的設定 ===
let timelineWidth = GM_getValue('timelineWidth', defaultWidth);
let debounceDelay = GM_getValue('debounceDelay', defaultDebounce);
// ===【3】註冊選單:左側欄顯示/隱藏開關 ===
let hideLeftbar = GM_getValue('hideLeftbar', false); // 預設顯示
GM_registerMenuCommand(`${hideLeftbar ? '顯示' : '隱藏'}左側欄`, () => {
hideLeftbar = !hideLeftbar;
GM_setValue('hideLeftbar', hideLeftbar);
location.reload(); // 切換後自動重整頁面
});
function applyLeftbarToggle() {
const leftbar = document.querySelector('header[role="banner"]');
if (leftbar) {
leftbar.style.display = hideLeftbar ? 'none' : '';
}
}
// ===【4】註冊選單:右側欄顯示/隱藏開關 ===
let hideSidebar = GM_getValue('hideSidebar', false); // 預設顯示
GM_registerMenuCommand(`${hideSidebar ? '顯示' : '隱藏'}右側欄`, () => {
hideSidebar = !hideSidebar;
GM_setValue('hideSidebar', hideSidebar);
location.reload(); // 切換後自動重整頁面
});
function applySidebarToggle() {
const sidebar = document.querySelector('[data-testid="sidebarColumn"]');
if (sidebar) {
sidebar.style.display = hideSidebar ? 'none' : '';
}
}
// ===【5】註冊選單:中間欄填滿開關 ===
let fillCenter = GM_getValue('fillCenter', false); // 預設關閉
GM_registerMenuCommand(`${fillCenter ? '取消' : '啟用'}中間欄填滿`, () => {
fillCenter = !fillCenter;
GM_setValue('fillCenter', fillCenter);
if (fillCenter) {
// 開啟中間欄填滿 → 強制隱藏左右欄
hideSidebar = true;
hideLeftbar = true;
} else {
// 關閉中間欄填滿 → 強制顯示左右欄
hideSidebar = false;
hideLeftbar = false;
}
GM_setValue('hideSidebar', hideSidebar);
GM_setValue('hideLeftbar', hideLeftbar);
location.reload(); // 切換後自動刷新
});
function applyCenterFillToggle() {
if (!fillCenter) return; // 開關關閉時不執行任何操作
// 針對 class .r-113js5t 強制寬度 100%
document.querySelectorAll('.r-113js5t').forEach(el => {
el.style.width = fillCenter ? '100%' : '';
});
// 針對 div.r-f8sm7e.r-13qz1uu.r-1ye8kvj 設定 width:100%
document.querySelectorAll('div.r-f8sm7e.r-13qz1uu.r-1ye8kvj').forEach(el => {
el.style.width = fillCenter ? '100%' : '';
});
}
// ===【6】註冊選單:時間軸寬度設定 ===
GM_registerMenuCommand(`設定:時間軸推文寬度,目前為:${timelineWidth}px`, () => {
const input = prompt('請輸入時間軸推文寬度(600 ~ 3000 px):', timelineWidth);
const val = parseInt(input);
if (!isNaN(val) && val >= 600 && val <= 3000) {
GM_setValue('timelineWidth', val);
location.reload();
} else {
alert('請輸入合理的數值(600 ~ 3000)');
}
});
// ===【7】註冊選單:防抖延遲時間設定 ===
GM_registerMenuCommand(`設定:防抖延遲時間(毫秒),目前為:${debounceDelay}ms`, () => {
const input = prompt('請輸入防抖延遲時間(0 表示關閉,1~300 表示啟用防抖):', debounceDelay);
const val = parseInt(input);
if (!isNaN(val) && val >= 0 && val <= 300) {
GM_setValue('debounceDelay', val);
location.reload();
} else {
alert('請輸入合理的數值(0 ~ 300)');
}
});
// ===【8】防抖函式封裝 ===
function debounce(func, delay) {
let timer = null;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => func.apply(this, args), delay);
};
}
// ===【9】主處理函式 ===
function cleanUpAndResize() {
try {
// -- 隱藏左側多語系選單項目 --
const labels = [
'書籤', 'Bookmarks', 'ブックマーク', '书签',
'工作機會', 'Careers', '求人', '工作机会',
'社群', 'Communities', 'コミュニティ', '社区',
'商業', '商业', 'ビジネス', 'Business',
'Premium', 'プレミアム',
'已認證組織', 'Verified Orgs', '認証済み組織', '认证组织',
'營利', 'Monetization', '収益化', '营利',
'廣告', 'Ads', '広告', '广告',
];
document.querySelectorAll('nav[role="navigation"] div[dir="ltr"]').forEach(item => {
const label = item.innerText?.trim();
if (labels.includes(label)) {
const top = item.closest('a, div[role="link"]');
if (top) top.style.display = 'none';
}
});
// -- 隱藏右側 Premium 推銷卡片 --
const premiumCard = document.querySelector('.css-175oi2r[data-testid="super-upsell-UpsellCardRenderProperties"]');
if (premiumCard) premiumCard.style.display = 'none';
// -- 隱藏頁尾區塊(多語系 aria-label) --
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 messagePanels = document.querySelectorAll('#layers div.r-1jte41z');
messagePanels.forEach(el => {
el.style.display = 'none';
});
// -- 加寬主內容區塊(時間軸整體) --
const main = document.querySelector('main.css-175oi2r');
if (main) {
Object.assign(main.style, {
width: '100%',
maxWidth: 'none',
marginLeft: 'auto',
marginRight: 'auto',
});
}
// -- 加寬推文容器(時間軸) --
const containers = document.querySelectorAll('div.r-f8sm7e.r-13qz1uu.r-1ye8kvj');
containers.forEach(el => {
Object.assign(el.style, {
width: `${timelineWidth}px`,
maxWidth: 'none',
marginLeft: 'auto',
marginRight: 'auto',
});
});
// -- 推文操作列寬度繼承外層,避免寬度錯位 --
const actionBars = document.querySelectorAll('div.r-1kbdv8c');
actionBars.forEach(el => {
Object.assign(el.style, {
width: '100%',
maxWidth: 'none',
});
});
// 套用左側欄開關
applyLeftbarToggle();
// 套用右側欄開關
applySidebarToggle();
// 套用中間欄開關
applyCenterFillToggle();
} catch (e) {
console.error('腳本錯誤:', e);
}
}
// ===【10】啟用 MutationObserver 搭配防抖監控畫面變更 ===
const handler = debounceDelay >= 1 && debounceDelay <= 300
? debounce(cleanUpAndResize, debounceDelay)
: cleanUpAndResize;
const observer = new MutationObserver(handler);
observer.observe(document.body, { childList: true, subtree: true });
})();