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

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

当前为 2024-04-17 提交的版本,查看 最新版本

  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.0
  14. // @license MIT
  15. // @match https://www.google.com/search
  16. // @match https://www.google.com/search?*
  17. // @match https://www.google.ad/search
  18. // @match https://www.google.ad/search?*
  19. // @match https://www.google.ae/search
  20. // @match https://www.google.ae/search?*
  21. // @match https://www.google.com.af/search
  22. // @match https://www.google.com.af/search?*
  23. // @match https://www.google.com.ag/search
  24. // @match https://www.google.com.ag/search?*
  25. // @match https://www.google.al/search
  26. // @match https://www.google.al/search?*
  27. // @match https://www.google.am/search
  28. // @match https://www.google.am/search?*
  29. // @match https://www.google.co.ao/search
  30. // @match https://www.google.co.ao/search?*
  31. // @match https://www.google.com.ar/search
  32. // @match https://www.google.com.ar/search?*
  33. // @match https://www.google.as/search
  34. // @match https://www.google.as/search?*
  35. // @match https://www.google.at/search
  36. // @match https://www.google.at/search?*
  37. // @match https://www.google.com.au/search
  38. // @match https://www.google.com.au/search?*
  39. // @match https://www.google.az/search
  40. // @match https://www.google.az/search?*
  41. // @match https://www.google.ba/search
  42. // @match https://www.google.ba/search?*
  43. // @match https://www.google.com.bd/search
  44. // @match https://www.google.com.bd/search?*
  45. // @match https://www.google.be/search
  46. // @match https://www.google.be/search?*
  47. // @match https://www.google.bf/search
  48. // @match https://www.google.bf/search?*
  49. // @match https://www.google.bg/search
  50. // @match https://www.google.bg/search?*
  51. // @match https://www.google.com.bh/search
  52. // @match https://www.google.com.bh/search?*
  53. // @match https://www.google.bi/search
  54. // @match https://www.google.bi/search?*
  55. // @match https://www.google.bj/search
  56. // @match https://www.google.bj/search?*
  57. // @match https://www.google.com.bn/search
  58. // @match https://www.google.com.bn/search?*
  59. // @match https://www.google.com.bo/search
  60. // @match https://www.google.com.bo/search?*
  61. // @match https://www.google.com.br/search
  62. // @match https://www.google.com.br/search?*
  63. // @match https://www.google.bs/search
  64. // @match https://www.google.bs/search?*
  65. // @match https://www.google.bt/search
  66. // @match https://www.google.bt/search?*
  67. // @match https://www.google.co.bw/search
  68. // @match https://www.google.co.bw/search?*
  69. // @match https://www.google.by/search
  70. // @match https://www.google.by/search?*
  71. // @match https://www.google.com.bz/search
  72. // @match https://www.google.com.bz/search?*
  73. // @match https://www.google.ca/search
  74. // @match https://www.google.ca/search?*
  75. // @match https://www.google.cd/search
  76. // @match https://www.google.cd/search?*
  77. // @match https://www.google.cf/search
  78. // @match https://www.google.cf/search?*
  79. // @match https://www.google.cg/search
  80. // @match https://www.google.cg/search?*
  81. // @match https://www.google.ch/search
  82. // @match https://www.google.ch/search?*
  83. // @match https://www.google.ci/search
  84. // @match https://www.google.ci/search?*
  85. // @match https://www.google.co.ck/search
  86. // @match https://www.google.co.ck/search?*
  87. // @match https://www.google.cl/search
  88. // @match https://www.google.cl/search?*
  89. // @match https://www.google.cm/search
  90. // @match https://www.google.cm/search?*
  91. // @match https://www.google.cn/search
  92. // @match https://www.google.cn/search?*
  93. // @match https://www.google.com.co/search
  94. // @match https://www.google.com.co/search?*
  95. // @match https://www.google.co.cr/search
  96. // @match https://www.google.co.cr/search?*
  97. // @match https://www.google.com.cu/search
  98. // @match https://www.google.com.cu/search?*
  99. // @match https://www.google.cv/search
  100. // @match https://www.google.cv/search?*
  101. // @match https://www.google.com.cy/search
  102. // @match https://www.google.com.cy/search?*
  103. // @match https://www.google.cz/search
  104. // @match https://www.google.cz/search?*
  105. // @match https://www.google.de/search
  106. // @match https://www.google.de/search?*
  107. // @match https://www.google.dj/search
  108. // @match https://www.google.dj/search?*
  109. // @match https://www.google.dk/search
  110. // @match https://www.google.dk/search?*
  111. // @match https://www.google.dm/search
  112. // @match https://www.google.dm/search?*
  113. // @match https://www.google.com.do/search
  114. // @match https://www.google.com.do/search?*
  115. // @match https://www.google.dz/search
  116. // @match https://www.google.dz/search?*
  117. // @match https://www.google.com.ec/search
  118. // @match https://www.google.com.ec/search?*
  119. // @match https://www.google.ee/search
  120. // @match https://www.google.ee/search?*
  121. // @match https://www.google.com.eg/search
  122. // @match https://www.google.com.eg/search?*
  123. // @match https://www.google.es/search
  124. // @match https://www.google.es/search?*
  125. // @match https://www.google.com.et/search
  126. // @match https://www.google.com.et/search?*
  127. // @match https://www.google.fi/search
  128. // @match https://www.google.fi/search?*
  129. // @match https://www.google.com.fj/search
  130. // @match https://www.google.com.fj/search?*
  131. // @match https://www.google.fm/search
  132. // @match https://www.google.fm/search?*
  133. // @match https://www.google.fr/search
  134. // @match https://www.google.fr/search?*
  135. // @match https://www.google.ga/search
  136. // @match https://www.google.ga/search?*
  137. // @match https://www.google.ge/search
  138. // @match https://www.google.ge/search?*
  139. // @match https://www.google.gg/search
  140. // @match https://www.google.gg/search?*
  141. // @match https://www.google.com.gh/search
  142. // @match https://www.google.com.gh/search?*
  143. // @match https://www.google.com.gi/search
  144. // @match https://www.google.com.gi/search?*
  145. // @match https://www.google.gl/search
  146. // @match https://www.google.gl/search?*
  147. // @match https://www.google.gm/search
  148. // @match https://www.google.gm/search?*
  149. // @match https://www.google.gr/search
  150. // @match https://www.google.gr/search?*
  151. // @match https://www.google.com.gt/search
  152. // @match https://www.google.com.gt/search?*
  153. // @match https://www.google.gy/search
  154. // @match https://www.google.gy/search?*
  155. // @match https://www.google.com.hk/search
  156. // @match https://www.google.com.hk/search?*
  157. // @match https://www.google.hn/search
  158. // @match https://www.google.hn/search?*
  159. // @match https://www.google.hr/search
  160. // @match https://www.google.hr/search?*
  161. // @match https://www.google.ht/search
  162. // @match https://www.google.ht/search?*
  163. // @match https://www.google.hu/search
  164. // @match https://www.google.hu/search?*
  165. // @match https://www.google.co.id/search
  166. // @match https://www.google.co.id/search?*
  167. // @match https://www.google.ie/search
  168. // @match https://www.google.ie/search?*
  169. // @match https://www.google.co.il/search
  170. // @match https://www.google.co.il/search?*
  171. // @match https://www.google.im/search
  172. // @match https://www.google.im/search?*
  173. // @match https://www.google.co.in/search
  174. // @match https://www.google.co.in/search?*
  175. // @match https://www.google.iq/search
  176. // @match https://www.google.iq/search?*
  177. // @match https://www.google.is/search
  178. // @match https://www.google.is/search?*
  179. // @match https://www.google.it/search
  180. // @match https://www.google.it/search?*
  181. // @match https://www.google.je/search
  182. // @match https://www.google.je/search?*
  183. // @match https://www.google.com.jm/search
  184. // @match https://www.google.com.jm/search?*
  185. // @match https://www.google.jo/search
  186. // @match https://www.google.jo/search?*
  187. // @match https://www.google.co.jp/search
  188. // @match https://www.google.co.jp/search?*
  189. // @match https://www.google.co.ke/search
  190. // @match https://www.google.co.ke/search?*
  191. // @match https://www.google.com.kh/search
  192. // @match https://www.google.com.kh/search?*
  193. // @match https://www.google.ki/search
  194. // @match https://www.google.ki/search?*
  195. // @match https://www.google.kg/search
  196. // @match https://www.google.kg/search?*
  197. // @match https://www.google.co.kr/search
  198. // @match https://www.google.co.kr/search?*
  199. // @match https://www.google.com.kw/search
  200. // @match https://www.google.com.kw/search?*
  201. // @match https://www.google.kz/search
  202. // @match https://www.google.kz/search?*
  203. // @match https://www.google.la/search
  204. // @match https://www.google.la/search?*
  205. // @match https://www.google.com.lb/search
  206. // @match https://www.google.com.lb/search?*
  207. // @match https://www.google.li/search
  208. // @match https://www.google.li/search?*
  209. // @match https://www.google.lk/search
  210. // @match https://www.google.lk/search?*
  211. // @match https://www.google.co.ls/search
  212. // @match https://www.google.co.ls/search?*
  213. // @match https://www.google.lt/search
  214. // @match https://www.google.lt/search?*
  215. // @match https://www.google.lu/search
  216. // @match https://www.google.lu/search?*
  217. // @match https://www.google.lv/search
  218. // @match https://www.google.lv/search?*
  219. // @match https://www.google.com.ly/search
  220. // @match https://www.google.com.ly/search?*
  221. // @match https://www.google.co.ma/search
  222. // @match https://www.google.co.ma/search?*
  223. // @match https://www.google.md/search
  224. // @match https://www.google.md/search?*
  225. // @match https://www.google.me/search
  226. // @match https://www.google.me/search?*
  227. // @match https://www.google.mg/search
  228. // @match https://www.google.mg/search?*
  229. // @match https://www.google.mk/search
  230. // @match https://www.google.mk/search?*
  231. // @match https://www.google.ml/search
  232. // @match https://www.google.ml/search?*
  233. // @match https://www.google.com.mm/search
  234. // @match https://www.google.com.mm/search?*
  235. // @match https://www.google.mn/search
  236. // @match https://www.google.mn/search?*
  237. // @match https://www.google.com.mt/search
  238. // @match https://www.google.com.mt/search?*
  239. // @match https://www.google.mu/search
  240. // @match https://www.google.mu/search?*
  241. // @match https://www.google.mv/search
  242. // @match https://www.google.mv/search?*
  243. // @match https://www.google.mw/search
  244. // @match https://www.google.mw/search?*
  245. // @match https://www.google.com.mx/search
  246. // @match https://www.google.com.mx/search?*
  247. // @match https://www.google.com.my/search
  248. // @match https://www.google.com.my/search?*
  249. // @match https://www.google.co.mz/search
  250. // @match https://www.google.co.mz/search?*
  251. // @match https://www.google.com.na/search
  252. // @match https://www.google.com.na/search?*
  253. // @match https://www.google.com.ng/search
  254. // @match https://www.google.com.ng/search?*
  255. // @match https://www.google.com.ni/search
  256. // @match https://www.google.com.ni/search?*
  257. // @match https://www.google.ne/search
  258. // @match https://www.google.ne/search?*
  259. // @match https://www.google.nl/search
  260. // @match https://www.google.nl/search?*
  261. // @match https://www.google.no/search
  262. // @match https://www.google.no/search?*
  263. // @match https://www.google.com.np/search
  264. // @match https://www.google.com.np/search?*
  265. // @match https://www.google.nr/search
  266. // @match https://www.google.nr/search?*
  267. // @match https://www.google.nu/search
  268. // @match https://www.google.nu/search?*
  269. // @match https://www.google.co.nz/search
  270. // @match https://www.google.co.nz/search?*
  271. // @match https://www.google.com.om/search
  272. // @match https://www.google.com.om/search?*
  273. // @match https://www.google.com.pa/search
  274. // @match https://www.google.com.pa/search?*
  275. // @match https://www.google.com.pe/search
  276. // @match https://www.google.com.pe/search?*
  277. // @match https://www.google.com.pg/search
  278. // @match https://www.google.com.pg/search?*
  279. // @match https://www.google.com.ph/search
  280. // @match https://www.google.com.ph/search?*
  281. // @match https://www.google.com.pk/search
  282. // @match https://www.google.com.pk/search?*
  283. // @match https://www.google.pl/search
  284. // @match https://www.google.pl/search?*
  285. // @match https://www.google.pn/search
  286. // @match https://www.google.pn/search?*
  287. // @match https://www.google.com.pr/search
  288. // @match https://www.google.com.pr/search?*
  289. // @match https://www.google.ps/search
  290. // @match https://www.google.ps/search?*
  291. // @match https://www.google.pt/search
  292. // @match https://www.google.pt/search?*
  293. // @match https://www.google.com.py/search
  294. // @match https://www.google.com.py/search?*
  295. // @match https://www.google.com.qa/search
  296. // @match https://www.google.com.qa/search?*
  297. // @match https://www.google.ro/search
  298. // @match https://www.google.ro/search?*
  299. // @match https://www.google.ru/search
  300. // @match https://www.google.ru/search?*
  301. // @match https://www.google.rw/search
  302. // @match https://www.google.rw/search?*
  303. // @match https://www.google.com.sa/search
  304. // @match https://www.google.com.sa/search?*
  305. // @match https://www.google.com.sb/search
  306. // @match https://www.google.com.sb/search?*
  307. // @match https://www.google.sc/search
  308. // @match https://www.google.sc/search?*
  309. // @match https://www.google.se/search
  310. // @match https://www.google.se/search?*
  311. // @match https://www.google.com.sg/search
  312. // @match https://www.google.com.sg/search?*
  313. // @match https://www.google.sh/search
  314. // @match https://www.google.sh/search?*
  315. // @match https://www.google.si/search
  316. // @match https://www.google.si/search?*
  317. // @match https://www.google.sk/search
  318. // @match https://www.google.sk/search?*
  319. // @match https://www.google.com.sl/search
  320. // @match https://www.google.com.sl/search?*
  321. // @match https://www.google.sn/search
  322. // @match https://www.google.sn/search?*
  323. // @match https://www.google.so/search
  324. // @match https://www.google.so/search?*
  325. // @match https://www.google.sm/search
  326. // @match https://www.google.sm/search?*
  327. // @match https://www.google.sr/search
  328. // @match https://www.google.sr/search?*
  329. // @match https://www.google.st/search
  330. // @match https://www.google.st/search?*
  331. // @match https://www.google.com.sv/search
  332. // @match https://www.google.com.sv/search?*
  333. // @match https://www.google.td/search
  334. // @match https://www.google.td/search?*
  335. // @match https://www.google.tg/search
  336. // @match https://www.google.tg/search?*
  337. // @match https://www.google.co.th/search
  338. // @match https://www.google.co.th/search?*
  339. // @match https://www.google.com.tj/search
  340. // @match https://www.google.com.tj/search?*
  341. // @match https://www.google.tl/search
  342. // @match https://www.google.tl/search?*
  343. // @match https://www.google.tm/search
  344. // @match https://www.google.tm/search?*
  345. // @match https://www.google.tn/search
  346. // @match https://www.google.tn/search?*
  347. // @match https://www.google.to/search
  348. // @match https://www.google.to/search?*
  349. // @match https://www.google.com.tr/search
  350. // @match https://www.google.com.tr/search?*
  351. // @match https://www.google.tt/search
  352. // @match https://www.google.tt/search?*
  353. // @match https://www.google.com.tw/search
  354. // @match https://www.google.com.tw/search?*
  355. // @match https://www.google.co.tz/search
  356. // @match https://www.google.co.tz/search?*
  357. // @match https://www.google.com.ua/search
  358. // @match https://www.google.com.ua/search?*
  359. // @match https://www.google.co.ug/search
  360. // @match https://www.google.co.ug/search?*
  361. // @match https://www.google.co.uk/search
  362. // @match https://www.google.co.uk/search?*
  363. // @match https://www.google.com.uy/search
  364. // @match https://www.google.com.uy/search?*
  365. // @match https://www.google.co.uz/search
  366. // @match https://www.google.co.uz/search?*
  367. // @match https://www.google.com.vc/search
  368. // @match https://www.google.com.vc/search?*
  369. // @match https://www.google.co.ve/search
  370. // @match https://www.google.co.ve/search?*
  371. // @match https://www.google.co.vi/search
  372. // @match https://www.google.co.vi/search?*
  373. // @match https://www.google.com.vn/search
  374. // @match https://www.google.com.vn/search?*
  375. // @match https://www.google.vu/search
  376. // @match https://www.google.vu/search?*
  377. // @match https://www.google.ws/search
  378. // @match https://www.google.ws/search?*
  379. // @match https://www.google.rs/search
  380. // @match https://www.google.rs/search?*
  381. // @match https://www.google.co.za/search
  382. // @match https://www.google.co.za/search?*
  383. // @match https://www.google.co.zm/search
  384. // @match https://www.google.co.zm/search?*
  385. // @match https://www.google.co.zw/search
  386. // @match https://www.google.co.zw/search?*
  387. // @match https://www.google.cat/search
  388. // @match https://www.google.cat/search?*
  389. // @run-at document-end
  390. // @grant none
  391. // @supportURL https://greasyfork.org/scripts/460247/feedback
  392. // ==/UserScript==
  393.  
  394. const TOOLS_BUTTON_ATTRIBUTES = [
  395. ["aria-controls", "hdtbMenus"],
  396. ["jsname", "I4bIT"],
  397. ["jscontroller", "LbcJwc"],
  398. ];
  399.  
  400. const TOOLS_BUTTON_SELECTOR = TOOLS_BUTTON_ATTRIBUTES.map(([name, value]) => `[${name}=${value}]`).join(",");
  401.  
  402. function handleToolsButton(button)
  403. {
  404. console.debug("“Tools” button found, activating the “Tools” menu...");
  405.  
  406. clearTimeout(observerTimeout);
  407. observer.disconnect();
  408.  
  409. const interval = setInterval(() =>
  410. {
  411. if (button.getAttribute("aria-expanded") === "true")
  412. {
  413. console.debug("“Tools” menu activated, congration!");
  414.  
  415. clearTimeout(activateTimeout);
  416. clearInterval(interval);
  417. }
  418. else
  419. {
  420. button.click();
  421. }
  422. }, 250);
  423.  
  424. const activateTimeout = setTimeout(() =>
  425. {
  426. console.debug("“Tools” menu not opened, aborting...");
  427. clearInterval(interval);
  428. }, 120000);
  429. }
  430.  
  431. const observer = new MutationObserver((records) =>
  432. {
  433. for (const record of records)
  434. {
  435. for (const node of record.addedNodes)
  436. {
  437. if (node instanceof Element)
  438. {
  439. if (TOOLS_BUTTON_ATTRIBUTES.some(([name, value]) => (node.getAttribute(name) === value)))
  440. {
  441. handleToolsButton(node);
  442. }
  443. else
  444. {
  445. const button = node.querySelector(TOOLS_BUTTON_SELECTOR);
  446. if (button)
  447. {
  448. handleToolsButton(button);
  449. }
  450. }
  451. }
  452. }
  453. }
  454. });
  455.  
  456. observer.observe(document.body, { subtree: true, childList: true });
  457. const observerTimeout = setTimeout(() =>
  458. {
  459. console.debug("“Tools” button still not exist, aborting...");
  460. observer.disconnect();
  461. }, 120000);
  462.  
  463. const button = document.querySelector(TOOLS_BUTTON_SELECTOR);
  464. if (button)
  465. {
  466. handleToolsButton(button);
  467. }
  468. else
  469. {
  470. console.debug("“Tools” button not exist, attempting the MutationObserver method...");
  471. }