聚合搜索

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

  1. // ==UserScript==
  2. // @name 聚合搜索
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.1
  5. // @description 整合百度、Google、微信、Bing、知乎、知网空间搜索,提高搜索效率。在原作者基础上自行修改了部分内容,原作者链接:https://gf.qytechs.cn/zh-CN/scripts/436613-聚合搜索。原原作者链接:https://gf.qytechs.cn/zh-CN/scripts/401457-聚合搜索
  6. // @author Peng Shiyu, 海洋空氣
  7. // @website https://www.pengshiyu.com/
  8.  
  9. // @match *://www.baidu.com/s*
  10. // @match *://www.google.com/search*
  11. // @match *://weixin.sogou.com/weixin*
  12. // @match *://www.bing.com/search*
  13. // @match *://www.zhihu.com/search*
  14. // @match *://search.cnki.com.cn/Search/Result*
  15.  
  16. // @grant unsafeWindow
  17. // @grant window.onload
  18. // @run-at document-end
  19.  
  20. // @license MIT
  21. // ==/UserScript==
  22.  
  23. // @require file:///Users/hina/workspace/www.farthe.com/code/chrome/search/index.js
  24.  
  25.  
  26. // 搜索网址配置
  27. const urlMapping = [{
  28. name: '百度',
  29. searchUrl: 'https://www.baidu.com/s?wd=',
  30. keyName: 'wd',
  31. testUrl: /https:\/\/www.baidu.com\/s.*/,
  32. },
  33. {
  34. name: 'Google',
  35. searchUrl: 'https://www.google.com/search?q=',
  36. keyName: 'q',
  37. testUrl: /https:\/\/www.google.com\/search.*/,
  38. },
  39. {
  40. name: '微信文章',
  41. searchUrl: 'https://weixin.sogou.com/weixin?type=2&s_from=input&query=',
  42. keyName: 'query',
  43. testUrl: /https:\/\/www.baidu.com\/s.*/,
  44. },
  45. {
  46. name: 'Bing',
  47. searchUrl: 'https://www.bing.com/search?ensearch=0&q=',
  48. keyName: 'q',
  49. testUrl: /https:\/\/www.bing.com\/search.*/,
  50. },
  51. {
  52. name: '知乎',
  53. searchUrl: 'https://www.zhihu.com/search?type=content&q=',
  54. keyName: 'q',
  55. testUrl: /https:\/\/www.google.com.hk\/search.*/,
  56. },
  57. {
  58. name: '知网空间',
  59. searchUrl: 'https://search.cnki.com.cn/Search/Result?content=',
  60. keyName: 'q',
  61. testUrl: /https:\/\/fsou.cc\/search.*/,
  62. }
  63. ];
  64.  
  65. // JS获取url参数
  66. function getQueryVariable(variable) {
  67. let query = window.location.search.substring(1);
  68. let pairs = query.split("&");
  69. for (let pair of pairs) {
  70. let [key, value] = pair.split("=");
  71. if (key == variable) {
  72. return decodeURIComponent(value);
  73. }
  74. }
  75. return null;
  76. };
  77.  
  78. // 从url中获取搜索关键词
  79. function getKeywords() {
  80. let keywords = '';
  81.  
  82. for (let item of urlMapping) {
  83. if (item.testUrl.test(window.location.href)) {
  84. keywords = getQueryVariable(item.keyName);
  85. break
  86. }
  87. }
  88.  
  89. console.log(keywords);
  90. return keywords;
  91. };
  92.  
  93. // 添加节点
  94. function addBox() {
  95. // 主元素
  96. var div = document.createElement('div')
  97. div.id = 'search-app-box'
  98. div.style = "position: fixed; top: 160px; left: 20px; width: 100px; background-color: #EEEEEE; font-size: 12px;z-index: 99999;"
  99. // document.body.appendChild(div)
  100. document.body.insertAdjacentElement("afterBegin", div);
  101.  
  102. // 标题
  103. let title = document.createElement('span')
  104. title.innerText = "聚合搜索"
  105. title.style = "display: block; text-align: center; margin-top: 10px; font-size: 14px; font-weight: bold;"
  106. div.appendChild(title)
  107.  
  108. // 搜索列表
  109. for (let index in urlMapping) {
  110.  
  111. let item = urlMapping[index];
  112.  
  113. // 样式
  114. let style = "display: block; padding: 10px 0 10px 20px; text-decoration: none;";
  115. let defaultStyle = style + "color: #333333 !important;";
  116. let hoverStyle = style + "color: #ffffff !important; background-color: #666666;";
  117.  
  118. let a = document.createElement('a')
  119. a.innerText = item.name
  120. a.style = defaultStyle
  121. a.id = index
  122. a.href = item.searchUrl + getKeywords()
  123.  
  124. // 鼠标移入移除效果,相当于hover
  125. a.onmouseenter = function () {
  126. this.style = hoverStyle
  127. }
  128. a.onmouseleave = function () {
  129. this.style = defaultStyle
  130. }
  131.  
  132. div.appendChild(a)
  133. }
  134. };
  135.  
  136. (function () {
  137. 'use strict';
  138. window.onload = addBox;
  139. })();

QingJ © 2025

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