Greasy Fork

Greasy Fork is available in English.

聚合搜索引擎切换导航[手机版][移动端]

在搜索顶部显示一个聚合搜索引擎切换导航,模拟M浏览器的综合搜索引擎。专注手机网页搜索引擎切换,纯粹的搜索。SearchJump、搜索跳转、聚合搜索。

当前为 2023-03-21 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         聚合搜索引擎切换导航[手机版][移动端]
// @namespace    http://tampermonkey.net/
// @version      1.0.6
// @description  在搜索顶部显示一个聚合搜索引擎切换导航,模拟M浏览器的综合搜索引擎。专注手机网页搜索引擎切换,纯粹的搜索。SearchJump、搜索跳转、聚合搜索。
// @author       PunkJet
// @home-url     http://greasyfork.icu/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
// ==/UserScript==

const searchUrlMap = [
{
    name: "必应",
    searchUrl: "https://cn.bing.com/search?q=",
    searchkeyName: ["q"],
    matchUrl:"cn.bing.com",
    mark:"Bing",
},
{
    name: "百度",
    searchUrl: "https://baidu.com/s?wd=",
    searchkeyName: ["wd", "word"],
    matchUrl:"baidu.com",
    mark:"Baidu",
},
{
    name: "谷歌",
    searchUrl: "https://www.google.com/search?q=",
    searchkeyName: ["q"],
    matchUrl:"google.com",
    mark:"Google",
},
{
    name: "知乎",
    searchUrl: "https://www.zhihu.com/search?q=",
    searchkeyName: ["q"],
    matchUrl:"zhihu.com",
    mark:"Zhihu",
},
{
    name: "豆瓣",
    searchUrl: "https://m.douban.com/search/?query=",
    searchkeyName: ["query"],
    matchUrl:"m.douban.com",
    mark:"Douban",
},
{
    name: "夸克",
    searchUrl: "https://quark.sm.cn/s?q=",
    searchkeyName: ["q"],
    matchUrl:"quark.sm.cn",
    mark:"Quark",
},
{
    name: "搜狗",
    searchUrl: "https://m.sogou.com/web/searchList.jsp?keyword=",
    searchkeyName: ["keyword"],
    matchUrl:"m.sogou.com/web",
    mark:"Sougou",
},
{
  name: "Yandex",
  searchUrl: "https://yandex.com/search/touch/?text=",
  searchkeyName: ["text"],
  matchUrl:"yandex.com",
  mark:"Yandex",
},
{
    name: "DuckDuckGo",
    searchUrl: "https://duckduckgo.com/?q=",
    searchkeyName: ["q"],
    matchUrl:"duckduckgo.com",
    mark:"DuckDuckGo",
  }

];

const deafultMark = "Bing-Baidu-Google-Zhihu-Douban-Yandex-Quark-Sougou-DuckDuckGo";

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渲染次数
  
    let showList = GM_getValue("setup_search").split('-');
    for (let showListIndex in showList) {
        for (let index in searchUrlMap) {
            let item = searchUrlMap[index];
            if (item.mark == showList[showListIndex]) {
                let liItem = document.createElement('li');
                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);
                break;
            }
        }
    }
    ulList.appendChild(fragment);

    const setBoxDiv = document.createElement("div");
    setBoxDiv.id = "search-setting-box";
    setBoxDiv.innerHTML = `<span id="btnSet"><svg width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M34.0003 41L44 24L34.0003 7H14.0002L4 24L14.0002 41H34.0003Z" fill="none" stroke="#444444" stroke-width="4" stroke-linejoin="round"/><path d="M24 29C26.7614 29 29 26.7614 29 24C29 21.2386 26.7614 19 24 19C21.2386 19 19 21.2386 19 24C19 26.7614 21.2386 29 24 29Z" fill="none" stroke="#444444" stroke-width="4" stroke-linejoin="round"/></svg></span>`;
    searchBox.appendChild(setBoxDiv);

    const closeBoxDiv = document.createElement("div");
    closeBoxDiv.id = "search-close-box";
    closeBoxDiv.innerHTML = `<span id="btnClose"><svg width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M24 44C35.0457 44 44 35.0457 44 24C44 12.9543 35.0457 4 24 4C12.9543 4 4 12.9543 4 24C4 35.0457 12.9543 44 24 44Z" fill="none" stroke="#444444" stroke-width="4" stroke-linejoin="round"/><path d="M29.6567 18.3432L18.343 29.6569" stroke="#444444" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M18.3433 18.3432L29.657 29.6569" stroke="#444444" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg></span>`;
    searchBox.appendChild(closeBoxDiv);

    document.getElementsByTagName('head')[0].after(searchBox);

  
    let btnSet = document.querySelector("#btnSet");
    btnSet.onclick = function () {
        let sss = prompt("输入需要显示的搜索引擎。格式:" + deafultMark);
        if (sss) {
            GM_setValue("setup_search", sss);
        }
        //alert("用户设置" + GM_getValue("setup_search"));
    }

    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 30px;
      text-align: center;
      margin: auto;
    }
    #search-close-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;*/
      color: #666666 !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;
    }

  `
    if (!GM_getValue("setup_search")) {
        GM_setValue("setup_search", deafultMark);
    }
    GM_addStyle(css);
    addSearchBox();

})();