Search Engine Switcher (Jerry Modified)

More transparent and working better on both dark and light mode; added stackoverflow, devdocs etc; modified from https://gf.qytechs.cn/en/scripts/446492

  1. // ==UserScript==
  2. // @name Search Engine Switcher (Jerry Modified)
  3. // @namespace https://gf.qytechs.cn/en/users/28298
  4. // @version 0.1.36
  5. // @description More transparent and working better on both dark and light mode; added stackoverflow, devdocs etc; modified from https://gf.qytechs.cn/en/scripts/446492
  6. // @homepage https://gf.qytechs.cn/en/scripts/456231
  7. // @author https://gf.qytechs.cn/en/users/28298
  8.  
  9. // @match *://www.baidu.com/s*
  10. // @match *://www.baidu.com/baidu*
  11. // @match *://duckduckgo.com/*
  12. // @match *://www.google.com/search*
  13. // @match *://www.google.com.hk/search*
  14. // @match *://scholar.google.com/*
  15. // @match *://translate.google.com/*
  16. // // @match *://www.youtube.com/*
  17. // // @match *://www.google.com/maps*
  18. // @match *://weixin.sogou.com/weixin*
  19. // @match *://www.bing.com/search*
  20. // @match *://cn.bing.com/search*
  21. // @match *://www.zhihu.com/search*
  22. // @match *://devdocs.io/*
  23. // @match *://stackoverflow.com/*
  24. // @match *://search.luxirty.com/*
  25.  
  26. // @grant unsafeWindow
  27. // @grant window.onload
  28. // @grant GM_getValue
  29. // @grant GM_setValue
  30. // @run-at document-body
  31.  
  32. // @license MIT
  33. // ==/UserScript==
  34.  
  35.  
  36.  
  37.  
  38. // modified from https://gf.qytechs.cn/en/scripts/446492
  39. // 搜索网址配置 (* not show, i.e., 1 way)
  40. const urlMapping = [
  41. {
  42. name: "Google",
  43. searchUrl: "https://www.google.com/search?q=",
  44. keyName: "q",
  45. testUrl: /https:\/\/www.google.com\/search.*/,
  46. },
  47. {
  48. name: "GImages",
  49. searchUrl: "https://www.google.com/search?tbm=isch&q=",
  50. keyName: "q",
  51. testUrl: /https:\/\/www.google.com\/search.*/,
  52. },
  53. {
  54. name: "Youtube",
  55. searchUrl: "https://www.youtube.com/results?search_query=",
  56. keyName: "search_query",
  57. testUrl: /https:\/\/www.youtube.com\/results.*/,
  58. },
  59. {
  60. name: "GScholars",
  61. searchUrl: "https://scholar.google.com/scholar?hl=en&as_sdt=0%2C14&oq=&q=",
  62. keyName: "q",
  63. testUrl: /https:\/\/scholar.google.com\/scholar.*/,
  64. },
  65. {
  66. name: "GMaps",
  67. searchUrl: "https://maps.google.com/maps?q=",
  68. keyName: "q",
  69. testUrl: /https:\/\/maps.google.com\/maps.*/,
  70. },
  71. // {
  72. // name: "GTranslate",
  73. // searchUrl: "https://translate.google.com/?sl=auto&tl=en&op=translate&text=",
  74. // keyName: "text",
  75. // testUrl: /https:\/\/translate.google.com\/*/,
  76. // },
  77. {
  78. name: "Luxirty",
  79. searchUrl: "https://search.luxirty.com/search?q=",
  80. keyName: "text",
  81. testUrl: /https:\/\/search.luxirty.com\/search.*/,
  82. },
  83. {
  84. name: "DuckDuckGo",
  85. searchUrl: "https://duckduckgo.com/?q=",
  86. keyName: "q",
  87. testUrl: /https:\/\/duckduckgo.com\/*/,
  88. },
  89. {
  90. name: "Bing",
  91. searchUrl: "https://www.bing.com/search?q=",
  92. keyName: "q",
  93. testUrl: /https:\/\/www.bing.com\/search.*/,
  94. },
  95. {
  96. name: "Baidu",
  97. searchUrl: "https://www.baidu.com/s?wd=",
  98. keyName: "wd",
  99. testUrl: /https:\/\/www.baidu.com\/s.*/,
  100. },
  101. {
  102. name: "Wechat",
  103. searchUrl: "https://weixin.sogou.com/weixin?type=2&s_from=input&query=",
  104. keyName: "query",
  105. testUrl: /https:\/\/weixin.sogou.com\/weixin.*/,
  106. },
  107. {
  108. name: "Zhihu",
  109. searchUrl: "https://www.zhihu.com/search?q=",
  110. keyName: "q",
  111. testUrl: /https:\/\/www.zhihu.com\/search.*/,
  112. },
  113. {
  114. name: "StackOverflow",
  115. searchUrl: "https://stackoverflow.com/search?q=",
  116. keyName: "q",
  117. testUrl: /https:\/\/stackoverflow.com\/search.*/,
  118. },
  119. {
  120. name: "DevDocs",
  121. searchUrl: "https://devdocs.io/#q=",
  122. keyName: "q",
  123. testUrl: /https:\/\/devdocs.io\/*/,
  124. },
  125. ];
  126.  
  127. // JS获取url参数
  128. function getQueryVariable(variable) {
  129. let query = window.location.search.substring(1);
  130. let pairs = query.split("&");
  131. for (let pair of pairs) {
  132. let [key, value] = pair.split("=");
  133. if (key == variable) {
  134. return decodeURIComponent(value);
  135. }
  136. }
  137. return null;
  138. }
  139.  
  140. // 从url中获取搜索关键词
  141. function getKeywords() {
  142. let keywords = "";
  143. for (let item of urlMapping) {
  144. if (window.location.href.startsWith("https://www.google.com/maps")) {
  145. // jerry: fix google maps
  146. keywords = decodeURIComponent(window.location.href.split('/')[5]);
  147. break;
  148. } else if (window.location.href.startsWith("https://devdocs.io")) {
  149. // jerry: fix
  150. let myarray = window.location.href.split('/');
  151. keywords = decodeURIComponent(myarray[myarray.length-1]);
  152. break;
  153. } else if (window.location.href.startsWith("https://search.luxirty.com")) {
  154. // jerry: fix
  155. keywords = decodeURIComponent(window.location.href.split('/')[3].split('q=')[1].split('#')[0]);
  156. break;
  157. } else {
  158. if (item.testUrl.test(window.location.href)) {
  159. keywords = getQueryVariable(item.keyName);
  160. break;
  161. }
  162. }
  163. }
  164. console.log(keywords);
  165. return keywords;
  166. }
  167.  
  168. // 适配火狐浏览器的百度搜索
  169. const isFirefox = () => {
  170. if (navigator.userAgent.indexOf("Firefox") > 0) {
  171. console.warn("[ Firefox ] 🚀");
  172. for (var i = 0; i < urlMapping.length; i++) {
  173. if (urlMapping[i]['name']=='Baidu') {
  174. break;
  175. }
  176. }
  177. urlMapping[i].searchUrl = "https://www.baidu.com/baidu?wd=";
  178. urlMapping[i].testUrl = /https:\/\/www.baidu.com\/baidu.*/;
  179. } else {
  180. return;
  181. }
  182. };
  183.  
  184. // 适配cn.bing.com的必应域名
  185. const cnBing = {
  186. name: "Bing",
  187. searchUrl: "https://cn.bing.com/search?q=",
  188. keyName: "q",
  189. testUrl: /https:\/\/cn.bing.com\/search.*/,
  190. };
  191.  
  192. // 匹配到cn.bing就修改必应配置对象
  193. if(window.location.hostname === 'cn.bing.com'){
  194. for(let item of urlMapping){
  195. if(item.name === "Bing"){
  196. item = cnBing
  197. }
  198. }
  199. }
  200.  
  201. // 添加节点
  202. function addBox() {
  203. isFirefox();
  204. // 主元素
  205. // original: background-color: hsla(200, 40%, 96%, .8);
  206. // word-break: normal; !important; for sogou
  207. const div = document.createElement("div");
  208. div.id = "search-app-box";
  209. var divstyle = `
  210. position: relative;
  211. display: flex;
  212. width: 100px;
  213. margin-bottom: 0px;
  214. word-break: normal;
  215. font-size: 13px;
  216. z-index: 99999;`;
  217. // console.log(divstyle)
  218. if (location.hostname=="duckduckgo.com") {
  219. divstyle += "top: 115px; left: 150px;";
  220. } else if (location.hostname=="www.bing.com") {
  221. divstyle += "top: 130px; left: 165px;";
  222. } else if (location.hostname=="www.google.com") {
  223. divstyle += "top: 150px; left: 210px;";
  224. } else if (location.hostname=="search.luxirty.com") {
  225. divstyle += "top: -840px; left: 210px;";
  226. } else {
  227. divstyle += "top: 1px; left: 150px;";
  228. }
  229. // console.log(divstyle)
  230. div.style = divstyle;
  231. document.body.insertAdjacentElement("afterbegin", div);
  232.  
  233. // 搜索列表
  234. for (let index in urlMapping) {
  235. let item = urlMapping[index];
  236.  
  237. // 列表样式
  238. let style = `
  239. font-weight: bold;
  240. color: #FFFFFF; background-color: #b60002; box-shadow:0 2px 5px 0 #888;
  241. margin: 0; padding-top: 0px; padding-bottom: 0px; padding-left: 8px; padding-right: 8px;
  242. text-decoration: none;`;
  243. // jerry: color: hsla(211, 20%, 64%, .4) lighter fonts
  244. // background-color: hsla(211, 20%, 64%, 0.1); color: hsla(211, 100%, 100%, .8)
  245. let defaultStyle = style + "!important;";
  246. let hoverStyle =
  247. style + "color:#91C5EE; box-shadow:0 3px 3px 0 #888; !important;";
  248.  
  249. // 设置搜索引擎链接
  250. let a = document.createElement("a");
  251. a.innerText = item.name;
  252. if (index==0) {
  253. a.style = defaultStyle + "border-top-left-radius: 5px; border-bottom-left-radius: 5px";
  254. a.onmouseenter = function () {
  255. this.style = hoverStyle +"border-top-left-radius: 5px; border-bottom-left-radius: 5px";
  256. };
  257. a.onmouseleave = function () {
  258. this.style = defaultStyle + "border-top-left-radius: 5px; border-bottom-left-radius: 5px";
  259. };
  260. } else if (index==(urlMapping.length-1)) {
  261. a.style = defaultStyle + "border-top-right-radius: 5px; border-bottom-right-radius: 5px";
  262. a.onmouseenter = function () {
  263. this.style = hoverStyle +"border-top-right-radius: 5px; border-bottom-right-radius: 5px";
  264. };
  265. a.onmouseleave = function () {
  266. this.style = defaultStyle + "border-top-right-radius: 5px; border-bottom-right-radius: 5px";
  267. };
  268. } else {
  269. a.style = defaultStyle;
  270. // 鼠标移入&移出效果,相当于hover
  271. a.onmouseenter = function () {
  272. this.style = hoverStyle;
  273. };
  274. a.onmouseleave = function () {
  275. this.style = defaultStyle;
  276. };
  277. }
  278. a.className = "search-engine-a";
  279. a.href = item.searchUrl + getKeywords();
  280.  
  281. div.appendChild(a);
  282. }
  283. }
  284.  
  285. (function () {
  286. "use strict";
  287. window.onload = addBox();
  288. })();

QingJ © 2025

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