// ==UserScript==
// @name 聚合搜索引擎切换导航[手机版][移动端]
// @namespace http://tampermonkey.net/
// @version 1.0.4
// @description 在搜索顶部显示一个聚合搜索引擎切换导航,模拟M浏览器的综合搜索引擎。专注手机网页搜索引擎切换,纯粹的搜索。SearchJump、搜索跳转、聚合搜索。
// @author PunkJet
// @home-url https://greasyfork.org/zh-CN/scripts/462130
// @match *://www.baidu.com/s*
// @match *://m.baidu.com/s*
// @match *://m.baidu.com/*/s*
// @include *://www.baidu.com/*/s*
// @include *://m.baidu.com/*/s*
// @match *://duckduckgo.com/*
// @match *://www.google.com/search*
// @match *://www.google.com.hk/search*
// @match *://www.bing.com/search*
// @match *://cn.bing.com/search*
// @match *://www.zhihu.com/search*
// @match *://m.sogou.com/web/searchList.jsp*
// @match *//m.sogou.com/web/*
// @match *://m.douban.com/search*
// @match *://yandex.com/search*
// @match *://quark.sm.cn/s*
// @grant unsafeWindow
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// @run-at document-idle
// @license MIT
// @downloadURL none
// ==/UserScript==
const searchUrlMap = [
{
name: "必应",
searchUrl: "https://cn.bing.com/search?q=",
searchkeyName: ["q"],
matchUrl:"cn.bing.com",
},
{
name: "百度",
searchUrl: "https://baidu.com/s?wd=",
searchkeyName: ["wd", "word"],
matchUrl:"baidu.com",
},
{
name: "谷歌",
searchUrl: "https://www.google.com/search?q=",
searchkeyName: ["q"],
matchUrl:"google.com",
},
{
name: "知乎",
searchUrl: "https://www.zhihu.com/search?q=",
searchkeyName: ["q"],
matchUrl:"zhihu.com",
},
{
name: "豆瓣",
searchUrl: "https://m.douban.com/search/?query=",
searchkeyName: ["query"],
matchUrl:"m.douban.com",
},
{
name: "夸克",
searchUrl: "https://quark.sm.cn/s?q=",
searchkeyName: ["q"],
matchUrl:"quark.sm.cn",
},
{
name: "搜狗",
searchUrl: "https://m.sogou.com/web/searchList.jsp?keyword=",
searchkeyName: ["keyword"],
matchUrl:"m.sogou.com/web",
},
{
name: "yandex",
searchUrl: "https://yandex.com/search/touch/?text=",
searchkeyName: ["text"],
matchUrl:"yandex.com",
},
{
name: "DuckDuckGo",
searchUrl: "https://duckduckgo.com/?q=",
searchkeyName: ["q"],
matchUrl:"duckduckgo.com",
}
];
function getSearchKeywords(name) {
const url_string = window.location.href;
const url = new URL(url_string);
return url.searchParams.get(name);
}
function getKeywords() {
let keywords = "";
for (let urlItem of searchUrlMap) {
if( window.location.href.indexOf(urlItem.matchUrl) >= 0 ) {
for (let keyItem of urlItem.searchkeyName) {
if ( window.location.href.indexOf(keyItem) >= 0 )
{
keywords = getSearchKeywords(keyItem);
return keywords;
}
}
}
}
return keywords;
}
function addSearchBox() {
const searchBox = document.createElement("div");
searchBox.id = "search-box";
const appBoxDiv = document.createElement("div");
appBoxDiv.id = "search-app-box";
searchBox.appendChild(appBoxDiv);
var ulList = document.createElement('ul');
appBoxDiv.appendChild(ulList);
let fragment = document.createDocumentFragment();//创建一个文档碎片,减少DOM渲染次数
for (let index in searchUrlMap) {
let liItem = document.createElement('li');
let item = searchUrlMap[index];
let a = document.createElement("a");
a.innerText = item.name;
if( window.location.href.indexOf(item.matchUrl) >= 0 ) {
a.className = "search-engine-highlight";
}
a.href = item.searchUrl + getKeywords();
liItem.appendChild(a);
fragment.appendChild(liItem);
}
ulList.appendChild(fragment);
const setBoxDiv = document.createElement("div");
setBoxDiv.id = "search-setting-box";
//setBoxDiv.innerHTML = `X`;
setBoxDiv.innerHTML = `
`;
searchBox.appendChild(setBoxDiv);
document.getElementsByTagName('head')[0].after(searchBox);
let btnClose = document.querySelector("#btnClose");
btnClose.onclick = function () {
searchBox.style = `display:none;`;
}
}
(function () {
"use strict";
const css =
`
#search-box {
opacity:1 !important;
position: fixed;
display: -webkit-flex;
display:flex;
top: 0px;
left: 0px;
width: 100%;
background-color: #FFFFFF !important;
font-size: 15px;
border-radius: 1px;
z-index: 99999;
}
#search-app-box {
flex:1;
width: 0;
}
#search-setting-box {
flex: 0 0 36px;
text-align: center;
margin: auto;
}
#search-app-box ul {
margin: 0;
padding: 0;
overflow: hidden;
overflow-x: auto;
list-style: none;
white-space:nowrap;
}
#search-app-box ul::-webkit-scrollbar {
display: none !important;
}
#search-app-box li {
margin-left: 0px;
display: inline-block;
}
#search-app-box ul li a {
display: block;
color: #767676 !important;
padding: 8px;
text-decoration: none;
font-weight:bold;
/*background-color: hsla(211, 60%, 35%, .1);*/
font-family:Helvetica Neue,Helvetica,Arial,Microsoft Yahei,Hiragino Sans GB,Heiti SC,WenQuanYi Micro Hei,sans-serif;
}
.search-engine-highlight {
background-color: hsla(211, 60%, 35%, .1) !important;
}
body{
margin-top: 35px !important;
}
.his-wrap-new .fix-wrap {
top:35px !important;
}
`
GM_addStyle(css);
addSearchBox();
})();