聚合搜索V4

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

目前为 2022-04-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         聚合搜索V4
// @namespace    http://tampermonkey.net/
// @version      0.1.6
// @description  整合百度、F搜、Google、微信、Bing、知乎、知网空间搜索,提高搜索效率。在原作者基础上自行修改了部分内容,原作者链接:https://gf.qytechs.cn/zh-CN/scripts/436652
// @author       Liao Brant

// @match        *://www.baidu.com/s*
// @match        *://www.baidu.com/baidu*
// @match        *://fsoufsou.com/search*
// @match        *://www.google.com/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==

// @require      https://gf.qytechs.cn/zh-CN/scripts/436652

// 搜索网址配置
const urlMapping = [
  {
    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: "Google",
    searchUrl: "https://www.google.com/search?q=",
    keyName: "q",
    testUrl: /https:\/\/www.google.com\/search.*/,
  },
  {
    name: "微信文章",
    searchUrl: "https://weixin.sogou.com/weixin?type=2&s_from=input&query=",
    keyName: "query",
    testUrl: /https:\/\/weixin.sogou.com\/weixin.*/,
  },
  {
    name: "Bing",
    searchUrl: "https://www.bing.com/search?ensearch=0&q=",
    keyName: "q",
    testUrl: /https:\/\/www.bing.com\/search.*/,
  },
  {
    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: 160px; left: 20px; width: 100px; background-color: #EEEEEE; 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: 14px;
    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 20px; text-decoration: none;";
    let defaultStyle = style + "color: #333333 !important;";
    let hoverStyle =
      style + "color: #ffffff !important; background-color: #666666;";

    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();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址