预设开启 Google 的“工具”选单

在 Google 搜索载入后自动打开“工具”选单。

  1. // ==UserScript==
  2. // @name Opens “Tools” Menu by Default on Google
  3. // @name:zh-TW 預設開啟 Google 的「工具」選單
  4. // @name:zh-CN 预设开启 Google 的“工具”选单
  5. // @name:ja Google のデフォルトで「ツール」メニューを開く
  6. // @description Opens the “Tools” menu on Google Search automatically when page loaded.
  7. // @description:zh-TW 在 Google 搜尋載入後自動打開「工具」選單。
  8. // @description:zh-CN 在 Google 搜索载入后自动打开“工具”选单。
  9. // @description:ja ページが読み込まれると、Google 検索の「ツール」メニューが自動的に開きます。
  10. // @icon https://wsrv.nl/?url=https://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png
  11. // @author Jason Kwok
  12. // @namespace https://jasonhk.dev/
  13. // @version 1.2.1
  14. // @license MIT
  15. // @match https://www.google.com/search?*
  16. // @match https://www.google.ad/search?*
  17. // @match https://www.google.ae/search?*
  18. // @match https://www.google.com.af/search?*
  19. // @match https://www.google.com.ag/search?*
  20. // @match https://www.google.al/search?*
  21. // @match https://www.google.am/search?*
  22. // @match https://www.google.co.ao/search?*
  23. // @match https://www.google.com.ar/search?*
  24. // @match https://www.google.as/search?*
  25. // @match https://www.google.at/search?*
  26. // @match https://www.google.com.au/search?*
  27. // @match https://www.google.az/search?*
  28. // @match https://www.google.ba/search?*
  29. // @match https://www.google.com.bd/search?*
  30. // @match https://www.google.be/search?*
  31. // @match https://www.google.bf/search?*
  32. // @match https://www.google.bg/search?*
  33. // @match https://www.google.com.bh/search?*
  34. // @match https://www.google.bi/search?*
  35. // @match https://www.google.bj/search?*
  36. // @match https://www.google.com.bn/search?*
  37. // @match https://www.google.com.bo/search?*
  38. // @match https://www.google.com.br/search?*
  39. // @match https://www.google.bs/search?*
  40. // @match https://www.google.bt/search?*
  41. // @match https://www.google.co.bw/search?*
  42. // @match https://www.google.by/search?*
  43. // @match https://www.google.com.bz/search?*
  44. // @match https://www.google.ca/search?*
  45. // @match https://www.google.cd/search?*
  46. // @match https://www.google.cf/search?*
  47. // @match https://www.google.cg/search?*
  48. // @match https://www.google.ch/search?*
  49. // @match https://www.google.ci/search?*
  50. // @match https://www.google.co.ck/search?*
  51. // @match https://www.google.cl/search?*
  52. // @match https://www.google.cm/search?*
  53. // @match https://www.google.cn/search?*
  54. // @match https://www.google.com.co/search?*
  55. // @match https://www.google.co.cr/search?*
  56. // @match https://www.google.com.cu/search?*
  57. // @match https://www.google.cv/search?*
  58. // @match https://www.google.com.cy/search?*
  59. // @match https://www.google.cz/search?*
  60. // @match https://www.google.de/search?*
  61. // @match https://www.google.dj/search?*
  62. // @match https://www.google.dk/search?*
  63. // @match https://www.google.dm/search?*
  64. // @match https://www.google.com.do/search?*
  65. // @match https://www.google.dz/search?*
  66. // @match https://www.google.com.ec/search?*
  67. // @match https://www.google.ee/search?*
  68. // @match https://www.google.com.eg/search?*
  69. // @match https://www.google.es/search?*
  70. // @match https://www.google.com.et/search?*
  71. // @match https://www.google.fi/search?*
  72. // @match https://www.google.com.fj/search?*
  73. // @match https://www.google.fm/search?*
  74. // @match https://www.google.fr/search?*
  75. // @match https://www.google.ga/search?*
  76. // @match https://www.google.ge/search?*
  77. // @match https://www.google.gg/search?*
  78. // @match https://www.google.com.gh/search?*
  79. // @match https://www.google.com.gi/search?*
  80. // @match https://www.google.gl/search?*
  81. // @match https://www.google.gm/search?*
  82. // @match https://www.google.gr/search?*
  83. // @match https://www.google.com.gt/search?*
  84. // @match https://www.google.gy/search?*
  85. // @match https://www.google.com.hk/search?*
  86. // @match https://www.google.hn/search?*
  87. // @match https://www.google.hr/search?*
  88. // @match https://www.google.ht/search?*
  89. // @match https://www.google.hu/search?*
  90. // @match https://www.google.co.id/search?*
  91. // @match https://www.google.ie/search?*
  92. // @match https://www.google.co.il/search?*
  93. // @match https://www.google.im/search?*
  94. // @match https://www.google.co.in/search?*
  95. // @match https://www.google.iq/search?*
  96. // @match https://www.google.is/search?*
  97. // @match https://www.google.it/search?*
  98. // @match https://www.google.je/search?*
  99. // @match https://www.google.com.jm/search?*
  100. // @match https://www.google.jo/search?*
  101. // @match https://www.google.co.jp/search?*
  102. // @match https://www.google.co.ke/search?*
  103. // @match https://www.google.com.kh/search?*
  104. // @match https://www.google.ki/search?*
  105. // @match https://www.google.kg/search?*
  106. // @match https://www.google.co.kr/search?*
  107. // @match https://www.google.com.kw/search?*
  108. // @match https://www.google.kz/search?*
  109. // @match https://www.google.la/search?*
  110. // @match https://www.google.com.lb/search?*
  111. // @match https://www.google.li/search?*
  112. // @match https://www.google.lk/search?*
  113. // @match https://www.google.co.ls/search?*
  114. // @match https://www.google.lt/search?*
  115. // @match https://www.google.lu/search?*
  116. // @match https://www.google.lv/search?*
  117. // @match https://www.google.com.ly/search?*
  118. // @match https://www.google.co.ma/search?*
  119. // @match https://www.google.md/search?*
  120. // @match https://www.google.me/search?*
  121. // @match https://www.google.mg/search?*
  122. // @match https://www.google.mk/search?*
  123. // @match https://www.google.ml/search?*
  124. // @match https://www.google.com.mm/search?*
  125. // @match https://www.google.mn/search?*
  126. // @match https://www.google.com.mt/search?*
  127. // @match https://www.google.mu/search?*
  128. // @match https://www.google.mv/search?*
  129. // @match https://www.google.mw/search?*
  130. // @match https://www.google.com.mx/search?*
  131. // @match https://www.google.com.my/search?*
  132. // @match https://www.google.co.mz/search?*
  133. // @match https://www.google.com.na/search?*
  134. // @match https://www.google.com.ng/search?*
  135. // @match https://www.google.com.ni/search?*
  136. // @match https://www.google.ne/search?*
  137. // @match https://www.google.nl/search?*
  138. // @match https://www.google.no/search?*
  139. // @match https://www.google.com.np/search?*
  140. // @match https://www.google.nr/search?*
  141. // @match https://www.google.nu/search?*
  142. // @match https://www.google.co.nz/search?*
  143. // @match https://www.google.com.om/search?*
  144. // @match https://www.google.com.pa/search?*
  145. // @match https://www.google.com.pe/search?*
  146. // @match https://www.google.com.pg/search?*
  147. // @match https://www.google.com.ph/search?*
  148. // @match https://www.google.com.pk/search?*
  149. // @match https://www.google.pl/search?*
  150. // @match https://www.google.pn/search?*
  151. // @match https://www.google.com.pr/search?*
  152. // @match https://www.google.ps/search?*
  153. // @match https://www.google.pt/search?*
  154. // @match https://www.google.com.py/search?*
  155. // @match https://www.google.com.qa/search?*
  156. // @match https://www.google.ro/search?*
  157. // @match https://www.google.ru/search?*
  158. // @match https://www.google.rw/search?*
  159. // @match https://www.google.com.sa/search?*
  160. // @match https://www.google.com.sb/search?*
  161. // @match https://www.google.sc/search?*
  162. // @match https://www.google.se/search?*
  163. // @match https://www.google.com.sg/search?*
  164. // @match https://www.google.sh/search?*
  165. // @match https://www.google.si/search?*
  166. // @match https://www.google.sk/search?*
  167. // @match https://www.google.com.sl/search?*
  168. // @match https://www.google.sn/search?*
  169. // @match https://www.google.so/search?*
  170. // @match https://www.google.sm/search?*
  171. // @match https://www.google.sr/search?*
  172. // @match https://www.google.st/search?*
  173. // @match https://www.google.com.sv/search?*
  174. // @match https://www.google.td/search?*
  175. // @match https://www.google.tg/search?*
  176. // @match https://www.google.co.th/search?*
  177. // @match https://www.google.com.tj/search?*
  178. // @match https://www.google.tl/search?*
  179. // @match https://www.google.tm/search?*
  180. // @match https://www.google.tn/search?*
  181. // @match https://www.google.to/search?*
  182. // @match https://www.google.com.tr/search?*
  183. // @match https://www.google.tt/search?*
  184. // @match https://www.google.com.tw/search?*
  185. // @match https://www.google.co.tz/search?*
  186. // @match https://www.google.com.ua/search?*
  187. // @match https://www.google.co.ug/search?*
  188. // @match https://www.google.co.uk/search?*
  189. // @match https://www.google.com.uy/search?*
  190. // @match https://www.google.co.uz/search?*
  191. // @match https://www.google.com.vc/search?*
  192. // @match https://www.google.co.ve/search?*
  193. // @match https://www.google.co.vi/search?*
  194. // @match https://www.google.com.vn/search?*
  195. // @match https://www.google.vu/search?*
  196. // @match https://www.google.ws/search?*
  197. // @match https://www.google.rs/search?*
  198. // @match https://www.google.co.za/search?*
  199. // @match https://www.google.co.zm/search?*
  200. // @match https://www.google.co.zw/search?*
  201. // @match https://www.google.cat/search?*
  202. // @run-at document-end
  203. // @grant none
  204. // @supportURL https://gf.qytechs.cn/scripts/460247/feedback
  205. // ==/UserScript==
  206.  
  207. const TOOLS_BUTTON_ATTRIBUTES = [
  208. ["aria-controls", "hdtbMenus"],
  209. ["jsname", "I4bIT"],
  210. ["jscontroller", "LbcJwc"],
  211. ];
  212.  
  213. const TOOLS_BUTTON_SELECTOR = TOOLS_BUTTON_ATTRIBUTES.map(([name, value]) => `[${name}=${value}]`).join(",");
  214.  
  215. function handleToolsButton(button)
  216. {
  217. console.debug("“Tools” button found, activating the “Tools” menu...");
  218.  
  219. clearTimeout(observerTimeout);
  220. observer.disconnect();
  221.  
  222. const interval = setInterval(() =>
  223. {
  224. if (button.getAttribute("aria-expanded") === "true")
  225. {
  226. console.debug("“Tools” menu activated, congration!");
  227.  
  228. clearTimeout(activateTimeout);
  229. clearInterval(interval);
  230. }
  231. else
  232. {
  233. button.click();
  234. }
  235. }, 250);
  236.  
  237. const activateTimeout = setTimeout(() =>
  238. {
  239. console.debug("“Tools” menu not opened, aborting...");
  240. clearInterval(interval);
  241. }, 120000);
  242. }
  243.  
  244. const observer = new MutationObserver((records) =>
  245. {
  246. for (const record of records)
  247. {
  248. for (const node of record.addedNodes)
  249. {
  250. if (node instanceof Element)
  251. {
  252. if (TOOLS_BUTTON_ATTRIBUTES.some(([name, value]) => (node.getAttribute(name) === value)))
  253. {
  254. handleToolsButton(node);
  255. }
  256. else
  257. {
  258. const button = node.querySelector(TOOLS_BUTTON_SELECTOR);
  259. if (button)
  260. {
  261. handleToolsButton(button);
  262. }
  263. }
  264. }
  265. }
  266. }
  267. });
  268.  
  269. observer.observe(document.body, { subtree: true, childList: true });
  270. const observerTimeout = setTimeout(() =>
  271. {
  272. console.debug("“Tools” button still not exist, aborting...");
  273. observer.disconnect();
  274. }, 120000);
  275.  
  276. const button = document.querySelector(TOOLS_BUTTON_SELECTOR);
  277. if (button)
  278. {
  279. handleToolsButton(button);
  280. }
  281. else
  282. {
  283. console.debug("“Tools” button not exist, attempting the MutationObserver method...");
  284. }

QingJ © 2025

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