Threads Custom Keyboard Navigation

Customize keyboard shortcuts for navigating Threads features

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

  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.13
  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("keypress", this.keydownHandler);
  33. const boardKey = GM_getValue("boardKey", { Home: "F", Notifications: "D", Profile: "S", Search: "A", Create: "B", BacK:"G"});
  34. console.log("開始聆聽", boardKey);
  35. }
  36.  
  37. handleKeydown(event) {
  38. const boardKey = GM_getValue("boardKey", { Home: "F", Notifications: "D", Profile: "S", Search: "A", Create: "B", BacK:"G"});
  39. const boardButtons = document.querySelectorAll(this.boardButtons);
  40. const newPostButton = document.querySelector(this.newPostButton);
  41. const backButton=document.querySelector(this.backButton);
  42. const keyMap = {
  43. Home: boardButtons[0],
  44. Notifications: boardButtons[2],
  45. Profile: boardButtons[3],
  46. Search: boardButtons[1],
  47. Create: newPostButton,
  48. Back:backButton,
  49. };
  50.  
  51. for (const [key, element] of Object.entries(boardKey)) {
  52. if (event.key.toUpperCase() === element.toUpperCase()) {
  53. console.log(key.toLowerCase());
  54. keyMap[key].click();
  55. break;
  56. }
  57. }
  58. }
  59. }
  60.  
  61. class inputCustomMenu{
  62. constructor() {
  63. this.registerMenuCommands(this);
  64. this.loadBoardKey();
  65. }
  66.  
  67. async customizeKey(buttonType) {
  68. const currentKey = this.boardKey[buttonType];
  69. const newKey = prompt(`${this.getFeatureMessageLocalization(`EnterNew${buttonType}Letter`)}${currentKey}`);
  70.  
  71. if (newKey && newKey.length === 1) {
  72. this.boardKey[buttonType] = newKey;
  73. this.saveBoardKey();
  74. } else {
  75. alert(this.getFeatureMessageLocalization("CustomKeyError"));
  76. }
  77. }
  78.  
  79. loadBoardKey() {
  80. this.boardKey = GM_getValue("boardKey", { Home: "F", Notifications: "D", Profile: "S", Search: "A", Create: "B", BacK:"G"});
  81. console.log(this.boardKey);
  82. }
  83.  
  84. saveBoardKey() {
  85. GM_setValue("boardKey", this.boardKey);
  86. }
  87.  
  88. getFeatureMessageLocalization(word) {
  89. let display = {
  90. "zh-TW": {
  91. "CustomizeHome": "自訂首頁按鍵",
  92. "CustomizeNotifications": "自訂通知按鍵",
  93. "CustomizeProfile": "自訂個人簡介按鍵",
  94. "CustomizeSearch": "自訂搜尋按鍵",
  95. "CustomizeCreate": "自訂新貼文按鍵",
  96. "CustomizeBack": "自訂返回按鍵",
  97. "EnterNewHomeLetter": "請輸入要替換首頁按鈕的一個英文字母或數字,目前為:",
  98. "EnterNewNotificationsLetter": "請輸入要替換通知按鈕的一個英文字母或數字,目前為:",
  99. "EnterNewProfileLetter": "請輸入要替換個人簡介按鈕的一個英文字母或數字,目前為:",
  100. "EnterNewSearchLetter": "請輸入要替換搜尋按鈕的一個英文字母或數字,目前為:",
  101. "EnterNewCreateLetter": "請輸入要替換新貼文按鈕的一個英文字母或數字,目前為:",
  102. "EnterNewBackLetter": "請輸入要替換返回按鈕的一個英文字母或數字,目前為:",
  103. "CustomKeyError": "自訂按鍵錯誤,請輸入一個英文字母或數字。",
  104. },
  105. "en": {
  106. "CustomizeHome": "Customize home button",
  107. "CustomizeNotifications": "Customize notification buttons",
  108. "CustomizeProfile": "Customize profile button",
  109. "CustomizeSearch": "Customize search button",
  110. "CustomizeCreate": "Customize the new post button",
  111. "EnterNewHomeLetter": "Please enter an English letter or number to replace the home button. Currently:",
  112. "EnterNewNotificationsLetter": "Please enter an English letter or number to replace the notification button, currently:",
  113. "EnterNewProfileLetter": "Please enter an English letter or number to replace the profile button. Currently:",
  114. "EnterNewSearchLetter": "Please enter an English letter or number to replace the search button. Currently:",
  115. "EnterNewCreateLetter": "Please enter an English letter or number to replace the new post button. Currently:",
  116. "EnterNewBackLetter": "Please enter a letter or number to be replaced back button, currently:",
  117. "CustomKeyError": "Custom key error, please enter an English letter or number.",
  118. },
  119. "ja": {
  120. "CustomizeHome": "ホームボタンをカスタマイズ",
  121. "CustomizeNotifications": "通知ボタンをカスタマイズする",
  122. "CustomizeProfile": "プロファイル ボタンをカスタマイズ",
  123. "CustomizeSearch": "検索ボタンをカスタマイズ",
  124. "CustomizeCreate": "新規投稿ボタンをカスタマイズします",
  125. "EnterNewHomeLetter": "ホーム ボタンを置き換える英語の文字または數字を入力してください。現在:",
  126. "EnterNewNotificationsLetter": "通知ボタンを置き換える英語の文字または數字を入力してください。現在:",
  127. "EnterNewProfileLetter": "プロフィール ボタンを置き換える英語の文字または數字を入力してください。現在:",
  128. "EnterNewSearchLetter": "検索ボタンを置き換える英語の文字または數字を入力してください。現在:",
  129. "EnterNewCreateLetter": "新しい投稿ボタンを置き換えるには、英語の文字または數字を入力してください。現在:",
  130. "EnterNewBackLetter": "戻るボタンを置き換える英語の文字または數字を入力してください。現在:",
  131. "CustomKeyError": "カスタム キー エラーです。英語の文字または數字を入力してください。",
  132. }
  133. };
  134. return display[navigator.language][word];
  135. }
  136.  
  137. registerMenuCommands(instance) {
  138. const buttonTypes = ["Home", "Notifications", "Profile", "Search", "Create","Back"];
  139. buttonTypes.forEach(type => {
  140. GM_registerMenuCommand(instance.getFeatureMessageLocalization(`Customize${type}`), () => instance.customizeKey(type));
  141. });
  142. }
  143. }
  144.  
  145. const johnTheAlmondHolder = new boardInputNavigation();
  146. const johnTheRestaurantWaiter = new inputCustomMenu();

QingJ © 2025

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