Threadsカスタムキーボードナビゲーション

Threads 機能をトリガーするためのカスタムキーボードショートカット

2024/05/31のページです。最新版はこちら

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