Skip to content

Instantly share code, notes, and snippets.

@Thomashighbaugh
Last active November 12, 2023 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thomashighbaugh/8a9934e272fe9988e3bc3ff2bf6fea26 to your computer and use it in GitHub Desktop.
Save Thomashighbaugh/8a9934e272fe9988e3bc3ff2bf6fea26 to your computer and use it in GitHub Desktop.
Metasearch user script but without Chinese sites I don't use and some extra search engines I do use.
// ==UserScript==
// @name Metasearch
// @namespace https://gist.github.com/Thomashighbaugh/8a9934e272fe9988e3bc3ff2bf6fea26
// @version 1.2.6
// @description Toolbar on the bottom of search result pages for using the same query to search other search engines. Fork of Jkker's Metasearch
// @author Thomas Leon Highbaugh
// @license MIT
// @match *://google.com/search*
// @match *://*.google.com/search*
// @match *://duckduckgo.com/*
// @match *://*.duckduckgo.com/*
// @match *://youtube.com/results*
// @match *://*.youtube.com/results*
// @match *://github.com/search*
// @match *://*.github.com/search*
// @match *://twitter.com/search*
// @match *://*.twitter.com/search*
// @match *://wolframalpha.com/input*
// @match *://*.wolframalpha.com/input*
// @match *://bing.com/search*
// @match *://*.bing.com/search*
// @match *://metager.org/meta*
// @match *://*.metager.org/meta*
// @match *://amazon.com/s*
// @match *://*.amazon.com/s*
// @match *://ebay.com/sch/i.html*
// @match *://*.ebay.com/sch/i.html*
// @match *://mozilla.org/en-US/search*
// @match *://*.mozilla.org/en-US/search*
// @icon https://raw.githubusercontent.com/Jkker/metasearch-tampermonkey/master/src/favicon.ico
// @grant none
// @supportURL https://gist.github.com/Thomashighbaugh/8a9934e272fe9988e3bc3ff2bf6fea26
// ==/UserScript==
(function() {
"use strict";
const allEngines = [
{
name: "Google",
key: "google",
disabled: false,
url: "https://www.google.com/search?igu=1&pws=0&gl=us&q=%s&oq=%s&safe=off",
matchSite: /^https?:\/\/www\.google(?:\.[A-z]{2,3}){1,2}\/[^?]+\?(?!tbm=)(?:&?q=|(?:[^#](?!&tbm=))+?&q=)(?:.(?!&tbm=))*$|(^https?:\/\/xn--flw351e\.ml\/search\?q=)/i,
preload: false,
embeddable: true,
weight: 10,
url_scheme: "",
lightness: 0.607843137254902,
color: "#4285F4",
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><g><path fill="none" d="M0 0h24v24H0z"></path><path d="M3.064 7.51A9.996 9.996 0 0 1 12 2c2.695 0 4.959.99 6.69 2.605l-2.867 2.868C14.786 6.482 13.468 5.977 12 5.977c-2.605 0-4.81 1.76-5.595 4.123-.2.6-.314 1.24-.314 1.9 0 .66.114 1.3.314 1.9.786 2.364 2.99 4.123 5.595 4.123 1.345 0 2.49-.355 3.386-.955a4.6 4.6 0 0 0 1.996-3.018H12v-3.868h9.418c.118.654.182 1.336.182 2.045 0 3.046-1.09 5.61-2.982 7.35C16.964 21.105 14.7 22 12 22A9.996 9.996 0 0 1 2 12c0-1.614.386-3.14 1.064-4.49z"></path></g></svg>'
},
{
name: "MetaGer",
key: "metager",
disabled: false,
url: "https://metager.org/meta/meta.ger3?eingabe=%s",
matchSite: /^https?:\/\/metager\.org\/*/i,
preload: false,
embeddable: true,
weight: 10,
url_scheme: "https://metager.org/meta/meta.ger3?eingabe=%s",
lightness: 0.607843137254902,
color: "#F47216",
icon: '<svg height="132.62419" viewBox="0 0 813.33331 142.66667" width="754.010258" xmlns="http://www.w3.org/2000/svg"><g fill="#f47216" transform="matrix(.13333 0 0 -.13333 0 142.67)"><path d="m8.1133 805.72v-798.85h110.19v688.66h422.38v-688.66h107.12v688.66h264.75c104.06 0 156.1-55.09 156.1-163.75v-524.91h111.71v543.28c0 169.87-82.64 255.57-246.39 255.57h-925.87"/><path d="m2074.1 6.8711v108.66h-456.05c-101 0-151.5 53.563-151.5 157.63v273.93c0 108.65 52.04 149.98 156.1 149.98h243.32c82.64 0 125.49-41.32 125.49-122.43v-15.305c0-70.391-41.32-105.59-123.96-105.59h-325.14v-94.886l354.22.003c136.2 0 202.01 59.692 202.01 177.53v58.152c0 140.78-70.4 211.18-212.72 211.18h-281.59c-165.28 0-249.45-85.699-249.45-255.57v-287.7c0-169.87 84.17-255.57 249.45-255.57h469.82"/><path d="m2654.1 115.53h-21.53c-98.36 0-148.88 50.86-151.4 149.73v431.81h172.93v108.65h-172.93v73.277h.16v112.79c0 48.231-19.15 74.091-69.52 74.091h-42.19v-113.38h-.17v-146.78h-149.97v-108.65h149.97v-146.92l-.1.003v-287.7c0-3.265.04-6.492.1-9.695v-19.105h.77c9.22-150.7 92.92-226.77 248.57-226.77h35.31v108.66"/><path d="m2828 805.72v-230.32h69.31c27.25 0 40.87 14.426 40.87 42.879v78.789h345.86c101.01 0 151.51-53.668 151.51-157.63v-85.7h-497.37l.01-52.015c0-28.313-13.75-42.871-40.87-42.871h-93.81v-140.79c0-140.79 70.4-211.19 212.72-211.19h281.59c165.27 0 249.45 85.699 249.45 255.57v287.7c0 169.87-84.18 255.57-249.45 255.57zm289.79-446.87h74.76c50.36 0 69.52-25.856 69.52-74.098v-112.79c0-38.305-19.21-58.168-56.76-58.168h-38.57c-32.53 0-48.95 19.25-48.95 57.465v187.59"/><path d="m3966.6 1065.9c-166.8 0-249.45-84.169-249.45-254.03l.01-550.94c0-169.86 82.64-254.04 249.45-254.04h344.33c149.97 0 224.96 74.988 224.96 226.5v342.03h-425.45v-94.878h316.79v-225.73c0-93.34-45.92-139.26-139.26-139.26h-299.95c-102.52 0-154.56 52.028-154.56 157.62l-.01 520.33c0 105.6 52.03 157.62 154.57 157.62h521.85v114.78h-543.28"/><path d="m5875 805.72c-166.81 0-249.45-85.699-249.45-255.82v-543.02h111.72v524.66c0 108.91 53.56 164 157.62 164h195.89v110.19h-215.78"/><path d="m5426.6 6.8711v108.66h-456.05c-101 0-151.5 53.563-151.5 157.63v273.93c0 108.65 52.03 149.98 156.09 149.98h243.33c82.64 0 125.49-41.32 125.49-122.43v-15.305c0-70.391-41.32-105.59-123.96-105.59h-325.14v-94.886l354.22.003c136.2 0 202.01 59.692 202.01 177.53v58.152c0 140.78-70.4 211.18-212.72 211.18h-281.59c-165.28 0-249.45-85.699-249.45-255.57v-287.7c0-169.87 84.17-255.57 249.45-255.57h469.82"/></g></svg>'
},
{
},
{
name: "DDG",
key: "duckduckgo",
url: "https://duckduckgo.com/?q=%s&kaj=m&k1=-1&kn=1&kp=-2",
matchSite: /^https?:\/\/duckduckgo\.com\/*/i,
preload: false,
embeddable: true,
weight: 6,
disabled: false,
lightness: 0.6039215686274509,
color: "#E37151",
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" role="img" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><title></title><path d="M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0zm0 23C5.925 23 1 18.074 1 12S5.926 1 12 1s11 4.925 11 11-4.925 11-11 11zm10.219-11c0 4.805-3.317 8.833-7.786 9.925-.27-.521-.53-1.017-.749-1.438.645.249 1.93.718 2.208.615.376-.144.282-3.149-.14-3.245-.338-.075-1.632.837-2.141 1.209l.034.156c.078.397.144.993.03 1.247-.001.004-.002.01-.004.013a.218.218 0 0 1-.068.088c-.284.188-1.081.284-1.503.188a.516.516 0 0 1-.064-.02c-.694.396-2.01 1.109-2.25.971-.329-.188-.377-2.676-.329-3.288.035-.46 1.653.286 2.442.679.174-.163.602-.272.98-.31-.57-1.389-.99-2.977-.733-4.105 0 .002.002.002.002.002.356.248 2.73 1.05 3.91 1.027 1.18-.024 3.114-.743 2.903-1.323-.212-.58-2.135.51-4.142.324-1.486-.138-1.748-.804-1.42-1.29.414-.611 1.168.116 2.411-.256 1.245-.371 2.987-1.035 3.632-1.397 1.494-.833-.625-1.177-1.125-.947-.474.22-2.123.637-2.889.82.428-1.516-.603-4.149-1.757-5.3-.376-.376-.951-.612-1.603-.736-.25-.344-.654-.671-1.225-.977a5.772 5.772 0 0 0-3.595-.584l-.024.004-.034.004.004.002c-.148.028-.237.08-.357.098.148.016.705.276 1.057.418-.174.068-.412.108-.596.184a.828.828 0 0 0-.204.056c-.173.08-.303.375-.3.515.84-.086 2.082-.026 2.991.246-.644.09-1.235.258-1.661.482-.016.008-.03.018-.048.028-.054.02-.106.042-.152.066-1.367.72-1.971 2.405-1.611 4.424.323 1.824 1.665 8.088 2.29 11.064-3.973-1.4-6.822-5.186-6.822-9.639C1.781 6.356 6.356 1.781 12 1.781S22.219 6.356 22.219 12zM9.095 9.581a.758.758 0 1 0 0 1.516.758.758 0 0 0 0-1.516zm.338.702a.196.196 0 1 1 0-.392.196.196 0 0 1 0 .392zm4.724-1.043a.65.65 0 1 0 0 1.299.65.65 0 0 0 0-1.3zm.29.601a.168.168 0 1 1 0-.336.168.168 0 0 1 0 .336zM9.313 8.146s-.571-.26-1.125.09c-.554.348-.534.704-.534.704s-.294-.656.49-.978c.786-.32 1.17.184 1.17.184zm5.236-.052s-.41-.234-.73-.23c-.654.008-.831.296-.831.296s.11-.688.945-.55a.84.84 0 0 1 .616.484z"></path></svg>'
},
{
name: "Reddit",
key: "reddit",
disabled: false,
url: "https://www.google.com/search?q=%s+site%3Areddit.com",
matchSite: (url2, query) => {
var _a, _b, _c;
return url2.includes("google.com") && ((_c = (_b = decodeURIComponent((_a = query.get("q")) != null ? _a : "")) == null ? void 0 : _b.includes) == null ? void 0 : _c.call(_b, "site:reddit.com"));
},
q: (url2, query) => {
var _a, _b, _c;
return (_c = (_b = decodeURIComponent((_a = query.get("q")) != null ? _a : "")).replace) == null ? void 0 : _c.call(_b, "site:reddit.com", "");
},
preload: false,
embeddable: true,
weight: 6,
url_scheme: "",
lightness: 0.5372549019607843,
color: "#eb5527",
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" role="img" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><title></title><path d="M12 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0zm5.01 4.744c.688 0 1.25.561 1.25 1.249a1.25 1.25 0 0 1-2.498.056l-2.597-.547-.8 3.747c1.824.07 3.48.632 4.674 1.488.308-.309.73-.491 1.207-.491.968 0 1.754.786 1.754 1.754 0 .716-.435 1.333-1.01 1.614a3.111 3.111 0 0 1 .042.52c0 2.694-3.13 4.87-7.004 4.87-3.874 0-7.004-2.176-7.004-4.87 0-.183.015-.366.043-.534A1.748 1.748 0 0 1 4.028 12c0-.968.786-1.754 1.754-1.754.463 0 .898.196 1.207.49 1.207-.883 2.878-1.43 4.744-1.487l.885-4.182a.342.342 0 0 1 .14-.197.35.35 0 0 1 .238-.042l2.906.617a1.214 1.214 0 0 1 1.108-.701zM9.25 12C8.561 12 8 12.562 8 13.25c0 .687.561 1.248 1.25 1.248.687 0 1.248-.561 1.248-1.249 0-.688-.561-1.249-1.249-1.249zm5.5 0c-.687 0-1.248.561-1.248 1.25 0 .687.561 1.248 1.249 1.248.688 0 1.249-.561 1.249-1.249 0-.687-.562-1.249-1.25-1.249zm-5.466 3.99a.327.327 0 0 0-.231.094.33.33 0 0 0 0 .463c.842.842 2.484.913 2.961.913.477 0 2.105-.056 2.961-.913a.361.361 0 0 0 .029-.463.33.33 0 0 0-.464 0c-.547.533-1.684.73-2.512.73-.828 0-1.979-.196-2.512-.73a.326.326 0 0 0-.232-.095z"></path></svg>'
},
{
name: "YouTube",
key: "youtube",
preload: false,
disabled: false,
url: "https://www.youtube.com/results?search_query=%s",
matchSite: /^https?:\/\/www\.youtube\.com\/results/i,
q: "search_query",
embeddable: true,
weight: 6,
url_scheme: "youtube://YouTube.com/results?search_query=%s",
lightness: 0.5254901960784314,
color: "#ea3322",
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><g><path fill="none" d="M0 0h24v24H0z"></path><path d="M21.543 6.498C22 8.28 22 12 22 12s0 3.72-.457 5.502c-.254.985-.997 1.76-1.938 2.022C17.896 20 12 20 12 20s-5.893 0-7.605-.476c-.945-.266-1.687-1.04-1.938-2.022C2 15.72 2 12 2 12s0-3.72.457-5.502c.254-.985.997-1.76 1.938-2.022C6.107 4 12 4 12 4s5.896 0 7.605.476c.945.266 1.687 1.04 1.938 2.022zM10 15.5l6-3.5-6-3.5v7z"></path></g></svg>'
},
{
name: "Github",
key: "github",
preload: false,
disabled: false,
url: "https://github.com/search?q=%s",
matchSite: /^https?:\/\/github\.com\/search/i,
embeddable: true,
weight: 5,
lightness: 0.09215686274509804,
color: "#181717",
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><g><path fill="none" d="M0 0h24v24H0z"></path><path d="M12 2C6.475 2 2 6.475 2 12a9.994 9.994 0 0 0 6.838 9.488c.5.087.687-.213.687-.476 0-.237-.013-1.024-.013-1.862-2.512.463-3.162-.612-3.362-1.175-.113-.288-.6-1.175-1.025-1.413-.35-.187-.85-.65-.013-.662.788-.013 1.35.725 1.538 1.025.9 1.512 2.338 1.087 2.912.825.088-.65.35-1.087.638-1.337-2.225-.25-4.55-1.113-4.55-4.938 0-1.088.387-1.987 1.025-2.688-.1-.25-.45-1.275.1-2.65 0 0 .837-.262 2.75 1.026a9.28 9.28 0 0 1 2.5-.338c.85 0 1.7.112 2.5.337 1.912-1.3 2.75-1.024 2.75-1.024.55 1.375.2 2.4.1 2.65.637.7 1.025 1.587 1.025 2.687 0 3.838-2.337 4.688-4.562 4.938.362.312.675.912.675 1.85 0 1.337-.013 2.412-.013 2.75 0 .262.188.574.688.474A10.016 10.016 0 0 0 22 12c0-5.525-4.475-10-10-10z"></path></g></svg>'
},
{
name: "Twitter",
key: "twitter",
preload: false,
disabled: false,
url: "https://twitter.com/search?q=%s",
matchSite: /^https?:\/\/twitter\.com\/search/i,
embeddable: true,
weight: 2,
lightness: 0.5254901960784314,
color: "#1da1f2",
icon: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em"><title>Twitter</title><path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/></svg>'
},
{
name: "Wolfram",
key: "wolfram",
preload: false,
disabled: false,
url: "https://www.wolframalpha.com/input?i=%s",
matchSite: /^https?:\/\/www\.wolframalpha\.com\/input/i,
embeddable: true,
weight: 4,
lightness: 0.5254901960784314,
color: "#e87242",
icon: '<svg height="1em" width="1em" viewBox="0 0 20 20"><path d="M15.33 10l2.17-2.47-3.19-.71.33-3.29-3 1.33L10 2 8.35 4.86l-3-1.33.32 3.29-3.17.71L4.67 10 2.5 12.47l3.19.71-.33 3.29 3-1.33L10 18l1.65-2.86 3 1.33-.32-3.29 3.19-.71zm-2.83 1.5h-5v-1h5zm0-2h-5v-1h5z" fill="currentColor"></path></svg>',
q: "i"
},
{
name: "Quora",
key: "quora",
url: "https://www.google.com/search?q=%s+site%3Aquora.com",
matchSite: (url2, query) => {
var _a, _b, _c;
return url2.includes("google.com") && ((_c = (_b = decodeURIComponent((_a = query.get("q")) != null ? _a : "")) == null ? void 0 : _b.includes) == null ? void 0 : _c.call(_b, "site:quora.com"));
},
q: (url2, query) => {
var _a, _b, _c;
return (_c = (_b = decodeURIComponent((_a = query.get("q")) != null ? _a : "")).replace) == null ? void 0 : _c.call(_b, "site:quora.com", "");
},
url_scheme: "",
preload: false,
embeddable: true,
weight: 3,
disabled: false,
lightness: 0.42549019607843136,
color: "#aa382f",
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" role="img" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><title></title><path d="M12.738 18.701c-.831-1.635-1.805-3.287-3.708-3.287-.362 0-.727.061-1.059.209l-.646-1.289c.786-.678 2.058-1.214 3.693-1.214 2.544 0 3.851 1.229 4.888 2.792.613-1.335.904-3.14.904-5.375 0-5.582-1.744-8.447-5.822-8.447-4.018 0-5.757 2.865-5.757 8.447 0 5.553 1.739 8.389 5.757 8.389.64 0 1.22-.069 1.75-.225zm.996 1.947c-.881.237-1.817.366-2.743.366-5.352 0-10.59-4.269-10.59-10.478C.402 4.271 5.639 0 10.991 0c5.441 0 10.628 4.238 10.628 10.537 0 3.504-1.635 6.351-4.01 8.191.764 1.148 1.543 1.914 2.652 1.914 1.199 0 1.68-.915 1.77-1.649h1.557c.092.974-.402 5.007-4.766 5.007-2.652 0-4.047-1.528-5.096-3.328l.008-.024z"></path></svg>'
},
{
name: "Bing",
key: "bing",
url: "https://www.bing.com/search?q=%s",
matchSite: "https://www.bing.com/search",
embeddable: false,
preload: false,
weight: -1,
disabled: false,
url_scheme: "",
lightness: 0.49,
color: "#174AE4",
background: "linear-gradient(90deg, #2870EA 10.79%, #1B4AEF 87.08%)",
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" role="img" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><title></title><path d="M20.176 15.406a6.48 6.48 0 01-1.736 4.414c1.338-1.47.803-3.869-1.003-4.635-.862-.305-2.488-.85-3.367-1.158a1.834 1.834 0 01-.932-.818c-.381-.975-1.163-2.968-1.548-3.948-.095-.285-.31-.625-.265-.938.046-.598.724-1.003 1.276-.754l3.682 1.888c.621.292 1.305.692 1.796 1.172a6.486 6.486 0 012.097 4.777zm-1.44 1.888c-.264-1.194-1.135-1.744-2.216-2.028-1.527.902-4.853 2.878-6.952 4.13-1.103.68-2.13 1.35-2.919 1.242a2.866 2.866 0 01-2.77-2.325c-.012-.048-.008-.03-.001.01a6.4 6.4 0 00.947 2.653 6.498 6.498 0 005.486 3.022c1.908.062 3.536-1.153 5.099-2.096.292-.188.804-.496 1.332-.831l1.423-1.51c.553-.577.764-1.426.571-2.267zm-12.04 2.97c.422 0 .822-.1 1.173-.29.355-.215.964-.579 1.7-1.018L9.57 4.502c0-.99-.497-1.864-1.257-2.382-.08-.059-2.91-1.901-2.99-1.956-.605-.432-1.523.045-1.5.797v14.887l.417 2.36a2.488 2.488 0 002.455 2.056z"></path></svg>'
},
{
name: "\u5FC5\u5E94\u8BCD\u5178",
key: "bingdict",
url: "https://cn.bing.com/dict/search?q=%s",
matchSite: "https://cn.bing.com/dict/search",
embeddable: false,
preload: false,
weight: -1,
disabled: false,
url_scheme: "",
lightness: 0.6,
color: "#09ABA0",
icon: '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" viewBox="0 0 192 192" stroke="currentColor" fill="currentColor" height="1em" width="1em"> <path fill="currentColor" opacity="1" stroke="none" d="M125.938271,139.999985C125.938263,148.148605 125.938263,155.797226 125.938263,164.023041C98.843987,158.680450 72.166801,153.420120 45.270416,148.116562C45.270416,114.459473 45.270416,81.037483 45.270416,46.967846C62.228786,43.506916 79.376663,40.007309 97.039154,36.402676C97.039154,44.197578 97.039154,51.320023 97.039154,58.639111C103.398552,60.409878 109.443642,62.093124 115.979416,63.913002C115.979416,53.301517 115.979416,43.060650 115.979416,32.408718C119.249802,31.582613 122.226326,30.830734 125.938278,29.893085C125.938278,66.716309 125.938278,103.108154 125.938271,139.999985M105.556885,95.417641C98.872597,92.803558 92.188316,90.189476 85.170311,87.444878C85.292763,94.447502 88.210686,98.464058 95.248993,100.227272C88.292999,103.790497 82.593506,106.710068 76.366074,109.900085C78.324829,106.175674 80.642792,103.612091 80.932571,100.836739C81.552238,94.901794 81.284760,88.849625 81.002586,82.863297C80.936310,81.457268 79.673637,79.629036 78.427383,78.856766C75.826019,77.244774 72.868401,76.207695 69.365799,74.621307C69.365799,85.588722 69.771385,95.726028 69.216400,105.810471C68.873695,112.037827 70.771362,116.146141 76.053902,119.338562C78.356873,120.730324 79.861282,121.227829 82.227722,119.691635C87.390663,116.340034 92.520729,112.793396 98.083679,110.240456C104.462219,107.313217 107.190498,103.095993 105.556885,95.417641z" /> <path fill="currentColor" opacity="1" stroke="none" d="M134.234467,141.672394C134.232941,109.270256 134.232941,77.336044 134.232941,45.155708C138.008377,45.155708 141.253082,45.155708 144.758194,45.155708C144.758194,78.362305 144.758194,111.410103 144.758194,145.347412C141.243271,143.067505 136.426208,148.442032 134.234467,141.672394z" /></svg>'
},
{
name: "Amazon",
key: "amazon",
preload: false,
disabled: false,
url: "https://www.amazon.com/s?k=%s",
matchSite: "amazon.com/s",
q: "k",
embeddable: true,
weight: 2,
lightness: 0.5,
color: "#FF9900",
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><g><path fill="none" d="M0 0h24v24H0z"></path><path d="M21.996 18.23c0 .727-.405 2.127-1.314 2.896-.182.14-.365.061-.285-.143.265-.648.872-2.147.587-2.492-.2-.262-1.03-.243-1.738-.182-.324.041-.607.06-.828.105-.203.017-.245-.163-.041-.303.262-.185.545-.325.87-.428 1.15-.344 2.48-.137 2.67.083.036.042.08.16.08.463zm-1.921 1.294a7.426 7.426 0 0 1-.83.55c-2.122 1.275-4.87 1.943-7.258 1.943-3.843 0-7.28-1.417-9.888-3.788-.223-.182-.038-.446.223-.303 2.81 1.64 6.288 2.632 9.889 2.632 2.265 0 4.708-.424 7.035-1.336.162-.061.344-.144.503-.202.367-.165.69.243.326.504zm-6.17-11.03c0-1.041.041-1.654-.304-2.18-.306-.433-.833-.693-1.568-.652-.798.044-1.655.567-1.874 1.526-.042.22-.171.436-.436.483l-2.436-.31c-.174-.04-.438-.173-.352-.521C7.458 4.088 9.81 3.129 12.033 3h.523c1.22 0 2.787.349 3.79 1.264 1.217 1.136 1.088 2.662 1.088 4.32v3.927c0 1.178.477 1.7.958 2.314.13.219.174.477-.045.655-.48.435-1.394 1.219-1.917 1.654-.174.133-.488.147-.61.045-.77-.645-.958-1.003-1.435-1.658-.83.871-1.526 1.352-2.355 1.613a7.035 7.035 0 0 1-1.784.216c-2.09 0-3.746-1.303-3.746-3.88 0-2.049 1.09-3.442 2.7-4.101 1.61-.66 3.95-.87 4.704-.874zm-.478 5.192c.52-.872.477-1.586.477-3.185-.651 0-1.306.045-1.871.178-1.045.303-1.874.961-1.874 2.355 0 1.09.567 1.832 1.525 1.832.132 0 .248-.016.349-.045.67-.186 1.088-.522 1.394-1.135z"></path></g></svg>'
},
{
name: "eBay",
key: "ebay",
url: "https://www.ebay.com/sch/i.html?_nkw=%s",
matchSite: "ebay.com/sch",
q: "_nkw",
preload: false,
embeddable: true,
weight: 2,
disabled: false,
lightness: 0.4862745098039215,
color: "#4164ea",
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" role="img" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><title></title><path d="M6.056 12.132v-4.92h1.2v3.026c.59-.703 1.402-.906 2.202-.906 1.34 0 2.828.904 2.828 2.855 0 .233-.015.457-.06.668.24-.953 1.274-1.305 2.896-1.344.51-.018 1.095-.018 1.56-.018v-.135c0-.885-.556-1.244-1.53-1.244-.72 0-1.245.3-1.305.81h-1.275c.136-1.29 1.5-1.62 2.686-1.62 1.064 0 1.995.27 2.415 1.02l-.436-.84h1.41l2.055 4.125 2.055-4.126H24l-3.72 7.305h-1.346l1.07-2.04-2.33-4.38c.13.255.2.555.2.93v2.46c0 .346.01.69.04 1.005H16.8a6.543 6.543 0 01-.046-.765c-.603.734-1.32.96-2.32.96-1.48 0-2.272-.78-2.272-1.695 0-.15.015-.284.037-.405-.3 1.246-1.36 2.086-2.767 2.086-.87 0-1.694-.315-2.2-.93 0 .24-.015.494-.04.734h-1.18c.02-.39.04-.855.04-1.245v-1.05h-4.83c.065 1.095.818 1.74 1.853 1.74.718 0 1.355-.3 1.568-.93h1.24c-.24 1.29-1.61 1.725-2.79 1.725C.95 15.009 0 13.822 0 12.232c0-1.754.982-2.91 3.116-2.91 1.688 0 2.93.886 2.94 2.806v.005zm9.137.183c-1.095.034-1.77.233-1.77.95 0 .465.36.97 1.305.97 1.26 0 1.935-.69 1.935-1.814v-.13c-.45 0-.99.006-1.484.022h.012zm-6.06 1.875c1.11 0 1.876-.806 1.876-2.02s-.768-2.02-1.893-2.02c-1.11 0-1.89.806-1.89 2.02s.765 2.02 1.875 2.02h.03zm-4.35-2.514c-.044-1.125-.854-1.546-1.725-1.546-.944 0-1.694.474-1.815 1.546z"></path></svg>'
},
{
name: "MDN",
key: "mdnwebdocs",
preload: false,
disabled: false,
url: "https://developer.mozilla.org/en-US/search?q=%s",
matchSite: "developer.mozilla.org/en-US/search",
embeddable: true,
weight: 1,
lightness: 0,
color: "#000000",
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" role="img" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><title></title><path d="M0 0v24h24V0zm10.564 4.969c.667-.047 1.001.066 1.59.242l.436.13.152.046.557.17c.365.099.748.105 1.115.017a2.033 2.033 0 011.48.174c.409.233.684.648.737 1.115.048.413.288.78.648.989.537.293 1.096.538 1.672.736.407.156.815.331 1.219.488.2.077.377.203.514.37a.87.87 0 01.197.49c.025.359.068.722.086 1.084h-.002c.028.5-.08.997-.317 1.439-.087.165-.183.321-.263.486a.616.616 0 01-.635.367.417.417 0 00-.277.09c-.246.161-.497.32-.75.471-.35.193-.77.216-1.141.06a5.36 5.36 0 00-1.908-.351 2.11 2.11 0 00-1.7.775 2.62 2.62 0 00-.38.77c-.223.55-.414 3.838-.414 4.676 0 0-3.161-.615-6.13-3.653l.774-2.03H5.4l1.754-1.856H4.14l1.752-1.858H3.029l3.188-3.383a7.349 7.349 0 013.549-1.95c.318-.055.576-.089.798-.104z"></path></svg>'
},
];
const styles = "";
const engines = allEngines.filter((e) => !e.disabled).sort((a, b) => b.weight - a.weight);
const hotkeys = engines.reduce((acc, engine, index) => {
const key = engine.key[0].toLowerCase();
acc[key] = acc[key] ? [...acc[key], index] : [index];
return acc;
}, {});
function Button({
icon,
color,
background,
name,
display,
lightness,
href,
index
}) {
const a = document.createElement("a");
a.style.setProperty("--color", color);
a.style.setProperty("--background", background != null ? background : color);
a.href = href;
if (!display) {
a.style.display = "none";
}
a.setAttribute("target", "_blank");
a.setAttribute("rel", "noopener noreferrer");
a.setAttribute("title", name);
a.setAttribute("aria-label", name);
a.setAttribute("data-index", index + "");
a.title = name;
a.classList.add("icon-button");
a.innerHTML = icon;
const text = document.createElement("span");
text.innerText = name;
if (lightness < 0.5) {
a.classList.add("dark-invert");
}
a.append(text);
return a;
}
const getCurrentEngineIndex = (url2, searchParams) => {
for (let i = engines.length - 1; i >= 0; i--) {
const e = engines[i];
if (e.matchSite instanceof RegExp) {
if (e.matchSite.test(url2)) {
return i;
}
} else if (typeof e.matchSite === "function") {
try {
if (e.matchSite(url2, searchParams)) {
return i;
}
} catch (e2) {
console.error(e2);
}
} else if (typeof e.matchSite === "string") {
if (url2.includes(e.matchSite)) {
return i;
}
}
}
return -1;
};
const getQuery = (engine, url2, searchParams) => {
if (typeof engine.q === "string") {
return searchParams.get(engine.q);
}
if (engine.q instanceof RegExp) {
const match = engine.q.exec(window.location.href);
if (match)
return match[1];
}
if (typeof engine.q === "function") {
try {
return engine.q(url2, searchParams);
} catch (e) {
console.error(e);
}
}
if (Array.isArray(engine.q)) {
for (let i = 0; i < engine.q.length; i++) {
const q = searchParams.get(engine.q[i]);
if (q)
return q;
}
}
return searchParams.get("q") || searchParams.get("query") || void 0;
};
const throttle = (callback, limit) => {
let waiting = false;
return (...args) => {
if (!waiting) {
callback.apply(null, args);
waiting = true;
setTimeout(() => {
waiting = false;
}, limit);
}
};
};
const url = window.location.href;
const params = new URLSearchParams(window.location.search);
const currEngineIndex = getCurrentEngineIndex(url, params);
if (currEngineIndex !== -1) {
const filtered = engines.filter((_, i) => i !== currEngineIndex);
const matchedEngine = engines[currEngineIndex];
let q = getQuery(matchedEngine, url, params);
if (q) {
q = encodeURIComponent(q.trim());
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.addEventListener(
"scroll",
throttle(() => {
const currentScrollPos = window.pageYOffset;
if (prevScrollPosition < currentScrollPos) {
root.style.bottom = "-48px";
} else {
root.style.bottom = "0";
}
prevScrollPosition = currentScrollPos;
}, 100),
true
);
const linkList = [];
for (let i = 0; i < filtered.length; i++) {
const engine = filtered[i];
const button = Button({
icon: engine.icon,
color: engine.color,
background: engine.background,
name: engine.name,
display: true,
lightness: engine.lightness,
href: engine.url.replaceAll("%s", q),
index: i
});
linkList.push(button);
linkContainer.appendChild(button);
}
root.appendChild(linkContainer);
const close = document.createElement("button");
close.innerHTML = `<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path fill="none" stroke="currentColor" stroke-width="2" d="M3,3 L21,21 M3,21 L21,3"></path></svg>`;
close.classList.add("icon-button");
close.id = "metasearch-close";
close.addEventListener("click", () => {
root.style.bottom = "-40px";
});
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: 32px;
background-color: rgba(255, 255, 255, 0.8);
-webkit-backdrop-filter: blur(8px);
backdrop-filter: blur(8px);
z-index: 999999999;
box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.07);
overflow-y: hidden;
}
#metasearch-root .icon-button {
all: unset;
box-sizing: border-box;
text-decoration: none;
color: var(--color);
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;
flex: 1 0 auto;
padding: 2px 5px;
min-width: 32px;
height: 100%;
}
#metasearch-root .icon-button > svg {
width: 20px;
height: 20px;
color: currentColor;
fill: currentColor;
stroke: currentColor;
}
@media screen and (max-width: 768px) {
#metasearch-root .icon-button > svg {
height: 24px;
width: 24px;
}
}
#metasearch-root .icon-button:hover {
filter: brightness(0.85);
background: 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.9);
color: white;
background: var(--background);
}
@media screen and (prefers-color-scheme: dark) {
#metasearch-root .icon-button:active.dark-invert {
filter: invert(1) hue-rotate(180deg) brightness(0.9);
}
}
#metasearch-root .icon-button:focus {
-webkit-tap-highlight-color: transparent;
color: white;
background: var(--background);
}
@media screen and (prefers-color-scheme: dark) {
#metasearch-root .icon-button:focus.dark-invert {
filter: invert(1) hue-rotate(180deg) brightness(0.7);
}
}
@media screen and (max-width: 768px) {
#metasearch-root .icon-button {
padding: 0;
min-width: 40px;
}
#metasearch-root .icon-button > span {
display: none;
}
}
@media screen and (max-width: 768px) {
#metasearch-root {
height: 40px;
}
}
@media screen and (prefers-color-scheme: dark) {
#metasearch-root {
background-color: rgba(25, 25, 25, 0.7);
color: rgba(255, 255, 255, 0.8);
}
#metasearch-root .dark-invert {
filter: invert(1) hue-rotate(180deg);
}
}
#metasearch-root #metasearch-close {
box-shadow: -1px 2px 9px rgba(0, 0, 0, 0.1);
}
#metasearch-root #metasearch-link-container {
scrollbar-width: none;
overflow-x: auto;
overflow-y: hidden;
width: 100%;
display: flex;
box-sizing: border-box;
}
#metasearch-root #metasearch-link-container::-webkit-scrollbar {
display: none;
}
body {
position: relative !important;
}`);
root.appendChild(close);
body.appendChild(root);
const getNextTabIndex = (currIndex = -1, key) => {
for (let i = currIndex + 1; i < filtered.length + currIndex; i++) {
const index = i % filtered.length;
if (filtered[index].key[0] === key.toLowerCase())
return index;
}
return currIndex;
};
const keydownListener = (e) => {
if (e.key === "Alt") {
root.style.bottom = "0";
}
const active = document.activeElement;
if (e.key === "Escape" || e.key === "Esc") {
if (root.contains(active)) {
e.preventDefault();
active.blur();
return;
}
}
const key = e.key.toLowerCase();
const focusIndex = linkContainer.contains(active) ? parseInt(active.getAttribute("data-index") || "-1", 10) : -1;
if (e.altKey && hotkeys[key] !== void 0) {
e.preventDefault();
const next = getNextTabIndex(focusIndex, key);
linkList[next].focus();
return;
}
const num = parseInt(e.key, 10);
if (e.altKey && !isNaN(num) && num < filtered.length) {
e.preventDefault();
const index = num - 1;
linkList[index].focus();
return;
}
if (e.altKey && (e.key === "[" || e.key === "-")) {
const prevIndex = focusIndex - 1 < 0 ? filtered.length - 1 : focusIndex - 1;
linkList[prevIndex].focus();
return;
}
if (e.altKey && (e.key === "]" || e.key === "=")) {
const nextIndex = (focusIndex + 1) % filtered.length;
linkList[nextIndex].focus();
return;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment