Greasy Fork

Greasy Fork is available in English.

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

在搜索顶部显示一个聚合搜索引擎切换,模拟M浏览器和嗅觉浏览器的综合搜索引擎。专注手机网页搜索引擎切换,纯粹的搜索,但又有自用倾向。SearchJump、搜索跳转。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         聚合搜索引擎切换导航[手机版][移动端]
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @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",
    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; // window.location.href
  const url = new URL(url_string);
  return url.searchParams.get(name);
}

// JS获取url参数
function getQueryVariable(variable) {
  let query = window.location.search.substring(1);
  let pairs = query.split("&");
  for (let pair of pairs) {
    let [key, value] = pair.split("=");
    if (key == variable) {
      return decodeURIComponent(value);
    }
  }
  return null;
}


function getKeywords() {
  let keywords = "";
  const curUrl = window.location.href;
  for (let item of searchUrlMap) {
    //alert(item.matchUrl + "内容" + curUrl);
    if(curUrl.indexOf(item.matchUrl) >= 0 )
    {
        keywords = getSearchKeywords(item.searchkeyName);
        if (keywords === null)
        {

            if (item.name === "百度")
            {
                keywords = getSearchKeywords("word");
                break;
            }
        }
        break;
    }
  }
  //alert(keywords);
  return keywords;
}


function addSearchBox() {
  const boxDiv = document.createElement("div");
  boxDiv.id = "search-app-box";

  var ulList = document.createElement('ul');
  boxDiv.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);
  document.getElementsByTagName('head')[0].after(boxDiv);

}

(function () {
  "use strict";

  const css =
    `
    #search-app-box {
      opacity:1 !important;
      position: fixed;
      display:flex;
      top: 0px;
      left: 0px;
      width: 100%;
      /*padding-left:4px;*/
      background-color: #FFFFFF !important;
      font-size: 15px;
      border-radius: 1px;
      z-index: 99999;
    }

    #search-app-box ul {
      list-style-type: none;
      margin: 0;
      padding: 0;
      overflow: hidden;
      /* background-color: #333;*/
      overflow-x: auto;
      list-style: none;
      white-space:nowrap;
    }

    #search-app-box ul::-webkit-scrollbar {
      display: none !important;
    }

    #search-app-box li {
      /*float: left;*/
      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:"-apple-system",HelveticaNeue,Roboto,Arial,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();

})();