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

hidden Menu,Grok,Premium subscription,Explore,Notifications,Messages,Bookmarks and Customizable Settings

当前为 2024-06-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name X/Twitter Clean menu and sidebar (Supports multiple language)
  3. // @name:ja X/Twitter きれいなメニューとサイドバー(多言語対応)
  4. // @name:zh-TW X/Twitter 乾淨的選單和側邊欄(支持多種語言)
  5. // @name:zh-cn X/Twitter 干净的选单和侧边栏(支持多种语言)
  6. // @version 1.1
  7. // @description hidden Menu,Grok,Premium subscription,Explore,Notifications,Messages,Bookmarks and Customizable Settings
  8. // @description:ja 清潔なメニュー、Grok、高度なサブスクリプション、探索、通知、メッセージ、ブックマーク、およびカスタム設定
  9. // @description:zh-tw 乾淨的 選單、Grok、高級訂閱、探索、通知、訊息、書籤和可自訂設定
  10. // @description:zh-cn 干净的 选单、Grok、高级订阅、探索、通知、私信、书签和可自订设定
  11. // @license MIT
  12. // @author movwei
  13. // @match https://x.com/*
  14. // @match https://twitter.com/*
  15. // @grant GM_registerMenuCommand
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @grant GM_addStyle
  19. // @namespace https://greasyfork.org/users/1041101
  20. // ==/UserScript==
  21.  
  22. (function() {
  23. 'use strict';
  24.  
  25. const defaultSettings = {
  26. hideGrok: true,
  27. hidePremiumSignUp: true,
  28. hideSelectors: true,
  29. hideExplore: false,
  30. hideNotifications: false,
  31. hideBookmarks: false,
  32. hideMessages: false
  33. };
  34.  
  35. const settings = {
  36. hideGrok: GM_getValue('hideGrok', defaultSettings.hideGrok),
  37. hidePremiumSignUp: GM_getValue('hidePremiumSignUp', defaultSettings.hidePremiumSignUp),
  38. hideSelectors: GM_getValue('hideSelectors', defaultSettings.hideSelectors),
  39. hideExplore: GM_getValue('hideExplore', defaultSettings.hideExplore),
  40. hideNotifications: GM_getValue('hideNotifications', defaultSettings.hideNotifications),
  41. hideBookmarks: GM_getValue('hideBookmarks', defaultSettings.hideBookmarks),
  42. hideMessages: GM_getValue('hideMessages', defaultSettings.hideMessages)
  43. };
  44.  
  45. // 多語言支持
  46. const language = navigator.language || navigator.userLanguage;
  47. const languages = {
  48. 'en': {
  49. 'hideGrok': 'Hide Grok',
  50. 'hidePremiumSignUp': 'Hide Premium Sign-up',
  51. 'hideSelectors': 'Hide Subscribe Message',
  52. 'hideExplore': 'Hide Explore',
  53. 'hideNotifications': 'Hide Notifications',
  54. 'hideMessages': 'Hide Messages',
  55. 'hideBookmarks': 'Hide Bookmarks',
  56. 'settings': 'Settings',
  57. 'saveRefresh': 'Save & refresh',
  58. 'close': 'Close'
  59. },
  60. 'zh-TW': {
  61. 'hideGrok': '隱藏 Grok',
  62. 'hidePremiumSignUp': '隱藏 高級訂閱',
  63. 'hideSelectors': '隱藏 訂閱訊息',
  64. 'hideExplore': '隱藏 探索',
  65. 'hideNotifications': '隱藏 通知',
  66. 'hideMessages': '隱藏 訊息',
  67. 'hideBookmarks': '隱藏 書籤',
  68. 'settings': '設定',
  69. 'saveRefresh': '保存並刷新',
  70. 'close': '關閉'
  71. },
  72. 'zh-CN': {
  73. 'hideGrok': '隐藏 Grok',
  74. 'hidePremiumSignUp': '隐藏 高级订阅',
  75. 'hideSelectors': '隐藏 订阅消息',
  76. 'hideExplore': '隐藏 探索',
  77. 'hideNotifications': '隐藏 通知',
  78. 'hideMessages': '隐藏 私信',
  79. 'hideBookmarks': '隐藏 书签',
  80. 'settings': '设置',
  81. 'saveRefresh': '保存并刷新',
  82. 'close': '关闭'
  83. },
  84. 'ja': {
  85. 'hideGrok': 'Grokを非表示',
  86. 'hidePremiumSignUp': 'プレミアムサインアップを非表示',
  87. 'hideSelectors': 'サブスクライブメッセージを非表示',
  88. 'hideExplore': '話題を検索を非表示',
  89. 'hideNotifications': '通知を非表示',
  90. 'hideMessages': 'メッセージを非表示',
  91. 'hideBookmarks': 'ブックマークを非表示',
  92. 'settings': '設定',
  93. 'saveRefresh': '保存してリフレッシュ',
  94. 'close': '閉じる'
  95. },
  96. };
  97.  
  98. const currentLanguage = languages[language] || languages['en'];
  99.  
  100. function createSettingsPanel() {
  101. const panel = document.createElement('div');
  102. panel.id = 'settingsPanel';
  103. panel.innerHTML = `
  104. <div id="settingsPanelContent">
  105. <h2>${currentLanguage['settings']}</h2>
  106. <label><input type="checkbox" id="hideGrokCheckbox" ${settings.hideGrok ? 'checked' : ''}> ${currentLanguage['hideGrok']}</label><br>
  107. <label><input type="checkbox" id="hidePremiumSignUpCheckbox" ${settings.hidePremiumSignUp ? 'checked' : ''}> ${currentLanguage['hidePremiumSignUp']}</label><br>
  108. <label><input type="checkbox" id="hideSelectorsCheckbox" ${settings.hideSelectors ? 'checked' : ''}> ${currentLanguage['hideSelectors']}</label><br>
  109. <label><input type="checkbox" id="hideExploreCheckbox" ${settings.hideExplore ? 'checked' : ''}> ${currentLanguage['hideExplore']}</label><br>
  110. <label><input type="checkbox" id="hideNotificationsCheckbox" ${settings.hideNotifications ? 'checked' : ''}> ${currentLanguage['hideNotifications']}</label><br>
  111. <label><input type="checkbox" id="hideMessagesCheckbox" ${settings.hideMessages ? 'checked' : ''}> ${currentLanguage['hideMessages']}</label><br>
  112. <label><input type="checkbox" id="hideBookmarksCheckbox" ${settings.hideBookmarks ? 'checked' : ''}> ${currentLanguage['hideBookmarks']}</label><br>
  113. <button id="saveSettingsButton">${currentLanguage['saveRefresh']}</button>
  114. <button id="closeSettingsButton">${currentLanguage['close']}</button>
  115. </div>
  116. `;
  117. document.body.appendChild(panel);
  118.  
  119. document.getElementById('saveSettingsButton').addEventListener('click', saveSettings);
  120.  
  121. document.getElementById('closeSettingsButton').addEventListener('click', () => {
  122. document.getElementById('settingsPanel').style.display = 'none';
  123. });
  124. }
  125.  
  126. function saveSettings() {
  127. settings.hideGrok = document.getElementById('hideGrokCheckbox').checked;
  128. settings.hidePremiumSignUp = document.getElementById('hidePremiumSignUpCheckbox').checked;
  129. settings.hideSelectors = document.getElementById('hideSelectorsCheckbox').checked;
  130. settings.hideExplore = document.getElementById('hideExploreCheckbox').checked;
  131. settings.hideNotifications = document.getElementById('hideNotificationsCheckbox').checked;
  132. settings.hideBookmarks = document.getElementById('hideBookmarksCheckbox').checked;
  133. settings.hideMessages = document.getElementById('hideMessagesCheckbox').checked;
  134.  
  135. GM_setValue('hideGrok', settings.hideGrok);
  136. GM_setValue('hidePremiumSignUp', settings.hidePremiumSignUp);
  137. GM_setValue('hideSelectors', settings.hideSelectors);
  138. GM_setValue('hideExplore', settings.hideExplore);
  139. GM_setValue('hideNotifications', settings.hideNotifications);
  140. GM_setValue('hideBookmarks', settings.hideBookmarks);
  141. GM_setValue('hideMessages', settings.hideMessages);
  142. location.reload();
  143. }
  144.  
  145.  
  146. GM_addStyle(`
  147. #settingsPanel {
  148. width: 250px;
  149. position: fixed;
  150. top: 50%;
  151. left: 50%;
  152. transform: translate(-50%, -50%);
  153. background-color: white;
  154. border: 1px solid #ccc;
  155. padding: 20px;
  156. z-index: 10000;
  157. display: none;
  158. box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  159. border-radius: 8px;
  160. }
  161.  
  162. #settingsPanelContent {
  163. display: flex;
  164. flex-direction: column;
  165. align-items: flex-start;
  166. width: 100%;
  167. }
  168.  
  169. #settingsPanel h2 {
  170. margin: 0 0 15px 0;
  171. font-size: 18px;
  172. color: #333;
  173. text-align: center;
  174. width: 100%;
  175. }
  176.  
  177. #settingsPanel label {
  178. margin: 5px 0;
  179. font-size: 14px;
  180. color: #333;
  181. }
  182.  
  183. #settingsPanel button {
  184. margin-top: 10px;
  185. padding: 8px 15px;
  186. font-size: 14px;
  187. color: white;
  188. background-color: #007BFF;
  189. border: none;
  190. border-radius: 4px;
  191. cursor: pointer;
  192. width: 100%;
  193. }
  194.  
  195. #settingsPanel button#closeSettingsButton {
  196. background-color: #6c757d;
  197. }
  198. `);
  199.  
  200.  
  201. createSettingsPanel();
  202. GM_registerMenuCommand(currentLanguage['settings'], () => {
  203. const panel = document.getElementById('settingsPanel');
  204. panel.style.display = 'block';
  205. });
  206.  
  207. function addGlobalStyle(css) {
  208. var head, style;
  209. head = document.getElementsByTagName('head')[0];
  210. if (!head) { return; }
  211. style = document.createElement('style');
  212. style.type = 'text/css';
  213. style.innerHTML = css;
  214. head.appendChild(style);
  215. }
  216.  
  217.  
  218. var phrases = [
  219. 'Premium\'a Abone Ol', // 土耳其文 - Türkçe
  220. 'Abonner på Premium', // 丹麥文 - dansk
  221. '', // 巴斯克文 (測試版) - euskara
  222. 'プレミアムにサブスクライブ', // 日文 - 日本語
  223. '', // 加利西亞文 (測試版) - galego
  224. 'Subscriu-te a Premium', // 加泰蘭文 - català
  225. 'પ્રીમિયમ પર સબ્સ્ક્રાઇબ કરો', // 古吉拉特文 - ગુજરાતી
  226. 'Fizess elő a Premiumra!', // 匈牙利文 - magyar
  227. 'Berlangganan Premium', // 印尼文 - Indonesia
  228. 'Premium को सब्सक्राइब करें', // 印地文 - हिन्दी
  229. 'Suscríbete a Premium', // 西班牙文 - español
  230. 'Pretplatite se na Premium', // 克羅埃西亞文 - hrvatski
  231. 'Premiumಗೆ ಸಬ್‌ಸ್ರೈಬ್ ಮಾಡಿ', // 坎那達文 - ಕನ್ನಡ
  232. 'הרשמה ל-Premium', // 希伯來文 - עברית
  233. 'Εγγραφή στο Premium', // 希臘文 - Ελληνικά
  234. 'Premium-க்குச் சப்ஸ்கிரைப் செய்', // 坦米爾文 - தமிழ்
  235. 'Premium-এ সাবস্ক্রাইব করুন', // 孟加拉文 - বাংলা
  236. 'Abonnez‑vous à Premium', // 法文 - français
  237. 'اشتراک در Premium', // 波斯文 - فارسی
  238. 'Zasubskrybuj usługę Premium', // 波蘭文 - polski
  239. 'Tilaa Premium', // 芬蘭文 - suomi
  240. 'الاشتراك في Premium', // 阿拉伯文 - العربية
  241. 'الاشتراك في Premium', // 阿拉伯文 (陰性) - العربية (مؤنث)
  242. 'Подпишитесь на Premium', // 俄文 - русский
  243. 'Абонирайте се за Premium', // 保加利亞文 - български
  244. 'Subscribe to Premium', // 英文 - English
  245. 'Subscribe to Premium', // 英文(英國) - British English
  246. '', // 挪威文 - norsk
  247. 'สมัครสมาชิก Premium', // 泰文 - ไทย
  248. 'Передплатити Premium', // 烏克蘭文 - українська
  249. '', // 烏都文 (測試版) - اردو
  250. 'Langgan Premium', // 馬來文 - Melayu
  251. 'Premium ची सदस्यता घ्या', // 馬拉地文 - मराठी
  252. 'Přihlaste se k odběru předplatného Premium', // 捷克文 - čeština X
  253. 'Abonneren op Premium', // 荷蘭文 - Nederlands
  254. 'Zaregistrujte sa do služby Premium', // 斯洛伐克文 - slovenčina
  255. 'Mag-subscribe sa Premium', // 菲律賓文 - Filipino
  256. 'Đăng ký gói Premium', // 越南文 - Tiếng Việt
  257. 'Претплати се на Premium', // 塞爾維亞文 - српски
  258. '', // 愛爾蘭文 (測試版) - Gaeilge
  259. 'Prenumerera på Premium', // 瑞典文 - svenska
  260. 'Abbonati a Premium', // 義大利文 - italiano
  261. 'Assine o Premium', // 葡萄牙文 - português
  262. 'Premium abonnieren', // 德文 - Deutsch
  263. '訂閱 Premium', // 繁體中文
  264. 'Premium 구독하기', // 韓文 - 한국어
  265. '订阅 Premium', // 简体中文
  266. 'Abonează-te la Premium', // 羅馬尼亞文 - română
  267. ];
  268.  
  269.  
  270. var selectors = phrases.map(function(phrase) {
  271. if (phrase !== '') {
  272. return 'aside[aria-label="' + phrase + '"]';
  273. } else {
  274. return '';
  275. }
  276. }).filter(selector => selector !== '').join(', ');
  277.  
  278. var cssRules = '';
  279. if (settings.hideSelectors) {
  280. cssRules += selectors + '{ display: none !important; }';
  281. }
  282. if (settings.hideGrok) {
  283. cssRules += 'a[href="/i/grok"] { display: none !important; }';
  284. }
  285. if (settings.hidePremiumSignUp) {
  286. cssRules += 'a[href="/i/premium_sign_up"] { display: none !important; }';
  287. }
  288. if (settings.hideExplore) {
  289. cssRules += 'a[href="/explore"] { display: none !important; }';
  290. }
  291. if (settings.hideNotifications) {
  292. cssRules += 'a[href="/notifications"] { display: none !important; }';
  293. }
  294. if (settings.hideBookmarks) {
  295. cssRules += 'a[href="/i/bookmarks"] { display: none !important; }';
  296. }
  297. if (settings.hideMessages) {
  298. cssRules += 'a[href="/messages"] { display: none !important; }';
  299. }
  300.  
  301. addGlobalStyle(cssRules);
  302. })();