// ==UserScript==
// @name 搜索引擎切换器2(侧栏版)
// @namespace https://github.com/qq943260285
// @version 2.0.0
// @description 搜索引擎切换小助手,支持百度(Baidu)、谷歌(Google)、必应(Bing)、无追/360、神马/夸克、搜狗、f搜、头条/悟空、Yandex、Duckgo、雅虎(Yahoo)、Qwant、SwissCows等23个站点,支持更改排序和显示(在代码中)
// @author 小宇专属
// @license GPL-3.0-only
// @include *
// @exclude *image*
// @exclude *video*
// @grant GM_addStyle
// ==/UserScript==
"use strict";
(function() {
window.WeltTool = function(config) {
if (!config) config = {};
if (!config.id) config.id = "xyzs-welt-tool";
if (!config.itemList || !config.itemList.length) config.itemList = [];
var mainDivDom, titleDiv = document.createElement("style"), bodyDom = document.getElementsByTagName("body")[0];
if (titleDiv.innerHTML = ".xyzs-welt-tool{position:fixed;width:124px;height:200px;display:flex;background-color:#C1FFFB;opacity:.3;border-radius:10px;padding:5px 40px 5px 5px;flex-direction:column;bottom:200px;left:-148px;z-index:99999;transition:all .4s;overflow:hidden;}.xyzs-welt-tool:hover{opacity:1;background-color:hsla(200, 40%, 96%,.9);left:5px;overflow-y:scroll;padding:5px 10px;transition:all .4s;height:300px;}.xyzs-welt-tool .xyzs-title-div{font-size:6px;padding:0 0 2px;margin:0 5px 5px;text-align: center;color:#067;border-bottom:1px solid currentColor;line-height: 7px;}.xyzs-welt-tool .xyzs-item-list-div{margin:0;display:flex;justify-content:center;align-items:center;flex-direction:row;flex-wrap:wrap;}.xyzs-welt-tool .xyzs-item-list-div .xyzs-item-div{display:flex;width:max-content !important;margin:2px 2px;padding:4px;color:#222;font-size:13px !important;cursor:pointer;white-space:nowrap;box-sizing:border-box;}.xyzs-welt-tool .xyzs-item-list-div .xyzs-item-div:hover{color:#067;transition:all .4s;}", bodyDom.appendChild(titleDiv), (mainDivDom = document.createElement("div")).id = config.id,
mainDivDom.className = "xyzs-welt-tool", config.color) mainDivDom.style.backgroundColor = config.color;
if (mainDivDom.onmouseout = function(e) {
}, mainDivDom.onmouseover = function(e) {
}, void 0 !== config.title) {
titleDiv = document.createElement("div");
titleDiv.className = "xyzs-title-div", titleDiv.innerHTML = decodeURI(config.title),
mainDivDom.appendChild(titleDiv);
}
var listDivDom = document.createElement("div");
listDivDom.className = "xyzs-item-list-div";
for (var i = 0; i < config.itemList.length; i++) (function(itemDiv) {
var item = config.itemList[itemDiv];
if (item.show(item.data)) {
if (item.onload) item.onload(item.data);
itemDiv = document.createElement("div");
itemDiv.className = "xyzs-item-div", itemDiv.title = item.title, itemDiv.onclick = function(e) {
if (item.onclick) item.onclick(e, item.data);
}, itemDiv.onmouseout = function(e) {
if (item.onmouseout) item.onmouseout(e, item.data);
}, itemDiv.onmouseover = function(e) {
if (item.onmouseover) item.onmouseover(e, item.data);
}, itemDiv.innerHTML = item.name, listDivDom.appendChild(itemDiv);
}
})(i);
mainDivDom.appendChild(listDivDom), bodyDom.appendChild(mainDivDom)
};
})(), function() {
function getKeywordString() {
for (var i = 0; i < searchList.length; i++) {
var urlParam = searchList[i];
if (matchItemHost(urlParam)) {
urlParam = function(url) {
for (var pList = url.substring(url.indexOf("?") + 1).split("&"), i = 0; i < pList.length; i++) {
var pair = pList[i].split("=");
if (pair[1] === CONFIG.KeywordSymbol) return pair[0];
}
return !1;
}(urlParam.searchUrl), urlParam = function(url, name) {
for (var pList = url.substring(url.indexOf("?") + 1).split("&"), i = 0; i < pList.length; i++) {
var pair = pList[i].split("=");
if (pair[0] === name) return pair[1];
}
return !1;
}(window.location.href, urlParam);
return urlParam;
}
}
return "";
}
function createDiv() {
for (var itemList = [], _loop = function(i) {
var search = searchList[i];
itemList.push({
name: search.name,
title: search.host,
onclick: function(e, data) {
window.open(function(search) {
var keywordString = getKeywordString();
return search.searchUrl.replaceAll(CONFIG.KeywordSymbol, keywordString);
}(search), "_blank");
},
show: function(data) {
return search.show && !matchItemHost(search);
},
data: search
});
}, i = 0; i < searchList.length; i++) _loop(i);
new WeltTool({
title: "“"+getKeywordString()+"”",
itemList: itemList
});
}
function matchItemHost(item) {
if (item.host === window.location.host) return 1;
var countryHost = item.countryHost;
if (countryHost && 0 < countryHost.length) for (var j = 0; j < countryHost.length; j++) if (countryHost[j] === window.location.host) return 1;
return;
}
var SEARCH_TYPE_RequestParam = 0, CONFIG = {
KeywordSymbol: "%s",
DivId: "xyzs-search",
defaultSearchType: SEARCH_TYPE_RequestParam,
defaultCustomize: !1
}, searchList = [ {
index: 1,
name: "百度",
host: "www.baidu.com",
searchUrl: "https://www.baidu.com/s?word=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
countryHost: [ "m.baidu.com","wap.baidu.com" ]
}, {
index: 2,
name: "Bing",
host: "bing.com",
searchUrl: "https://bing.com/search?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
countryHost: ["cn.bing.com","www.bing.com"]
},{
index: 3,
name: "Google",
host: "www.google.com",
searchUrl: "https://www.google.com/search?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
}, {
index: 4,
name: "无追",
host: "www.wuzhuiso.com",
searchUrl: "https://www.wuzhuiso.com/s?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
countryHost: [ "m.wuzhuiso.com" ]
}, {
index: 5,
name: "神马",
host: "yz.m.sm.cn",
searchUrl: "https://yz.m.sm.cn/s?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
countryHost: [ ]
},{
index: 6,
name: "搜狗",
host: "wap.sogou.com",
searchUrl: "https://wap.sogou.com/web/sl?bid=sogou-mobb-15adc2044e61b45c&keyword=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
countryHost: [ "www.sogou.com","m.sogou.com" ]
},{
index: 7,
name: "f搜",
host: "fsoufsou.com",
searchUrl: "https://fsoufsou.com/search?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0
},
{
index: 8,
name: "头条搜索",
host: "so.toutiao.com",
searchUrl: "https://so.toutiao.com/search?keyword=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
countryHost:["tsearch.toutiaoapi.com"]
},{
index: 9,
name: "Duckgo",
host: "duckduckgo.com",
searchUrl: "https://duckduckgo.com/?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !1,//默认隐藏,将1改为0显示
countryHost: [ ]
},{
index: 10,
name: "Yandex",
host: "www.yandex.com",
searchUrl: "https://www.yandex.com/search/touch/?text=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
},{
index: 11,
name: "Yahoo",
host: "search.yahoo.com",
searchUrl: "https://search.yahoo.com/search?p=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !1,//默认隐藏,将1改为0显示
},{
index: 12,
name: "Ecosia",
host: "www.ecosia.org",
searchUrl: "https://www.ecosia.org/search?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !1,//默认隐藏,将1改为0显示
},{
index: 13,
name: "Qwant",
host: "www.qwant.com",
searchUrl: "https://www.qwant.com/?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
countryHost: [ "lite.qwant.com" ]
},{
index: 14,
name: "SwissCows",
host: "swisscows.com",
searchUrl: "https://swisscows.com/en/web?query=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0
},{
index: 15,
name: "夸克",
host: "quark.sm.cn",
searchUrl: "https://quark.sm.cn/s?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !1,//默认隐藏,将1改为0显示
},{
index: 16,
name: "360搜索",
host: "www.so.com",
searchUrl: "https://www.so.com/s?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !1,//默认隐藏,将1改为0显示
countryHost: [ "m.so.com" ]
},{
index: 17,
name: "知乎搜索",
host: "www.zhihu.com",
searchUrl: "https://www.zhihu.com/search?q=%s&type=content",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
countryHost: [ "m.zhihu.com" ]
},{
index: 18,
name: "微博",
host: "m.weibo.cn",
searchUrl: "https://m.weibo.cn/search?containerid=100103type=1&q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
countryHost: [ "www.weibo.com" ]
},{
index: 19,
name: "B站",
host: "m.bilibili.com",
searchUrl: "https://m.bilibili.com/search?keyword=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
countryHost: ["search.bilibili.com"]
},{
index: 20,
name: "微信文章",
host: "weixin.sogou.com",
searchUrl: "https://weixin.sogou.com/weixinwap?type=2&query=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,
},{
index: 21,
name: "GitHub",
host: "github.com",
searchUrl: "https://github.com/search?o=desc&q=%s&s=stars&type=Repositories",
searchType: SEARCH_TYPE_RequestParam,
show: !1,//默认隐藏,将1改为0显示
},{
index: 22,
name: "Gitee",
host: "search.gitee.com",
searchUrl: "https://search.gitee.com/?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !1,//默认隐藏,将1改为0显示
},{
index: 23,//序号,用来排序的
name: "GreasyFork",//名字,用来显示的
host: "gf.qytechs.cn",//应用到此域名
searchUrl: "https://gf.qytechs.cn/zh-CN/scripts?q=%s",
searchType: SEARCH_TYPE_RequestParam,
show: !0,//默认显示,将0改为1隐藏
countryHost: [ "sleazyfork.org" ],//相似域名
},
];
(function() {
if (top !== window) return;
for (var i = 0; i < searchList.length; i++) if (matchItemHost(searchList[i])) return createDiv();
})();
}();