Search Switcher - SearXNG

Add links to each other in search engines. Including multiple search modes.

  1. // ==UserScript==
  2. // @name Search Switcher - SearXNG
  3. // @description Add links to each other in search engines. Including multiple search modes.
  4. // @license GPL-3.0
  5. // @include https://jrem.org/*
  6. // @include *.bing.com/*
  7. // @include *.duckduckgo.com/*
  8. // @include *duckduckgo.com/*
  9. // @include /^https?://[a-z]+\.google\.[a-z,\.]+/.+$/
  10. // @grant none
  11. // @run-at document_body
  12. // @version 1
  13. // @namespace https://gf.qytechs.cn/en/users/807108-jeremy-r
  14. // ==/UserScript==
  15.  
  16. {
  17. const sites = [
  18. {
  19. name: "SearXNG jrem.org",
  20. host: "jrem.org",
  21. link: "https://jrem.org/search",
  22. key: "q",
  23. hide: false,
  24. },
  25. {
  26. name: "Bing",
  27. host: "bing.com",
  28. link: "https://bing.com/search",
  29. key: "q",
  30. hide: false,
  31. },
  32. {
  33. name: "Google",
  34. host: "google.com",
  35. link: "https://www.google.com/search",
  36. key: "q",
  37. hide: false,
  38. },
  39. {
  40. name: "DuckDuckGo",
  41. host: "duckduckgo.com",
  42. link: "https://duckduckgo.com/",
  43. key: "q",
  44. hide: false,
  45. },
  46. ];
  47.  
  48. const css = `
  49. .search-warpper {
  50. position: fixed;
  51. left: 0;
  52. top: 0;
  53. }
  54.  
  55. .search-switcher {
  56. position: fixed;
  57. opacity: 0.2;
  58. top: 80px;
  59. right: calc(100% - 10px);
  60. z-index: 9999999;
  61. transition: all 400ms;
  62. }
  63.  
  64. .search-switcher:hover {
  65. top: 80px;
  66. left: 0px;
  67. right:auto;
  68. opacity: 1;
  69. border-radius: 0 20px;
  70. }
  71.  
  72. .search-switcher .search-list {
  73. display: flex;
  74. flex-direction: column;
  75. align-items: center;
  76. justify-content: center;
  77. box-sizing:border-box;
  78. background-color: #000;
  79. border-radius: 0px 10px 10px 0px;
  80. color: #fff;
  81. padding: 10px;
  82. box-shadow: 5px 5px 5px #777;
  83. }
  84.  
  85. .search-switcher .search-list a {
  86. color: #0cf;
  87. height: 25px;
  88. line-height: 25px;
  89. }
  90.  
  91. .search-switcher .search-list a.mirror {
  92. font-weight: bold;
  93. }
  94. `;
  95.  
  96. function setup() {
  97. console.log("location:", location.href);
  98. let curSite;
  99. let isMirror;
  100. for (let site of sites) {
  101. if (location.host.includes(site.host)) {
  102. curSite = site;
  103. }
  104. }
  105. let siteList = sites.filter(
  106. ({ host, hide }) => !location.hostname.includes(host) && !hide
  107. );
  108. console.log("siteList:", siteList);
  109. let query = new URLSearchParams(location.search).get(curSite.key || "q");
  110. console.log("site:", curSite, ",query:", query);
  111. if (query == null) {
  112. return;
  113. }
  114. let body = document.body;
  115. if (body == undefined) {
  116. return;
  117. }
  118. let switcherParentId = "search-switcher-parent";
  119. let switcherParent = document.getElementById(switcherParentId);
  120. if (switcherParent == undefined) {
  121. // 样式
  122. const style = document.createElement("style");
  123. style.innerHTML = css;
  124. body.appendChild(style);
  125. // 生成切换框
  126. switcherParent = document.createElement("div");
  127. switcherParent.setAttribute("id", switcherParentId);
  128. console.log("body.appendChild:", switcherParent);
  129. body.appendChild(switcherParent);
  130. }
  131. const siteTag = ({ link, name, host, mirror, key }) => {
  132. let className = "";
  133. let text = name;
  134. let href = `${link}?${key}=${query}`;
  135. console.log("href:", href);
  136. return `<a href='${href}' target='_blank' >${text}</a>`;
  137. };
  138. const tags = siteList
  139. .filter(({ hidden }) => !hidden)
  140. .map(siteTag)
  141. .join("");
  142.  
  143. switcherParent.innerHTML = `
  144. <div id='search-switcher' class='search-switcher'>
  145. <div id='search-list' class="search-list">${tags}</div>
  146. </div>
  147. `;
  148. console.log("switcherParent:", switcherParent);
  149. }
  150.  
  151. let _href = "";
  152. !(function init() {
  153. var current_href = location.href;
  154. if (_href != current_href) {
  155. setup();
  156. _href = current_href;
  157. }
  158. setTimeout(init, 2000);
  159. })();
  160. }
  161. // end userScript

QingJ © 2025

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