// ==UserScript==
// @name Metasearch
// @namespace https://github.com/Jkker/metasearch-v3
// @version 1.0.1
// @description Aggregated Searcher
// @author Jkker
// @license MIT
// @match *://google.com/search*
// @match *://*.google.com/search*
// @match *://baidu.com/s*
// @match *://*.baidu.com/s*
// @match *://zhihu.com/search*
// @match *://*.zhihu.com/search*
// @match *://bilibili.com/all*
// @match *://*.bilibili.com/all*
// @match *://duckduckgo.com/*
// @match *://*.duckduckgo.com/*
// @match *://google.com/search*
// @match *://*.google.com/search*
// @match *://youtube.com/results*
// @match *://*.youtube.com/results*
// @match *://github.com/search*
// @match *://*.github.com/search*
// @match *://toutiao.com/search*
// @match *://*.toutiao.com/search*
// @match *://weibo.com/weibo*
// @match *://*.weibo.com/weibo*
// @match *://wpxz.org/*
// @match *://*.wpxz.org/*
// @match *://google.com/search*
// @match *://*.google.com/search*
// @match *://youdao.com/result*
// @match *://*.youdao.com/result*
// @match *://amazon.com/s*
// @match *://*.amazon.com/s*
// @match *://ebay.com/sch/i.html*
// @match *://*.ebay.com/sch/i.html*
// @match *://jd.com/bases/m/searchKeyword.htm*
// @match *://*.jd.com/bases/m/searchKeyword.htm*
// @match *://taobao.com/search*
// @match *://*.taobao.com/search*
// @match *://mozilla.org/en-US/search*
// @match *://*.mozilla.org/en-US/search*
// @match *://sogou.com/weixin*
// @match *://*.sogou.com/weixin*
// @icon https://raw.githubusercontent.com/Jkker/metasearch-v3/master/src/public/favicon.ico
// @grant none
// @supportURL https://github.com/Jkker/metasearch-v3/issues
// @downloadURL none
// ==/UserScript==
(function() {
var _a, _b, _c;
"use strict";
const styles = "";
const engines = [
{
name: "Google",
key: "google",
display: "",
disabled: false,
url: "https://www.google.com/search?igu=1&pws=0&gl=us&gws_rd=cr&source=hp&newwindow=1&q=%s&oq=%s&safe=off",
preload: false,
embeddable: true,
weight: 10,
url_scheme: "",
lightness: 0.607843137254902,
color: "#4285F4",
icon: ''
},
{
name: "\u767E\u5EA6",
key: "baidu",
display: "",
disabled: false,
url: "https://www.baidu.com/s?ie=utf-8&word=%s",
preload: false,
embeddable: true,
weight: 9,
lightness: 0.5078431372549019,
color: "#556dea",
icon: '',
q: "word"
},
{
name: "\u77E5\u4E4E",
key: "zhihu",
display: "",
preload: false,
disabled: false,
url: "https://www.zhihu.com/search?type=content&q=%s",
embeddable: false,
weight: 8,
url_scheme: "zhihu://search?q=%s",
lightness: 0.5,
color: "#0084FF",
icon: ''
},
{
name: "bilibili",
key: "bilibili",
display: "",
preload: false,
disabled: false,
url: "https://search.bilibili.com/all?keyword=%s",
q: "keyword",
embeddable: true,
weight: 7,
url_scheme: "bilibili://search?keyword=%s",
lightness: 0.6431372549019607,
color: "#DF698C",
icon: ''
},
{
name: "Duckduckgo",
key: "duckduckgo",
display: "",
url: "https://duckduckgo.com/?q=%s&kaj=m&k1=-1&kn=1&kp=-2",
preload: false,
embeddable: true,
weight: 6,
disabled: false,
lightness: 0.6039215686274509,
color: "#E37151",
icon: ''
},
{
name: "Reddit",
key: "reddit",
display: "",
disabled: false,
url: "https://www.google.com/search?q=%s+site%3Areddit.com",
preload: false,
embeddable: true,
weight: 6,
url_scheme: "",
lightness: 0.5372549019607843,
color: "#eb5527",
icon: '',
match: (base, query) => base.includes("google.com") && query.includes("site:reddit.com")
},
{
name: "YouTube",
key: "youtube",
display: "",
preload: false,
disabled: false,
url: "https://www.youtube.com/results?search_query=%s",
q: "search_query",
embeddable: true,
weight: 6,
url_scheme: "youtube://YouTube.com/results?search_query=%s",
lightness: 0.5254901960784314,
color: "#ea3322",
icon: ''
},
{
name: "Github",
key: "github",
display: "",
preload: false,
disabled: false,
url: "https://github.com/search?q=%s",
embeddable: true,
weight: 5,
lightness: 0.09215686274509804,
color: "#181717",
icon: ''
},
{
name: "\u4ECA\u65E5\u5934\u6761",
key: "toutiao",
display: "",
preload: false,
disabled: false,
url: "https://so.toutiao.com/search?keyword=%s",
q: "keyword",
embeddable: true,
weight: 4,
lightness: 0.5764705882352941,
color: "#dd5049",
icon: ''
},
{
name: "\u5FAE\u535A",
key: "weibo",
display: "",
preload: false,
disabled: false,
url: "https://s.weibo.com/weibo?q=%s",
embeddable: true,
weight: 4,
url_scheme: "sinaweibo://searchall?q=%s",
lightness: 0.5156862745098039,
color: "#d33436",
icon: ''
},
{
name: "\u7F51\u76D8\u5C0F\u7AD9",
key: "wpxz",
display: "",
url: "https://wpxz.org/?q=%s",
preload: false,
embeddable: true,
weight: 4,
disabled: false,
url_scheme: "",
lightness: 0.6607843137254902,
color: "#5476fd",
icon: ''
},
{
name: "Quora",
key: "quora",
display: "",
url: "https://www.google.com/search?q=%s+site%3Aquora.com",
url_scheme: "",
preload: false,
embeddable: true,
weight: 3,
disabled: false,
lightness: 0.42549019607843136,
color: "#aa382f",
icon: ''
},
{
name: "\u6709\u9053",
key: "youdao",
display: "",
preload: false,
disabled: false,
url: "https://dict.youdao.com/result?word=%s&lang=en",
q: "word",
embeddable: true,
weight: 3,
lightness: 0.484313725490196,
color: "#E31436",
icon: ''
},
{
name: "Amazon",
key: "amazon",
display: "",
preload: false,
disabled: false,
url: "https://www.amazon.com/s?k=%s",
q: "k",
embeddable: true,
weight: 2,
lightness: 0.5,
color: "#FF9900",
icon: ''
},
{
name: "eBay",
key: "ebay",
display: "",
url: "https://www.ebay.com/sch/i.html?_nkw=%s",
q: "_nkw",
preload: false,
embeddable: true,
weight: 2,
disabled: false,
lightness: 0.5862745098039215,
color: "#4164ea",
icon: ''
},
{
name: "\u4EAC\u4E1C",
key: "jing-dong",
display: "",
preload: false,
disabled: false,
url: "https://sou.m.jd.com/bases/m/searchKeyword.htm?keyword=%s",
q: "keyword",
embeddable: true,
weight: 1,
url_scheme: 'openapp.jdmobile://virtual?params={"des":"productList","keyWord":"%s","from":"search","category":"jump"}',
lightness: 0.4941176470588235,
color: "#E1251B",
icon: ''
},
{
name: "\u6DD8\u5B9D",
key: "taobao",
display: "",
preload: false,
disabled: false,
url: "https://s.taobao.com/search?q=%s",
embeddable: true,
weight: 1,
url_scheme: "taobao://s.taobao.com?q=%s",
lightness: 0.5196078431372548,
color: "#E94F20",
icon: ''
},
{
name: "MDN",
key: "mdnwebdocs",
display: "",
preload: false,
disabled: false,
url: "https://developer.mozilla.org/en-US/search?q=%s",
embeddable: true,
weight: -1,
lightness: 0,
color: "#000000",
icon: ''
},
{
name: "\u5FAE\u4FE1",
key: "wechat",
display: "",
preload: false,
disabled: false,
url: "https://weixin.sogou.com/weixin?p=01030402&query=%s&type=2&ie=utf8",
q: "query",
embeddable: true,
weight: -2,
lightness: 0.39215686274509803,
color: "#07C160",
icon: ''
}
];
function Button({ icon, color, name, display, lightness, href }) {
const a = document.createElement("a");
a.style.color = color;
a.href = href;
if (!display) {
a.style.display = "none";
}
a.title = name;
a.classList.add("icon-button");
a.innerHTML = icon;
const text = document.createElement("span");
text.innerText = name;
if (lightness < 0.3) {
a.classList.add("dark-invert");
}
a.append(text);
return a;
}
const body = document.querySelector("body");
const root = document.createElement("div");
const linkContainer = document.createElement("div");
linkContainer.id = "metasearch-link-container";
root.id = "metasearch-root";
let prevScrollPosition = window.pageYOffset;
window.onscroll = function() {
const currentScrollPos = window.pageYOffset;
root.style.bottom = prevScrollPosition > currentScrollPos ? "0" : "-40px";
prevScrollPosition = currentScrollPos;
};
const getHost = (host) => host.split(".").at(-2);
const currHost = getHost(window.location.host);
let curr = -1;
const q = (_c = new URLSearchParams(window.location.search).get((_b = (_a = engines[curr]) == null ? void 0 : _a.q) != null ? _b : "q")) != null ? _c : "";
for (const i in engines) {
const engine = engines[i];
const button = Button({
icon: engine.icon,
color: engine.color,
name: engine.name,
display: true,
lightness: engine.lightness,
href: engine.url.replaceAll("%s", q)
});
linkContainer.appendChild(button);
if (curr !== -1)
continue;
const U = new URL(engine.url);
const host = getHost(U.host);
if (host === currHost) {
console.log("Found current engine", engine);
curr = i;
}
}
root.appendChild(linkContainer);
const close = document.createElement("button");
close.innerHTML = ``;
close.classList.add("icon-button");
close.id = "metasearch-close";
close.addEventListener("click", () => {
root.style.bottom = "-40px";
});
root.appendChild(close);
body.appendChild(root);
function styleInject(css,ref){if(ref===void 0){ref={}}var insertAt=ref.insertAt;if(!css||typeof document==="undefined"){return}var head=document.head||document.getElementsByTagName("head")[0];var style=document.createElement("style");style.type="text/css";if(insertAt==="top"){if(head.firstChild){head.insertBefore(style,head.firstChild)}else{head.appendChild(style)}}else{head.appendChild(style)}if(style.styleSheet){style.styleSheet.cssText=css}else{style.appendChild(document.createTextNode(css))}};styleInject(`#metasearch-root {
box-sizing: border-box;
width: 100vw;
display: flex;
position: fixed;
bottom: 0;
left: 0;
transition: all 0.1s ease-in-out;
height: 40px;
background-color: rgba(255, 255, 255, 0.8);
backdrop-filter: blur(8px);
z-index: 999999999;
}
#metasearch-root .icon-button {
all: unset;
box-sizing: border-box;
text-decoration: none;
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
background-color: transparent;
border: 0;
outline: transparent;
cursor: pointer;
transition: all 0.15s ease-in-out;
white-space: nowrap;
-webkit-tap-highlight-color: transparent;
color: black;
flex: 1 0 auto;
padding: 2px 6px;
min-width: 40px;
height: 100%;
}
#metasearch-root .icon-button > svg {
width: 1em;
height: 1em;
color: currentColor;
fill: currentColor;
stroke: currentColor;
}
@media screen and (prefers-color-scheme: dark) {
#metasearch-root .icon-button {
color: white;
}
}
#metasearch-root .icon-button:hover {
filter: brightness(0.85);
background-color: rgba(0, 0, 0, 0.08);
}
@media screen and (prefers-color-scheme: dark) {
#metasearch-root .icon-button:hover.dark-invert {
filter: invert(1) hue-rotate(180deg) brightness(0.85);
}
}
#metasearch-root .icon-button:active {
-webkit-tap-highlight-color: transparent;
filter: brightness(0.7);
background-color: rgba(0, 0, 0, 0.12);
}
@media screen and (prefers-color-scheme: dark) {
#metasearch-root .icon-button:active.dark-invert {
filter: invert(1) hue-rotate(180deg) brightness(0.7);
}
}
@media screen and (max-width: 768px) {
#metasearch-root .icon-button {
padding: 0;
}
#metasearch-root .icon-button > span {
display: none;
}
}
@media screen and (prefers-color-scheme: dark) {
#metasearch-root {
background-color: rgba(0, 0, 0, 0.7);
}
#metasearch-root .dark-invert {
filter: invert(1) hue-rotate(180deg);
}
}
#metasearch-root #metasearch-close {
box-shadow: 0px 9px 9px rgba(0, 0, 0, 0.17);
}
#metasearch-root #metasearch-link-container {
scrollbar-width: none;
overflow-x: auto;
width: 100%;
display: flex;
box-sizing: border-box;
}
#metasearch-root #metasearch-link-container::-webkit-scrollbar {
display: none;
}
body {
position: relative !important;
}`);
})();