Greasy Fork

Greasy Fork is available in English.

聚合搜索 V5

整合Google、Bing、DuckDuckGo、百度、Brave、F搜、微信、知乎、知网空间搜索,提高搜索效率。在原作者基础上自行修改了部分内容,原作者链接:http://greasyfork.icu/zh-CN/scripts/440235

当前为 2022-06-15 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         聚合搜索 V5
// @namespace    http://tampermonkey.net/
// @version      0.1.12
// @description  整合Google、Bing、DuckDuckGo、百度、Brave、F搜、微信、知乎、知网空间搜索,提高搜索效率。在原作者基础上自行修改了部分内容,原作者链接:http://greasyfork.icu/zh-CN/scripts/440235
// @author       Jony Xiao
 
// @match        *://www.baidu.com/s*
// @match        *://www.baidu.com/baidu*
// @match        *://www.duckduckgo.com/*
// @match        *://search.brave.com/search*
// @match        *://fsoufsou.com/search*
// @match        *://www.google.com/search*
// @match        *://www.google.com.hk/search*
// @match        *://weixin.sogou.com/weixin*
// @match        *://www.bing.com/search*
// @match        *://cn.bing.com/search*
// @match        *://www.zhihu.com/search*
// @match        *://search.cnki.com.cn/Search/Result*
 
// @grant        unsafeWindow
// @grant        window.onload
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at       document-body
 
// @license     MIT
// ==/UserScript==
 
// 搜索网址配置
const urlMapping = [
  {
    name: "Google",
    searchUrl: "https://www.google.com/search?q=",
    keyName: "q",
    testUrl: /https:\/\/www.google.com\/search.*/,
  },
  {
    name: "DuckDuckGo",
    searchUrl: "https://www.duckduckgo.com/?q=",
    keyName: "q",
    testUrl: /https:\/\/www.duckduckgo.com\/q.*/,
  },
  {
    name: "Bing",
    searchUrl: "https://cn.bing.com/search?q=",
    keyName: "q",
    testUrl: /https:\/\/cn.bing.com\/search.*/,
  },
  {
    name: "Brave",
    searchUrl: "https://search.brave.com/search?q=",
    keyName: "q",
    testUrl: /https:\/\/search.brave.com\/search.*/,
  },
  {
    name: "百度",
    searchUrl: "https://www.baidu.com/s?wd=",
    keyName: "wd",
    testUrl: /https:\/\/www.baidu.com\/s.*/,
  },
  {
    name: "F搜",
    searchUrl: "https://fsoufsou.com/search?q=",
    keyName: "q",
    testUrl: /https:\/\/fsoufsou.com\/search.*/,
  },
  {
    name: "微信文章",
    searchUrl: "https://weixin.sogou.com/weixin?type=2&s_from=input&query=",
    keyName: "query",
    testUrl: /https:\/\/weixin.sogou.com\/weixin.*/,
  },
  {
    name: "知乎",
    searchUrl: "https://www.zhihu.com/search?type=content&q=",
    keyName: "q",
    testUrl: /https:\/\/www.google.com.hk\/search.*/,
  },
  {
    name: "知网空间",
    searchUrl: "https://search.cnki.com.cn/Search/Result?content=",
    keyName: "q",
    testUrl: /https:\/\/fsou.cc\/search.*/,
  },
];
 
// 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;
}
 
// 从url中获取搜索关键词
function getKeywords() {
  let keywords = "";
  for (let item of urlMapping) {
    if (item.testUrl.test(window.location.href)) {
      keywords = getQueryVariable(item.keyName);
      break;
    }
  }
  console.log(keywords);
  return keywords;
}
 
// 域名
const hostname = window.location.hostname;
 
let isBlank = GM_getValue("isBlank");
 
console.log("新标签页打开?", isBlank);
if (isBlank === undefined) {
  GM_setValue("isBlank", false);
  isBlank = false;
}
 
// 改变打开搜索引擎的方式
const engine = document.getElementsByClassName("search-engine-a");
function triggerAttribute(value) {
  for (const item of engine) {
    item.target = value;
  }
}
 
// 适配火狐浏览器的百度搜索
const isFirefox = () => {
  if (navigator.userAgent.indexOf("Firefox") > 0) {
    console.warn("[ Firefox ] 🚀");
    urlMapping[0].searchUrl = "https://www.baidu.com/baidu?wd=";
    urlMapping[0].testUrl = /https:\/\/www.baidu.com\/baidu.*/;
  } else {
    return;
  }
};
 
// 适配cn.bing.com的必应域名
const cnBing = {
    name: "Bing",
    searchUrl: "https://cn.bing.com/search?q=",
    keyName: "q",
    testUrl: /https:\/\/cn.bing.com\/search.*/,
};

// 匹配到cn.bing就修改必应配置对象
if(window.location.hostname === 'cn.bing.com'){
  for(let item of urlMapping){
    if(item.name === "Bing"){
      item = cnBing
    }
  }
}
 
 
// 添加节点
function addBox() {
  isFirefox();
  // 主元素
  const div = document.createElement("div");
  div.id = "search-app-box";
  div.style =
    "position: fixed; top: 148px; left: 8px; width: 88px; background-color: rgba(230, 230, 240, 0.5); font-size: 12px; z-index: 99999;";
  document.body.insertAdjacentElement("afterBegin", div);
 
  // 标题
  let title = document.createElement("span");
  title.innerText = "聚合搜索";
  title.style = `
    display: block;
    text-align: center;
    margin-top: 10px; 
    margin-bottom: 5px;
    font-size: 12px;
    font-weight: bold;
    -webkit-user-select:none;
    -moz-user-select:none;
    -ms-user-select:none;
    user-select:none;`;
 
  title.style.textDecoration = isBlank ? "underline" : "";
  title.ondblclick = () => {
    title.style.textDecoration = !isBlank ? "underline" : "";
    GM_setValue("isBlank", !isBlank);
    isBlank = !isBlank;
    triggerAttribute(isBlank ? "_blank" : "");
  };
  div.appendChild(title);
 
  // 搜索列表
  for (let index in urlMapping) {
    let item = urlMapping[index];
 
    // 样式
    let style =
      "display: block; padding: 10px 0 10px 10px; text-decoration: none;";
    let defaultStyle = style + "color: #333333 !important;";
    let hoverStyle =
      style + "color: #ffffff !important; background-color: #555555;";
 
    let a = document.createElement("a");
    a.innerText = item.name;
    a.style = defaultStyle;
    a.className = "search-engine-a";
    a.href = item.searchUrl + getKeywords();
    if (!item.searchUrl.includes(hostname) && isBlank) {
      a.target = "_blanck";
    }
 
    // 鼠标移入移除效果,相当于hover
    a.onmouseenter = function () {
      this.style = hoverStyle;
    };
    a.onmouseleave = function () {
      this.style = defaultStyle;
    };
    div.appendChild(a);
  }
}
 
(function () {
  "use strict";
  window.onload = addBox();
})();