词典切换 / Dictionary Switcher

在辞典网站左侧显示一个快速切换列表,节省「另开辞典页面」和「输入关键词」的动作及时间,提高查询效率。参考了自己撸的另一款:[搜索引擎切换器 / Search Engine Switcher](https://gf.qytechs.cn/zh-CN/scripts/446492)。

  1. // ==UserScript==
  2. // @name 词典切换 / Dictionary Switcher
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.1
  5. // @description 在辞典网站左侧显示一个快速切换列表,节省「另开辞典页面」和「输入关键词」的动作及时间,提高查询效率。参考了自己撸的另一款:[搜索引擎切换器 / Search Engine Switcher](https://gf.qytechs.cn/zh-CN/scripts/446492)。
  6. // @icon https://www.google.com/s2/favicons?sz=64&domain=gf.qytechs.cn
  7.  
  8.  
  9. // @match *://www.google.com/search?q=*
  10. // @match *://www.merriam-webster.com/dictionary/*
  11. // @match *://www.ldoceonline.com/dictionary/*
  12. // @match *://dictionary.cambridge.org/dictionary/english/*
  13. // @match *://www.vocabulary.com/dictionary/*
  14. // @match *://www.collinsdictionary.com/dictionary/english/*
  15. // @match *://www.oxfordlearnersdictionaries.com/definition/english/*
  16. // @match *://www.oxfordlearnersdictionaries.com/definition/american_english/*
  17. // @match *://www.britannica.com/dictionary/*
  18. // @match *://www.macmillandictionary.com/dictionary/british/*
  19. // @match *://www.etymonline.com/search?q=*
  20. // @match *://cn.bing.com/dict/search?q=*
  21. // @match *://www.urbandictionary.com/define.php?term=*
  22. // @match *://en.wikipedia.org/wiki/*
  23. // @match *://www.voicetube.com/definition/*
  24. // @match *://dict.youdao.com/w/*
  25. // @match *://dict.eudic.net/dicts/en/*
  26. // @match *://fanyi.sogou.com/text?keyword=*
  27. // @match *://www.jukuu.com/search.php?q=*
  28. // @match *://www.91dict.com/words*
  29. // @match *://www.zdic.net/hans/*
  30. // @match *://www.moedict.tw/*
  31. // @match *://youglish.com/pronounce/*
  32. // @match *://www.dictionary.com/browse/*
  33. // @match *://www.eigochigai.com/search?q=*
  34. // @match *://en.wiktionary.org/wiki/*
  35.  
  36. // @grant unsafeWindow
  37. // @grant window.onload
  38. // @grant GM_getValue
  39. // @grant GM_setValue
  40. // @run-at document-body
  41.  
  42. // @license MIT
  43. // ==/UserScript==
  44.  
  45. // 辞典网址配置
  46. const urlMapping = [
  47. {
  48. name: "Google",
  49. dicUrl: "https://www.google.com/search?q=",
  50. keyName: "q",
  51. testUrl: /https:\/\/www.google.com\/search.*/,
  52. },
  53. {
  54. name: "Oxford",
  55. dicUrl: "https://www.oxfordlearnersdictionaries.com/definition/english/",
  56. keyName: "",
  57. testUrl: /https:\/\/www.oxfordlearnersdictionaries.com\/definition\/english\/*/,
  58. },
  59. {
  60. name: "Oxford美式",
  61. dicUrl: "https://www.oxfordlearnersdictionaries.com/definition/american_english/",
  62. keyName: "",
  63. testUrl: /https:\/\/www.oxfordlearnersdictionaries.com\/definition\/american_english\/*/,
  64. },
  65. {
  66. name: "韦氏词典",
  67. dicUrl: "https://www.merriam-webster.com/dictionary/",
  68. keyName: "",
  69. testUrl: /https:\/\/www.merriam-webster.com\/dictionary\/*/,
  70. },
  71. {
  72. name: "Longman",
  73. dicUrl: "https://www.ldoceonline.com/dictionary/",
  74. keyName: "",
  75. testUrl: /https:\/\/www.ldoceonline.com\/dictionary\/*/,
  76. },
  77. {
  78. name: "Cambridge",
  79. dicUrl: "https://dictionary.cambridge.org/dictionary/english/",
  80. keyName: "",
  81. testUrl: /https:\/\/dictionary.cambridge.org\/dictionary\/english\/*/,
  82. },
  83. {
  84. name: "Macmillan",
  85. dicUrl: "https://www.macmillandictionary.com/dictionary/british/",
  86. keyName: "",
  87. testUrl: /https:\/\/www.macmillandictionary.com\/dictionary\/british\/*/,
  88. },
  89. {
  90. name: "Etymo词源",
  91. dicUrl: "https://www.etymonline.com/search?q=",
  92. keyName: "q",
  93. testUrl: /https:\/\/www.etymonline.com\/search.*/,
  94. },
  95. {
  96. name: "Vocabulary",
  97. dicUrl: "https://www.vocabulary.com/dictionary/",
  98. keyName: "",
  99. testUrl: /https:\/\/www.vocabulary.com\/dictionary\/*/,
  100. },
  101. {
  102. name: "Collins",
  103. dicUrl: "https://www.collinsdictionary.com/dictionary/english/",
  104. keyName: "",
  105. testUrl: /https:\/\/www.collinsdictionary.com\/dictionary\/english\/*/,
  106. },
  107. {
  108. name: "Britannica",
  109. dicUrl: "https://www.britannica.com/dictionary/",
  110. keyName: "",
  111. testUrl: /https:\/\/www.britannica.com\/dictionary\/*/,
  112. },
  113. {
  114. name: "YouGlish",
  115. dicUrl: "https://youglish.com/pronounce/",
  116. keyName: "",
  117. testUrl: /https:\/\/youglish.com\/pronounce\/*/,
  118. },
  119. {
  120. name: "Dictionary",
  121. dicUrl: "https://www.dictionary.com/browse/",
  122. keyName: "",
  123. testUrl: /https:\/\/www.dictionary.com\/browse\/*/,
  124. },
  125. {
  126. name: "有道词典",
  127. dicUrl: "https://dict.youdao.com/w/",
  128. keyName: "",
  129. testUrl: /https:\/\/dict.youdao.com\/w\/*/,
  130. },
  131. {
  132. name: "欧路词典",
  133. dicUrl: "https://dict.eudic.net/dicts/en/",
  134. keyName: "",
  135. testUrl: /https:\/\/dict.eudic.net\/dicts\/en\/*/,
  136. },
  137. // {
  138. // name: "Wiktionary",
  139. // dicUrl: "https://en.wiktionary.org/wiki/",
  140. // keyName: "",
  141. // testUrl: /https:\/\/en.wiktionary.org\/wiki\/*/,
  142. // },
  143. // {
  144. // name: "Bing",
  145. // dicUrl: "https://cn.bing.com/dict/search?q=",
  146. // keyName: "q",
  147. // testUrl: /https:\/\/cn.bing.com\/dict\/search.*/,
  148. // },
  149. // {
  150. // name: "Urban",
  151. // dicUrl: "https://www.urbandictionary.com/define.php?term=",
  152. // keyName: "term",
  153. // testUrl: /https:\/\/www.urbandictionary.com\/define.php.*/,
  154. // },
  155. // {
  156. // name: "Wikipedia",
  157. // dicUrl: "https://en.wikipedia.org/wiki/",
  158. // keyName: "",
  159. // testUrl: /https:\/\/en.wikipedia.org\/wiki\/*/,
  160. // },
  161. // {
  162. // name: "VoiceTube",
  163. // dicUrl: "https://www.voicetube.com/definition/",
  164. // keyName: "",
  165. // testUrl: /https:\/\/www.voicetube.com\/definition\/*/,
  166. // },
  167. // {
  168. // name: "人人词典",
  169. // dicUrl: "https://www.91dict.com/words?w=",
  170. // keyName: "w",
  171. // testUrl: /https:\/\/www.91dict.com\/words.*/,
  172. // },
  173. // {
  174. // name: "搜狗翻译",
  175. // dicUrl: "https://fanyi.sogou.com/text?keyword=",
  176. // keyName: "keyword",
  177. // testUrl: /https:\/\/fanyi.sogou.com\/text.*/,
  178. // },
  179. // {
  180. // name: "句酷",
  181. // dicUrl: "http://www.jukuu.com/search.php?q=",
  182. // keyName: "q",
  183. // testUrl: /http:\/\/www.jukuu.com\/search.php.*/,
  184. // },
  185. // {
  186. // name: "Eigochigai",
  187. // dicUrl: "https://www.eigochigai.com/search?q=",
  188. // keyName: "q",
  189. // testUrl: /https:\/\/www.eigochigai.com\/search.*/,
  190. // },
  191. // {
  192. // name: "汉典",
  193. // dicUrl: "https://www.zdic.net/hans/",
  194. // keyName: "",
  195. // testUrl: /https:\/\/www.zdic.net\/hans\/*/,
  196. // },
  197. // {
  198. // name: "国语辞典/两岸辞典",
  199. // dicUrl: "https://www.moedict.tw/",
  200. // keyName: "",
  201. // testUrl: /https:\/\/www.moedict.tw\/*/,
  202. // },
  203. ];
  204.  
  205. // JS 获取 url 参数
  206. function getQueryVariable(variable) {
  207. let query = window.location.search.substring(1);
  208. if (query === "") {
  209. return decodeURIComponent(window.location.href.split("/").pop());
  210. } else {
  211. let pairs = query.split("&");
  212. for (let pair of pairs) {
  213. let [key, value] = pair.split("=");
  214. if (key === variable) {
  215. return decodeURIComponent(value);
  216. }
  217. }
  218. }
  219. return null;
  220. }
  221.  
  222. // 从 url 中获取搜索关键词
  223. function getKeywords() {
  224. let keywords = "";
  225. for (let item of urlMapping) {
  226. if (item.testUrl.test(window.location.href)) {
  227. keywords = getQueryVariable(item.keyName);
  228. break;
  229. }
  230. }
  231. console.log(keywords);
  232. return keywords;
  233. }
  234.  
  235. // 添加节点
  236. function addBox() {
  237. // 主元素
  238. const dics = document.createElement("div");
  239. dics.id = "dic-app-box";
  240. dics.style = `
  241. position: fixed;
  242. top: 150px;
  243. left: 12px;
  244. width: 100px;
  245. background-color: hsla(200, 40%, 96%, .8);
  246. font-size: 12px;
  247. border-radius: 6px;
  248. z-index: 99999;`;
  249. document.body.insertAdjacentElement("afterbegin", dics);
  250.  
  251. // 标题
  252. let title = document.createElement("span");
  253. title.innerText = "切换辞典";
  254. title.style = `
  255. display: block;
  256. color: hsla(211, 60%, 35%, .8);
  257. text-align: center;
  258. margin-top: 10px;
  259. margin-bottom: 5px;
  260. font-size 12px;
  261. font-weight: bold;
  262. -webkit-user-select: none;
  263. -moz-user-select: none;
  264. -ms-user-select: none;
  265. user-select:none;`;
  266. dics.appendChild(title);
  267.  
  268. // 辞典列表
  269. for (let index in urlMapping) {
  270. let item = urlMapping[index];
  271.  
  272. // 列表样式
  273. let style = `
  274. text-align: center;
  275. display: block;
  276. color: hsla(211, 60%, 35%, .8) !important;
  277. padding: 5px 5px;
  278. text-decoration: none;`;
  279. let defaultStyle = style + `
  280. color: hsla(211, 60%, 35%, .8) !important;`;
  281. let hoverStyle = style + `
  282. background-color: hsla(211, 60%, 35%, .1);`;
  283.  
  284. // 设置辞典链接
  285. let a = document.createElement("a");
  286. a.innerText = item.name;
  287. a.style = defaultStyle;
  288. a.className = "dic-a";
  289. a.href = item.dicUrl + getKeywords();
  290.  
  291. // 鼠标移入&移出效果,相当于 hover
  292. a.onmouseenter = function() {
  293. this.style = hoverStyle;
  294. };
  295. a.onmouseleave = function() {
  296. this.style = defaultStyle;
  297. };
  298. dics.appendChild(a);
  299. }
  300. }
  301.  
  302. (function() {
  303. "use strict";
  304. window.onload = addBox();
  305. })();

QingJ © 2025

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