Greasy Fork

Greasy Fork is available in English.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         聚合搜索引擎切换导航[手机版][移动端]
// @namespace    http://tampermonkey.net/
// @version      1.0.4
// @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",
    },
    {
      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 = `<a id="btnClose">X</a>`;
    setBoxDiv.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="#abcbe1" stroke-width="4" stroke-linejoin="round"/><path d="M29.6567 18.3432L18.343 29.6569" stroke="#abcbe1" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M18.3433 18.3432L29.657 29.6569" stroke="#abcbe1" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>
        </span>`;
    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();
   
})();