搜索-plus:为搜索结果页添加其他搜索引擎
// ==UserScript==
// @name 搜索-plus:为搜索结果页添加其他搜索引擎
// @description 本扩展在原ddrwin 的baidu++扩展基础上修改而来。
// @icon https://www.baidu.com/cache/icon/favicon.ico
// @version 1.2
// @author lawchou
// @run-at document-start
// @include http*://*.baidu.com/*
// @include http*://*.so.com/*
// @include http*://*.sogou.com/*
// @include http*://*.bing.com/*
// @include http*://*.fsou.cc/*
// @include http*://*.dogdoggo.com/*
// @include http*://*.wuzhuiso.com/*
// @include *://www.google.com/search?*
// @include *://www.google.com.*/search?*
// @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @grant GM_addStyle
// @grant GM_getResourceText
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_registerMenuCommand
// @note 2022.01.12 V1.1 修改搜索条实现方式,感谢大神 Hangover 指导;
// @note 2022.01.04 V1.0 在百度、搜狗、bing等搜索的结果页加入搜索按钮;
// ==/UserScript==
(function() {
'use strict';
var add_str ; //搜寻地址元素,class名称前用. id名称前用#
var hostname = window.location.hostname;
var getkw = function(){ //获取搜索关键词
var kw= $("#kw").val()||$("input[name=q]").val()||$("#upquery").val()||$("#baidu_translate_input").val()||$("#sb_form_q").val()||$("#query").val()||
$("#trans-input").val()||$("#Popover2-toggle").val()||$("input.word").val()||$("input[name=q]").eq(1).val() ||$("#search").val()||$("#searchword").val()||
$("input[name=keyword]").val()||$("input[name=searchInput]").val()||$("#mq").val()||$("#keywords").val()||$("input[name=p]").val()||
$(".right_contents input.selector_input").val()||$("#searchIput").val()||$("input[name=text]").val()||$("input[name=Keywords]").val()||$("#q").val()||
$("#toolbar-search-input").val()||$("input.search-input").val()||$("input[name='facet-search-input']").val()||$(".headword").text()||
$("input[name=ld_search_inp]").eq(1).val()||$("#twotabsearchtextbox").val()||$("#key_S").val()||$("#stickSearchKey").val()||"";
return encodeURIComponent(kw.replace(/^\s+|\s+$/gm,''));
};
keywords=getkw();
search_str='<div class="search_plus_wrapper" style="position: fixed; font-size:14px;top: 20px;left: 50%; width: 550px; height: 30px; line-height: 30px; display: flex; justify-content: space-around;">'
+' <div class="box1" >'
+' <span class="dropbtn1"> web搜索 </span>'
+' <div class="content1" ></div>'
+' </div>'
+' <div class="box2">'
+' <span class="dropbtn2"> 图片搜索 </span>'
+' <div class="content2"></div>'
+' </div>'
+' <div class="box3">'
+' <span class="dropbtn3">网盘磁力搜索</span>'
+' <div class="content3"></div>'
+' </div>'
+' <div class="box4">'
+' <span class="dropbtn4">软件搜索下载</span>'
+' <div class="content4"></div>'
+' </div>'
+' <div class="box5">'
+' <span class="dropbtn5">web搜索(暂无)</span>'
+' <div class="content5"></div>'
+' </div>'
+' <div class="box6">'
+' <span class="dropbtn6">web搜索(暂无)</span>'
+' <div class="content6"></div>'
+' </div>'
+'</div>';
var menu1 = [
{ name: "百度", url: "https://www.baidu.com/s?wd=" + keywords },
{ name: "谷歌", url: "https://www.google.com/search?q=" + keywords },
{ name: "必应", url: "https://cn.bing.com/search?q=" + keywords },
{ name: "搜狗", url: "https://www.sogou.com/web?query=" + keywords },
{ name: "f搜", url: "https://fsou.cc/search?q=" + keywords },
{ name: "searx.be", url: "https://searx.be/search?q=" + keywords },
{ name: "yandex", url: "https://yandex.com/search/?text=" + keywords },
{ name:"dogdoggo", url:"https://www.dogdoggo.com/search?q=" + keywords }
]
var menu2 = [
{ name: "百度图片", url: "https://image.baidu.com/search/index?tn=baiduimage&word=" + keywords },
{ name: "谷歌图片", url: "https://www.google.com/search?q=" + keywords },
{ name: "必应图片", url: "https://cn.bing.com/images/search?q=" + keywords },
{ name: "搜狗图片", url: "https://pic.sogou.com/pics?ie=utf&query=" + keywords },
{ name: "searx.be", url: "https://searx.be/search?categories=images&q=" + keywords },
{ name: "yandex", url: "https://yandex.com/images/search?text=" + keywords }
]
var menu3 = [
{ name: "网盘搜索", url: "https://www.baidu.com/s?wd="+ keywords + " 网盘" },
{ name: "javdb", url: "https://javdb7.com/search?f=all&q="+ keywords },
// { name: "oxtorrent", url: "https://www.oxtorrent.com/recherche/"+ keywords },
// { name: "btdp.online", url: "http://clg.btdp.online/search/"+ keywords },
// { name: "uihp.online", url: "http://clg.uihp.online/search/"+ keywords },
// { name: "ywxinxi.com", url: "https://www.ywxinxi.com/search/"+ keywords },
{ name: "torrentkitty", url: "https://www.torrentkitty.app/search/"+ keywords }
]
var menu4 = [
{ name: "52pojie.cn", url: "https://www.baidu.com/s?wd=" + keywords + " site:www.52pojie.cn" },
{ name: "hrtsea.com", url: "https://www.baidu.com/s?wd=" + keywords + " site:www.hrtsea.com" },
{ name: "qiuquan.cc", url: "http://www.qiuquan.cc/?s=" + keywords },
{ name: "macno1.com", url: "https://www.macno1.com/search.php?q="+ keywords },
{ name: "zdfans.com", url: "http://www.zdfans.com/search.asp?keyword=" + keywords },
{ name: "dayanzai.me", url: "http://www.dayanzai.me/?s=" + keywords },
{ name: "appinn.com", url: "https://www.appinn.com/?s=" + keywords },
{ name: "ghpym.com", url: "https://www.ghpym.com/?s=" + keywords },
{ name: "yxssp.com", url: "https://www.yxssp.com/?s=" + keywords },
{ name: "iplaysoft.com", url: "https://www.iplaysoft.com/?s=" + keywords }
]
var menu5 = [
{ name: "百度", url: "https://www.baidu.com/s?wd=" + keywords },
{ name: "谷歌", url: "https://www.google.com/search?q=" + keywords },
{ name: "必应", url: "https://cn.bing.com/search?q=" + keywords }
]
var menu6 = [
{ name: "百度", url: "https://www.baidu.com/s?wd=" + keywords },
{ name: "谷歌", url: "https://www.google.com/search?q=" + keywords },
{ name: "必应", url: "https://cn.bing.com/search?q=" + keywords }
]
function add_button(key){
var div = document.querySelector(add_str); //搜寻元素,class名称前用. id名称前用#
console.log(add_str);
//添加一级菜单
if (key==1){
div.insertAdjacentHTML('afterend', search_str); //插入内容 ,在当前元素节点的后面
}
else if (key==2){
div.insertAdjacentHTML('beforeend', search_str); //插入内容 ,在当前元素节点的前面
}
else if (key==3){
div.insertAdjacentHTML('beforebegin', search_str); //插入内容 ,在当前元素内第一个节点的前面
}
else if (key==4){
div.insertAdjacentHTML('afterbegin', search_str); //插入内容 ,在当前元素内最后一个节点的后面
}
// 添加二级菜单
var wrapper = document.querySelectorAll(".search_plus_wrapper>div>div");
for (var i in menu1) {
var element1 = document.createElement("a");
element1.innerHTML = menu1[i].name;
element1.href = menu1[i].url ;
element1.target="_blank";
wrapper[0].appendChild(element1);
}
for (var t in menu2) {
var element2 = document.createElement("a");
element2.innerHTML = menu2[t].name;
element2.href = menu2[t].url ;
element2.target="_blank";
wrapper[1].appendChild(element2);
}
for (var y in menu3) {
var element3 = document.createElement("a");
element3.innerHTML = menu3[y].name;
element3.href = menu3[y].url ;
element3.target="_blank";
wrapper[2].appendChild(element3);
}
for (var u in menu4) {
var element4 = document.createElement("a");
element4.innerHTML = menu4[u].name;
element4.href = menu4[u].url;
element4.target="_blank";
wrapper[3].appendChild(element4);
}
for (var s in menu5) {
var element5 = document.createElement("a");
element5.innerHTML = menu5[s].name;
element5.href = menu5[s].url ;
element4.target="_blank";
wrapper[4].appendChild(element5);
}
for (var g in menu6) {
var element6 = document.createElement("a");
element6.innerHTML = menu6[g].name;
element6.href = menu6[g].url ;
element6.target="_blank";
wrapper[5].appendChild(element6);
}
}
if(hostname.match(RegExp(/baidu.com/))){
add_str='.s_btn_wr'; //baidu
setTimeout(add_button(2),"1000"); //延迟1秒后加载
}
else if (hostname.match(RegExp(/wuzhuiso.com/))){
add_str='#searchbox' ;//wuzhuiso
setTimeout(add_button(1),"1000"); //延迟1秒后加载
}
else if (hostname.match(RegExp(/so.com/))){
add_str='.adv-search-wrap' ;//360so
setTimeout(add_button(3),"1000"); //延迟1秒后加载
}
else if (hostname.match(RegExp(/bing.com/))){
add_str='#id_h' ;//bing
setTimeout(add_button(1),"1000"); //延迟1秒后加载
}
else if (hostname.match(RegExp(/sogou.com/))){
add_str='.qborder' ;//sogou
setTimeout(add_button(2),"1000"); //延迟1秒后加载
}
else if (hostname.match(RegExp(/fsou.cc/))){
add_str='.flex-row-center' ;//fsou
setTimeout(add_button(3),"1000"); //延迟1秒后加载
}
else if (hostname.match(RegExp(/dogdoggo.com/))){
add_str='.icon-search' ;//dogdoggo
setTimeout(add_button(1),"1000"); //延迟1秒后加载
}
})();
//设置样式
GM_addStyle(`
<style>
.search_plus_wrapper {
position: fixed;
top: 100px;
left: 30%;
width: 500px;
height: 30px;
line-height: 30px;
background: #fff;
display: flex;
justify-content: space-around;
}
.search_plus_wrapper>div {
cursor: pointer;
}
.search_plus_wrapper>div:hover {
background-color:#96b97d;
}
.search_plus_wrapper>div>div {
text-align: center;
display: none;
}
.search_plus_wrapper>div>div a {
display: block;
background: #f6f6f3;
text-decoration: none;
color:#000000;
}
.search_plus_wrapper>div>div a:visited {
color:#000000;
}
.search_plus_wrapper>div>div a:hover {
background-color:#96b97d;
color:#000000;
}
.box1:hover .content1 {
display: block;
}
.box2:hover .content2 {
display: block;
}
.box3:hover .content3 {
display: block;
}
.box4:hover .content4 {
display: block;
}
.box5:hover .content5 {
display: block;
}
.box6:hover .content6 {
display: block;
}
</style>
`)