Greasy Fork镜像 支持简体中文。

网络百科聚合

同一词条在网络百科中互相跳转

目前為 2018-12-22 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 网络百科聚合
  3. // @version 0.94
  4. // @description 同一词条在网络百科中互相跳转
  5. // @include
  6. // @match *://baike.baidu.com/*
  7. // @match *://zh.wikipedia.org/*
  8. // @match *://baike.sogou.com/*
  9. // @match *://www.baike.com/*
  10. // @match *://baike.chinaso.com/*
  11. // @grant 来自各个网络百科
  12. // @author 太史子义慈
  13. // @namespace qs93313@sina.cn
  14. // ==/UserScript==
  15.  
  16. !(function() {
  17. wiki();
  18. })();
  19.  
  20. function wiki() {
  21. //获取域名
  22. var wlhost = window.location.host;
  23. console.log(wlhost);
  24. //百度百科
  25. var host_baidu = (wlhost == "baike.baidu.com");
  26. //维基百科
  27. var host_wiki = (wlhost == "zh.wikipedia.org");
  28. //搜狗百科
  29. var host_sogou = (wlhost == "baike.sogou.com");
  30. //互动百科
  31. var host_hudong = (wlhost == "www.baike.com");
  32. //国搜百科
  33. var host_china = (wlhost == "baike.chinaso.com");
  34.  
  35. //搜索引擎网址目录
  36. var dirall = dir_all();
  37. //新建选择框
  38. var new_select = document.createElement('select');
  39. new_select.setAttribute("id", "id_new_select");
  40. //循环索引
  41. var i
  42. //选择框子节点下面要建立大量【选项】子节点
  43. for(i in dirall) {
  44. var v = dirall[i][0];
  45. new_option(v, i, new_select);
  46. }
  47. //新建按钮
  48. var new_btn = document.createElement('div');
  49. new_btn.setAttribute("id", "id_new_button");
  50. new_btn.innerHTML = "跳转搜索";
  51.  
  52. //百度百科
  53. if(host_baidu) {
  54. //调整祖先节点的宽度
  55. var wsm = document.getElementsByClassName("wgt-searchbar-main")[0];
  56. wsm.style.cssText = "width: 100%;";
  57.  
  58. var father_baidu = document.getElementById("searchForm");
  59. var bro_baidu = document.getElementsByClassName("help")[0];
  60. father_baidu.insertBefore(new_select, bro_baidu);
  61. father_baidu.insertBefore(new_btn, bro_baidu);
  62.  
  63. new_select.style.cssText = "outline:none;font-size:17px;height:40px;margin:0 0 0 4px;";
  64. new_btn.style.cssText = "display:inline-block;outline:none;font-size:17px;width:104px;height:40px;background-color:#FF5200;line-height:40px;text-align:center;color:white;letter-spacing:1px;cursor:pointer;vertical-align:middle;";
  65. } else if(host_wiki) {
  66. var p_search = document.getElementById("p-search");
  67. p_search.style.marginRight = "8px";
  68.  
  69. var father_wiki = document.getElementById("right-navigation");
  70. father_wiki.appendChild(new_select);
  71. father_wiki.appendChild(new_btn);
  72. new_select.style.cssText = "outline:none;font-size:14px;height:25px;margin:9px 0 0 0;";
  73. new_btn.style.cssText = "display:inline-block;outline:none;font-size:14px;width:84px;height:25px;background-color:#FF5200;line-height:25px;text-align:center;color:white;letter-spacing:1px;cursor:pointer;margin:0 10px 0 0;";
  74. } else if(host_sogou) {
  75. var searchbox = document.getElementsByClassName("searchbox")[0];
  76. searchbox.style.width = "1138px";
  77. var btn_clear = document.getElementsByClassName("btn_clear")[0];
  78. btn_clear.style.right = "438px";
  79.  
  80. var father_sogou = document.getElementById("Form");
  81. var bro_sogou = document.getElementById("divc");
  82. father_sogou.insertBefore(new_select, bro_sogou);
  83. father_sogou.insertBefore(new_btn, bro_sogou);
  84. new_select.style.cssText = "outline:none;font-size:16px;height:30px;margin:0 0 0 4px;";
  85. new_btn.style.cssText = "display:inline-block;outline:none;font-size:16px;width:104px;height:32px;background-color:#FF5200;line-height:32px;text-align:center;color:white;letter-spacing:1px;cursor:pointer;";
  86. } else if(host_hudong) {
  87. var father_hudong = document.getElementsByClassName("search-panel")[0];
  88. father_hudong.appendChild(new_select);
  89. father_hudong.appendChild(new_btn);
  90. new_select.style.cssText = "outline:none;font-size:16px;height:36px;margin:0 0 0 4px;";
  91. new_btn.style.cssText = "display:inline-block;outline:none;font-size:16px;width:104px;height:34px;background-color:#FF5200;line-height:34px;text-align:center;color:white;letter-spacing:1px;cursor:pointer;";
  92. }else if(host_china){
  93. var bkgg = document.getElementsByClassName("bkgg")[0];
  94. bkgg.style.display = "none";
  95.  
  96. var father_china = document.getElementsByClassName("seInputWrapper")[0];
  97. father_china.appendChild(new_select);
  98. father_china.appendChild(new_btn);
  99. new_select.style.cssText = "outline:none;font-size:16px;height:43px;margin:0 0 0 650px;";
  100. new_btn.style.cssText = "display:inline-block;outline:none;font-size:16px;width:104px;height:43px;background-color:#FF5200;line-height:43px;text-align:center;color:white;letter-spacing:1px;cursor:pointer;margin:-43px 0 0 742px;";
  101. }
  102.  
  103. //按钮点击事件
  104. new_btn.onclick = function new_btn_click() {
  105. //获得输入框数据
  106. var new_input;
  107. if(host_baidu) {
  108. new_input = document.getElementById("query");
  109. } else if(host_wiki) {
  110. new_input = document.getElementById("searchInput");
  111. } else if(host_sogou) {
  112. new_input = document.getElementById("searchText");
  113. } else if(host_hudong) {
  114. new_input = document.getElementsByClassName("ac_input")[0];
  115. } else if(host_china){
  116. new_input = document.getElementsByClassName("search_input2")[0];
  117. }
  118. var new_input_val = new_input.value;
  119. //计算输入框数据长度
  120. var new_input_val_len = new_input_val.length;
  121. //如果输入框有数据
  122. if(new_input_val_len > 0) {
  123. //获得选择框里被选中的选项索引
  124. var option_index = new_select.selectedIndex;
  125. //根据索引获得获得选择框里被选中的选项id
  126. var option_select_id = new_select.options[option_index].id;
  127. //根据id和网址目录获得网址
  128. var pcsearch = dirall[option_select_id][1];
  129. //用输入框的数据替换掉网址内的替换符
  130. var dti = pcsearch.replace("%sv%", new_input_val);
  131. //网址跳转
  132. window.open(dti);
  133. } else {
  134. alert("请在前面的输入框输入要搜索的内容。[GreasyFork]");
  135. new_input.focus();
  136. }
  137. }
  138. }
  139.  
  140. //新建option
  141. function new_option(ih, aid, ns) {
  142. var new_opt = document.createElement('option');
  143. new_opt.innerHTML = ih;
  144. new_opt.setAttribute("id", aid);
  145. ns.appendChild(new_opt);
  146. }
  147.  
  148. //搜索引擎网址目录,%sv%为替换符
  149. function dir_all() {
  150. var da = {
  151. "id_opt_00": {
  152. 0: "维基百科",
  153. 1: "https://zh.wikipedia.org/w/index.php?search=%sv%&fulltext=1",
  154. },
  155. "id_opt_01": {
  156. 0: "百度百科",
  157. 1: "https://baike.baidu.com/search?word=%sv%",
  158. },
  159. "id_opt_02": {
  160. 0: "百度搜索",
  161. 1: "https://www.baidu.com/s?wd=site:(baike.baidu.com) \"%sv%\"&ct=1",
  162. },
  163. "id_opt_03": {
  164. 0: "搜狗百科",
  165. 1: "http://baike.sogou.com/Search.e?sp=S%sv%",
  166. },
  167. "id_opt_04": {
  168. 0: "互动百科",
  169. 1: "http://so.baike.com/doc/%sv%",
  170. },
  171. "id_opt_05": {
  172. 0: "国搜百科",
  173. 1: "http://baike.chinaso.com/wiki/search?q=%sv%",
  174. },
  175. "id_opt_06": {
  176. 0: "知网学问",
  177. 1: "http://xuewen.cnki.net/searchentry.aspx?key=%sv%",
  178. },
  179. "id_opt_07": {
  180. 0: "必应网典",
  181. 1: "http://www.bing.com/knows/search?mkt=zh-cn&q=%sv%",
  182. },
  183. "id_opt_08": {
  184. 0: "360百科",
  185. 1: "https://baike.so.com/search/?q=%sv%",
  186. },
  187. }
  188. return da;
  189. }

QingJ © 2025

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