聚合搜索

整合大部分网页搜索,提高搜索效率。在原作者基础上自行修改了部分内容,原作者链接:https://gf.qytechs.cn/zh-CN/scripts/401457-聚合搜索

  1. // ==UserScript==
  2. // @name 聚合搜索
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.4
  5. // @description 整合大部分网页搜索,提高搜索效率。在原作者基础上自行修改了部分内容,原作者链接: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 *://*.bing.com/search*
  11. // @match *://www.google.com.hk/search*
  12. // @match *://www.google.com/search*
  13.  
  14. // @grant window.onurlchange
  15. // @run-at document-end
  16.  
  17. // @license MIT
  18. // ==/UserScript==
  19.  
  20. // 针对百度不重载网页
  21. if (window.onurlchange === null) {
  22. window.addEventListener('urlchange', OnURLChange)
  23. }
  24.  
  25. // 搜索网址配置
  26. const urlMapping = [{
  27. name: '百度',
  28. searchUrl: 'https://www.baidu.com/s?wd=',
  29. keyName: 'wd',
  30. testUrl: /https:\/\/www.baidu.com\/s.*/,
  31. },
  32. {
  33. name: '必应国内版',
  34. searchUrl: 'https://www.bing.com/search?ensearch=0&q=',
  35. keyName: 'q',
  36. testUrl: /https:\/\/www.bing.com\/search.*/,
  37. },
  38. {
  39. name: '必应国际版',
  40. searchUrl: 'https://www.bing.com/search?ensearch=1&q=',
  41. keyName: 'q',
  42. testUrl: /https:\/\/www.bing.com\/search.*/,
  43. },
  44. {
  45. name: 'Google',
  46. searchUrl: 'https://www.google.com/search?q=',
  47. keyName: 'q',
  48. testUrl: /https:\/\/www.google.com\/search.*/,
  49. },
  50. {
  51. name: 'Google.hk',
  52. searchUrl: 'https://www.google.com.hk/search?q=',
  53. keyName: 'q',
  54. testUrl: /https:\/\/www.google.com.hk\/search.*/,
  55. }
  56. ];
  57.  
  58. // JS 获取 url 参数
  59. function getQueryVariable(variable) {
  60. let query = window.location.search.substring(1);
  61. let pairs = query.split("&");
  62. for (let pair of pairs) {
  63. let [key, value] = pair.split("=");
  64. if (key == variable) {
  65. return decodeURIComponent(value);
  66. }
  67. }
  68. return null;
  69. };
  70.  
  71. // 从 url 中获取搜索关键词
  72. function getKeywords() {
  73. let keywords = '';
  74.  
  75. for (let item of urlMapping) {
  76. if (item.testUrl.test(window.location.href)) {
  77. keywords = getQueryVariable(item.keyName);
  78. break
  79. }
  80. }
  81. return keywords;
  82. };
  83.  
  84. // 添加节点
  85. function addBox() {
  86. // 主元素
  87. var div = document.createElement('div');
  88. div.id = 'search-app-box';
  89. div.style = "position: fixed; top: 160px; left: 20px; width: 100px; background-color: #EEEEEE; font-size: 12px;z-index: 99999;";
  90. // document.body.appendChild(div);
  91. document.body.insertAdjacentElement("afterBegin", div);
  92.  
  93. // 标题
  94. let title = document.createElement('span');
  95. title.innerText = "聚合搜索";
  96. title.style = "display: block; text-align: center; margin-top: 10px; font-size: 14px; font-weight: bold;";
  97. div.appendChild(title);
  98.  
  99. // 搜索列表
  100. for (let index in urlMapping) {
  101.  
  102. let item = urlMapping[index];
  103.  
  104. // 样式
  105. let style = "display: block; padding: 10px 0 10px 20px; text-decoration: none;";
  106. let defaultStyle = style + "color: #333333 !important;";
  107. let hoverStyle = style + "color: #ffffff !important; background-color: #666666;";
  108.  
  109. let a = document.createElement('a');
  110. a.innerText = item.name;
  111. a.style = defaultStyle;
  112. a.id = index;
  113. a.href = item.searchUrl + getKeywords();
  114.  
  115. // 鼠标移入移除效果,相当于 hover
  116. a.onmouseenter = function () {
  117. this.style = hoverStyle;
  118. }
  119. a.onmouseleave = function () {
  120. this.style = defaultStyle;
  121. }
  122.  
  123. div.appendChild(a);
  124. }
  125. };
  126.  
  127. function OnURLChange() {
  128. // 删除原菜单,重新添加
  129. document.getElementById('search-app-box').remove();
  130. addBox();
  131. }
  132.  
  133. (function () {
  134. 'use strict';
  135. window.onload = addBox;
  136. })();

QingJ © 2025

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