【JS】聚合搜索脚本\代码\插件 聚合搜索脚本使用方法打开暴力猴➡️添加脚本➡️粘贴➡️测试简洁版// UserScript// name 聚合搜索左上角固定版// namespace http://tampermonkey.net/// version 0.0.0// description 在搜索页面左上角固定显示百度、必应和Google切换按钮// author -// match *://www.baidu.com/*// match *://cn.bing.com/*// match *://www.bing.com/*// match *://www.google.com/*// match *://google.com/*// run-at document-idle// grant none// /UserScript(function(){use strict;constBOX_IDsearch-app-box;// 搜索引擎配置consturlMapping[{name:百度,searchUrl:https://www.baidu.com/s?wd},{name:必应,searchUrl:https://cn.bing.com/search?q},{name:Google,searchUrl:https://www.google.com/search?q}];// 判断当前是否为搜索结果页functionisSearchPage(){consthostnamelocation.hostname;constpathnamelocation.pathname;// 百度搜索结果页if(hostnamewww.baidu.com){returnpathname/s||pathname.startsWith(/s/);}// 必应搜索结果页if(hostnamecn.bing.com||hostnamewww.bing.com){returnpathname/search;}// Google搜索结果页if(hostnamewww.google.com||hostnamegoogle.com){returnpathname/search;}returnfalse;}// 获取URL参数functiongetUrlParameter(name){constparamsnewURLSearchParams(location.search);returnparams.get(name)||;}// 获取当前页面搜索关键词functiongetKeywords(){consthostnamelocation.hostname;if(hostnamewww.baidu.com){returngetUrlParameter(wd);}if(hostnamecn.bing.com||hostnamewww.bing.com){returngetUrlParameter(q);}if(hostnamewww.google.com||hostnamegoogle.com){returngetUrlParameter(q);}return;}// 创建搜索切换栏functioncreateBox(){constdivdocument.createElement(div);div.idBOX_ID;div.style.cssTextposition: fixed; top: 1%; left: 1%; display: flex; align-items: center; flex-wrap: nowrap; width: fit-content; max-width: 95vw; background: #eeeeee; border: 1px solid #d0d0d0; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18); font-size: 12px; overflow: hidden; opacity: 0.75; z-index: 2147483647;;// 图标consttitledocument.createElement(span);title.textContent;title.style.cssTextdisplay: flex; align-items: center; justify-content: center; padding: 9px 13px; color: #333333; font-size: 15px; font-weight: bold; white-space: nowrap; border-right: 1px solid #cccccc; user-select: none;;div.appendChild(title);// 创建搜索引擎按钮urlMapping.forEach(function(item){constbuttondocument.createElement(a);button.href#;button.textContentitem.name;button.style.cssTextdisplay: block; padding: 9px 13px; color: #333333; background: transparent; text-decoration: none; white-space: nowrap; cursor: pointer; transition: color 0.2s, background-color 0.2s;;button.addEventListener(mouseenter,function(){button.style.color#ffffff;button.style.backgroundColor#666666;});button.addEventListener(mouseleave,function(){button.style.color#333333;button.style.backgroundColortransparent;});button.addEventListener(click,function(event){event.preventDefault();constkeywordsgetKeywords().trim();location.hrefitem.searchUrlencodeURIComponent(keywords);});div.appendChild(button);});returndiv;}// 添加搜索切换栏functionaddBox(){if(!isSearchPage()){returnfalse;}if(document.getElementById(BOX_ID)){returntrue;}if(!document.body){returnfalse;}document.body.appendChild(createBox());returntrue;}// 删除搜索切换栏functionremoveBox(){constoldBoxdocument.getElementById(BOX_ID);if(oldBox){oldBox.remove();}}// 页面加载后延迟重试functionstart(){letcount0;constmaxCount20;consttimersetInterval(function(){count;if(addBox()||countmaxCount){clearInterval(timer);}},300);}// 页面初次加载if(document.readyStatecomplete){start();}else{window.addEventListener(load,start,{once:true});}// 兼容SPA页面地址变化letlastUrllocation.href;setInterval(function(){constcurrentUrllocation.href;if(currentUrl!lastUrl){lastUrlcurrentUrl;removeBox();setTimeout(start,500);}// 防止网页动态刷新后删除工具栏if(isSearchPage()document.body!document.getElementById(BOX_ID)){addBox();}// 离开搜索结果页后删除if(!isSearchPage()){removeBox();}},1000);})();美化版// UserScript// name 聚合搜索-蓝色美化版// namespace http://tampermonkey.net/// version 0.0.0// description 在搜索页面左上角固定显示百度、必应和Google切换按钮// author ----// match *://www.baidu.com/*// match *://cn.bing.com/*// match *://www.bing.com/*// match *://www.google.com/*// match *://google.com/*// run-at document-idle// grant none// /UserScript(function(){use strict;constBOX_IDsearch-app-box;consturlMapping[{name:百度,searchUrl:https://www.baidu.com/s?wd},{name:必应,searchUrl:https://cn.bing.com/search?q},{name:Google,searchUrl:https://www.google.com/search?q}];// 判断当前是否为搜索结果页functionisSearchPage(){consthostnamelocation.hostname;constpathnamelocation.pathname;if(hostnamewww.baidu.com){returnpathname/s||pathname.startsWith(/s/);}if(hostnamecn.bing.com||hostnamewww.bing.com){returnpathname/search;}if(hostnamewww.google.com||hostnamegoogle.com){returnpathname/search;}returnfalse;}// 获取URL参数functiongetUrlParameter(name){constparamsnewURLSearchParams(location.search);returnparams.get(name)||;}// 获取当前页面搜索关键词functiongetKeywords(){consthostnamelocation.hostname;if(hostnamewww.baidu.com){returngetUrlParameter(wd);}if(hostnamecn.bing.com||hostnamewww.bing.com){returngetUrlParameter(q);}if(hostnamewww.google.com||hostnamegoogle.com){returngetUrlParameter(q);}return;}// 创建搜索切换栏functioncreateBox(){constdivdocument.createElement(div);div.idBOX_ID;div.style.cssTextposition: fixed; top: 1%; left: 1%; display: flex; align-items: center; flex-wrap: nowrap; width: fit-content; max-width: 95vw; background: rgba(239, 247, 255, 0.82); border: 1px solid rgba(72, 132, 255, 0.28); border-radius: 12px; box-shadow: 0 6px 18px rgba(34, 91, 180, 0.16), 0 2px 6px rgba(34, 91, 180, 0.08); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 12px; font-family: Segoe UI, Microsoft YaHei, Arial, sans-serif; overflow: hidden; opacity: 0.75; z-index: 2147483647; transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;;// 鼠标移入整体区域时提高透明度div.addEventListener(mouseenter,function(){div.style.opacity1;div.style.transformtranslateY(-1px);div.style.boxShadow0 8px 22px rgba(34, 91, 180, 0.22), 0 3px 8px rgba(34, 91, 180, 0.12);});div.addEventListener(mouseleave,function(){div.style.opacity0.75;div.style.transformtranslateY(0);div.style.boxShadow0 6px 18px rgba(34, 91, 180, 0.16), 0 2px 6px rgba(34, 91, 180, 0.08);});// 左侧图标consttitledocument.createElement(span);title.textContent;title.style.cssTextdisplay: flex; align-items: center; justify-content: center; padding: 9px 13px; color: #2563eb; font-size: 16px; font-weight: 700; background: rgba(219, 234, 254, 0.68); border-right: 1px solid rgba(72, 132, 255, 0.2); white-space: nowrap; user-select: none;;div.appendChild(title);// 创建搜索引擎按钮urlMapping.forEach(function(item){constbuttondocument.createElement(a);button.href#;button.textContentitem.name;button.style.cssTextdisplay: flex; align-items: center; justify-content: center; padding: 9px 14px; color: #2563eb; background: transparent; font-size: 13px; font-weight: 600; letter-spacing: 0.2px; text-decoration: none; white-space: nowrap; cursor: pointer; border-left: 1px solid rgba(72, 132, 255, 0.08); transition: color 0.18s ease, background-color 0.18s ease, transform 0.18s ease;;button.addEventListener(mouseenter,function(){button.style.color#ffffff;button.style.backgroundColor#3b82f6;button.style.transformtranslateY(-1px);});button.addEventListener(mouseleave,function(){button.style.color#2563eb;button.style.backgroundColortransparent;button.style.transformtranslateY(0);});button.addEventListener(click,function(event){event.preventDefault();constkeywordsgetKeywords().trim();location.hrefitem.searchUrlencodeURIComponent(keywords);});div.appendChild(button);});returndiv;}// 添加搜索切换栏functionaddBox(){if(!isSearchPage()){returnfalse;}if(document.getElementById(BOX_ID)){returntrue;}if(!document.body){returnfalse;}document.body.appendChild(createBox());returntrue;}// 删除搜索切换栏functionremoveBox(){constoldBoxdocument.getElementById(BOX_ID);if(oldBox){oldBox.remove();}}// 页面加载后重试functionstart(){letcount0;constmaxCount20;consttimersetInterval(function(){count;if(addBox()||countmaxCount){clearInterval(timer);}},300);}// 页面初次加载if(document.readyStatecomplete){start();}else{window.addEventListener(load,start,{once:true});}// 兼容SPA页面地址变化letlastUrllocation.href;setInterval(function(){constcurrentUrllocation.href;if(currentUrl!lastUrl){lastUrlcurrentUrl;removeBox();setTimeout(start,500);}if(isSearchPage()document.body!document.getElementById(BOX_ID)){addBox();}if(!isSearchPage()){removeBox();}},1000);})();