Threads自訂鍵盤導航

自訂鍵盤快捷鍵以瀏覽Threads功能

安裝腳本?
作者推薦腳本

您可能也會喜歡 脆的千喜問題

安裝腳本
  1. // ==UserScript==
  2. // @name Threads Custom Keyboard Navigation
  3. // @name:zh-TW Threads自訂鍵盤導航
  4. // @name:ja Threadsカスタムキーボードナビゲーション
  5. // @name:en Threads Custom Keyboard Navigation
  6. // @namespace https://github.com/Max46656
  7. // @version 1.14
  8. // @description Customize keyboard shortcuts for navigating Threads features
  9. // @description:zh-TW 自訂鍵盤快捷鍵以瀏覽Threads功能
  10. // @description:ja Threads 機能をトリガーするためのカスタムキーボードショートカット
  11. // @description:en Customize keyboard shortcuts for navigating Threads features
  12. // @author Max
  13. // @match https://www.threads.net/*
  14. // @icon https://www.google.com/s2/favicons?sz=64&domain=threads.net
  15. // @grant GM_registerMenuCommand
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @license MPL2.0
  19.  
  20. // ==/UserScript==
  21.  
  22. class boardInputNavigation {
  23. constructor() {
  24. this.setEventListeners();
  25. this.boardButtons = '.xefz13k.x1lq5wgf.xgqcy7u.x30kzoy';
  26. this.backButton = '.x1nhvcw1 .x1u6grsq .x1i10hfl';
  27. this.newPostButton = '.x1i10hfl.x1ypdohk.xdl72j9.x2lah0s.xe8uvvx.xdj266r.x11i5rnm.xat24cr.x1mh8g0r.x2lwn1j.xeuugli.xexx8yu.x4uap5.x18d9i69.xkhd6sd.x16tdsg8.x1hl2dhg.xggy1nq.x1t137rt.x1q0g3np.x87ps6o.x1lku1pv.x1a2a7pz.x6s0dn4.xz401s1.x6bh95i.x1re03b8.x1hvtcl2.x3ug3ww.xfh8nwu.xoqspk4.x12v9rci.x138vmkv.x13fuv20.xu3j5b3.x1q0q8m5.x26u7qi.xt8cgyo.xj515ic.x1co6499.x2j4hbs.xy58vm5.x1elh40u.x9f619.x78zum5.xrsfl73.x1gb2em4.xl56j7k.xixxii4.x12w9bfk.x13dflua.x11xpdln.x1pigqs1.x1vjfegm.xd3so5o.x1lcra6a';
  28. }
  29.  
  30. setEventListeners() {
  31. this.keydownHandler = (event) => this.handleKeydown(event);
  32. self.addEventListener("keydown", this.keydownHandler);
  33. const boardKey = GM_getValue("boardKey", { Home: "F", Notifications: "D", Profile: "S", Search: "A", Create: "B", Back: "G" });
  34. const modifierKey = GM_getValue("modifierKey", "Control");
  35. console.log("開始聆聽", boardKey, modifierKey);
  36. }
  37.  
  38. handleKeydown(event) {
  39. const boardKey = GM_getValue("boardKey", { Home: "F", Notifications: "D", Profile: "S", Search: "A", Create: "B", Back: "G" });
  40. const modifierKey = GM_getValue("modifierKey", "Control");
  41. const boardButtons = document.querySelectorAll(this.boardButtons);
  42. const newPostButton = document.querySelector(this.newPostButton);
  43. const backButton = document.querySelector(this.backButton);
  44. const keyMap = {
  45. Home: boardButtons[0],
  46. Notifications: boardButtons[2],
  47. Profile: boardButtons[3],
  48. Search: boardButtons[1],
  49. Create: newPostButton,
  50. Back: backButton,
  51. };
  52.  
  53. if (event.getModifierState(modifierKey)) {
  54. for (const [key, element] of Object.entries(boardKey)) {
  55. if (event.key.toUpperCase() === element.toUpperCase()) {
  56. event.preventDefault();
  57. console.log(key.toLowerCase());
  58. keyMap[key].click();
  59. break;
  60. }
  61. }
  62. }
  63. }
  64. }
  65.  
  66. class inputCustomMenu {
  67. constructor() {
  68. this.registerMenuCommands(this);
  69. this.loadBoardKey();
  70. this.loadModifierKey();
  71. }
  72.  
  73. async customizeKey(buttonType) {
  74. const currentKey = this.boardKey[buttonType];
  75. const newKey = prompt(`${this.getFeatureMessageLocalization(`EnterNew${buttonType}Letter`)}${currentKey}`);
  76.  
  77. if (newKey && newKey.length === 1) {
  78. this.boardKey[buttonType] = newKey;
  79. this.saveBoardKey();
  80. } else {
  81. alert(this.getFeatureMessageLocalization("CustomKeyError"));
  82. }
  83. }
  84.  
  85. async customizeModifierKey() {
  86. const currentModifierKey = this.modifierKey;
  87. const newModifierKey = prompt(`${this.getFeatureMessageLocalization("ChooseModifierKey")}\n1. Control\n2. Alt\n3. Shift\n4. CapsLock\n目前為:${currentModifierKey}`);
  88.  
  89. switch(newModifierKey) {
  90. case "1":
  91. this.modifierKey = "Control";
  92. break;
  93. case "2":
  94. this.modifierKey = "Alt";
  95. break;
  96. case "3":
  97. this.modifierKey = "Shift";
  98. break;
  99. case "4":
  100. this.modifierKey = "CapsLock";
  101. break;
  102. default:
  103. alert(this.getFeatureMessageLocalization("CustomModifierKeyError"));
  104. return;
  105. }
  106. this.saveModifierKey();
  107. }
  108.  
  109. loadBoardKey() {
  110. this.boardKey = GM_getValue("boardKey", { Home: "F", Notifications: "D", Profile: "S", Search: "A", Create: "B", Back: "G" });
  111. console.log(this.boardKey);
  112. }
  113.  
  114. loadModifierKey() {
  115. this.modifierKey = GM_getValue("modifierKey", "Control");
  116. console.log(this.modifierKey);
  117. }
  118.  
  119. saveBoardKey() {
  120. GM_setValue("boardKey", this.boardKey);
  121. }
  122.  
  123. saveModifierKey() {
  124. GM_setValue("modifierKey", this.modifierKey);
  125. }
  126.  
  127. getFeatureMessageLocalization(word) {
  128. let display = {
  129. "zh-TW": {
  130. "CustomizeHome": "自訂首頁按鍵",
  131. "CustomizeNotifications": "自訂通知按鍵",
  132. "CustomizeProfile": "自訂個人簡介按鍵",
  133. "CustomizeSearch": "自訂搜尋按鍵",
  134. "CustomizeCreate": "自訂新貼文按鍵",
  135. "CustomizeBack": "自訂返回按鍵",
  136. "CustomizeModifierKey": "自訂快捷鍵按鍵",
  137. "EnterNewHomeLetter": "請輸入要替換首頁按鈕的一個英文字母或數字,目前為:",
  138. "EnterNewNotificationsLetter": "請輸入要替換通知按鈕的一個英文字母或數字,目前為:",
  139. "EnterNewProfileLetter": "請輸入要替換個人簡介按鈕的一個英文字母或數字,目前為:",
  140. "EnterNewSearchLetter": "請輸入要替換搜尋按鈕的一個英文字母或數字,目前為:",
  141. "EnterNewCreateLetter": "請輸入要替換新貼文按鈕的一個英文字母或數字,目前為:",
  142. "EnterNewBackLetter": "請輸入要替換返回按鈕的一個英文字母或數字,目前為:",
  143. "ChooseModifierKey": "請輸入數字選擇要替換的快捷鍵按鍵(1 Control, 2 Alt, 3 Shift, 4 CapsLock):",
  144. "CustomKeyError": "自訂按鍵錯誤,請輸入一個英文字母或數字。",
  145. "CustomModifierKeyError": "自訂快捷鍵按鍵錯誤,請輸入 1, 2, 3 或 4。",
  146. },
  147. "en": {
  148. "CustomizeHome": "Customize home button",
  149. "CustomizeNotifications": "Customize notification buttons",
  150. "CustomizeProfile": "Customize profile button",
  151. "CustomizeSearch": "Customize search button",
  152. "CustomizeCreate": "Customize the new post button",
  153. "CustomizeBack": "Customize back button",
  154. "CustomizeModifierKey": "Customize Modifier Key",
  155. "EnterNewHomeLetter": "Please enter an English letter or number to replace the home button. Currently:",
  156. "EnterNewNotificationsLetter": "Please enter an English letter or number to replace the notification button, currently:",
  157. "EnterNewProfileLetter": "Please enter an English letter or number to replace the profile button. Currently:",
  158. "EnterNewSearchLetter": "Please enter an English letter or number to replace the search button. Currently:",
  159. "EnterNewCreateLetter": "Please enter an English letter or number to replace the new post button. Currently:",
  160. "EnterNewBackLetter": "Please enter a letter or number to be replaced back button, currently:",
  161. "ChooseModifierKey": "Please enter a number to choose the key to replace Modifier (1. Control, 2. Alt, 3. Shift, 4. CapsLock):",
  162. "CustomKeyError": "Custom key error, please enter an English letter or number.",
  163. "CustomModifierKeyError": "Custom Modifier Key error, please enter 1, 2, 3 or 4.",
  164. },
  165. "ja": {
  166. "CustomizeHome": "ホームボタンをカスタマイズ",
  167. "CustomizeNotifications": "通知ボタンをカスタマイズする",
  168. "CustomizeProfile": "プロファイル ボタンをカスタマイズ",
  169. "CustomizeSearch": "検索ボタンをカスタマイズ",
  170. "CustomizeCreate": "新規投稿ボタンをカスタマイズします",
  171. "CustomizeBack": "戻るボタンをカスタマイズ",
  172. "CustomizeModifierKey": "Modifierキーをカスタマイズ",
  173. "EnterNewHomeLetter": "ホーム ボタンを置き換える英語の文字または數字を入力してください。現在:",
  174. "EnterNewNotificationsLetter": "通知ボタンを置き換える英語の文字または數字を入力してください。現在:",
  175. "EnterNewProfileLetter": "プロフィール ボタンを置き換える英語の文字または數字を入力してください。現在:",
  176. "EnterNewSearchLetter": "検索ボタンを置き換える英語の文字または數字を入力してください。現在:",
  177. "EnterNewCreateLetter": "新しい投稿ボタンを置き換えるには、英語の文字または數字を入力してください。現在:",
  178. "EnterNewBackLetter": "戻るボタンを置き換える英語の文字または數字を入力してください。現在:",
  179. "ChooseModifierKey": "数字を入力して、modifierKeyボタンを置き換えるキーを選択してください(1. Control, 2. Alt, 3. Shift, 4. CapsLock):",
  180. "CustomKeyError": "カスタム キー エラーです。英語の文字または數字を入力してください。",
  181. "CustomModifierKeyError": "カスタムmodifierKeyキーエラー、1、2、3 または 4 を入力してください。",
  182. }
  183. };
  184. return display[navigator.language][word];
  185. }
  186.  
  187. registerMenuCommands(instance) {
  188. GM_registerMenuCommand(instance.getFeatureMessageLocalization("CustomizeModifierKey"), () => instance.customizeModifierKey());
  189. const buttonTypes = ["Home", "Notifications", "Profile", "Search", "Create", "Back"];
  190. buttonTypes.forEach(type => {
  191. GM_registerMenuCommand(instance.getFeatureMessageLocalization(`Customize${type}`), () => instance.customizeKey(type));
  192. });
  193. }
  194. }
  195.  
  196. const johnTheAlmondHolder = new boardInputNavigation();
  197. const johnTheRestaurantWaiter = new inputCustomMenu();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址