您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Opens the “Tools” menu on Google Search automatically when page loaded.
当前为
- // ==UserScript==
- // @name Opens “Tools” Menu by Default on Google
- // @name:zh-TW 預設開啟 Google 的「工具」選單
- // @description Opens the “Tools” menu on Google Search automatically when page loaded.
- // @description:zh-TW 在 Google 搜尋載入後自動打開「工具」選單。
- // @icon https://wsrv.nl/?url=https://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png
- // @author Jason Kwok
- // @namespace https://jasonhk.dev/
- // @version 1.1.1
- // @license MIT
- // @match https://www.google.com/search
- // @match https://www.google.com/search?*
- // @run-at document-end
- // @grant none
- // @supportURL https://greasyfork.org/scripts/460247/feedback
- // ==/UserScript==
- const TOOLS_BUTTON_SELECTOR = "[aria-controls=hdtbMenus], [jsname=I4bIT]";
- function handleToolsButton(button)
- {
- const interval = setInterval(() =>
- {
- if (button.getAttribute("aria-expanded") !== "true")
- {
- button.click();
- }
- else
- {
- clearInterval(interval);
- }
- }, 250);
- }
- const observer = new MutationObserver((records) =>
- {
- for (const record of records)
- {
- for (const node of record.addedNodes)
- {
- if (node instanceof Element)
- {
- if ((node.getAttribute("aria-controls") === "hdtbMenus") || (node.getAttribute("jsname") === "I4bIT"))
- {
- observer.disconnect();
- handleToolsButton(node);
- }
- else
- {
- const button = node.querySelector(TOOLS_BUTTON_SELECTOR);
- if (button)
- {
- observer.disconnect();
- handleToolsButton(button);
- }
- }
- }
- }
- }
- });
- observer.observe(document.body, { subtree: true, childList: true });
- const button = document.querySelector(TOOLS_BUTTON_SELECTOR);
- if (button) { handleToolsButton(button); }