您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Add a Reddit button to Google search to restrict your searches to results from reddit
// ==UserScript== // @name Google Reddit Button // @namespace http://tampermonkey.net/ // @version 1.1 // @description Add a Reddit button to Google search to restrict your searches to results from reddit // @match https://www.google.com/search* // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; function waitForElement(selector, callback) { const el = document.querySelector(selector); if (el) { callback(el); } else { const observer = new MutationObserver(() => { const el = document.querySelector(selector); if (el) { observer.disconnect(); callback(el); } }); observer.observe(document.body, { childList: true, subtree: true }); } } waitForElement('#hdtb-tls', (toolsBtn) => { const toolbar = toolsBtn.parentNode; // Create the new button const redditBtn = document.createElement('a'); redditBtn.textContent = "Reddit"; redditBtn.style.cursor = "pointer"; redditBtn.style.marginLeft = "12px"; redditBtn.style.fontWeight = "500"; redditBtn.style.color = "#80868b"; redditBtn.onclick = () => { const params = new URLSearchParams(window.location.search); const q = params.get("q") || ""; if (!q.includes("site:www.reddit.com")) { params.set("q", q + " site:www.reddit.com"); } window.location.search = params.toString(); }; toolbar.appendChild(redditBtn); console.log("Reddit button added"); }); })();