searchEngineJumpCE-modify by ted423

方便的在各个引擎之间跳转。可自定义搜索列表的 NLF 修改版。

当前为 2015-11-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name searchEngineJumpCE-modify by ted423
  3. // @author NLF && ywzhaiqi
  4. // @contributor ted423
  5. // @description 方便的在各个引擎之间跳转。可自定义搜索列表的 NLF 修改版。
  6. // @version 7.1511.23.0
  7. // @namespace https://greasyfork.org/users/85
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11. (function(){
  12. 'use strict';
  13. var prefs = {
  14. openInNewTab: false, // 是否在新页面打开.
  15. hidePrefsBtn: false, // 隐藏设置按钮
  16. hideEnglineLabel: 0, // 是否隐藏前几个搜索的文字部分。0:不隐藏,1:根据高度自行判断,2:隐藏
  17. engineListDataType: 'ted423', // 搜索列表默认类型
  18. iconType: '', // 获取 icon 的在线服务的地址类型
  19. //position: '', // 全局搜索条插入的位置:default, left, top
  20. debug: true,
  21. };
  22.  
  23. var engineListData = {
  24. custom: '',
  25. ted423: '网页\n 百度, https://www.baidu.com/s?wd=%s&ie=utf-8\n 360, http://www.haosou.com/s?ie=utf-8&q=%s\n bing, https://cn.bing.com/search?q=%s&pc=OPER\n 搜狗, http://www.sogou.com/web?query=%s\n DuckDuckGo, https://duckduckgo.com/?q=%s\n Yahoo--网页\n Yahoo, https://search.yahoo.com/search?p=%s\n Yahoo(tw), https://tw.search.yahoo.com/search?p=%s\n Yahoo.co.jp, http://search.yahoo.co.jp/search?p=%s&aq=-1&oq=&ei=UTF-8&fr=top_ga1_sa&x=wrt\n Google--百度\n Google.hk, https://www.google.com.hk/search?q=%s&ie=utf-8&safe=off, https://i.imgur.com/xK23DKf.png\n Google.co.jp,https://www.google.co.jp/search?q=%s&ie=utf-8&safe=off, https://i.imgur.com/xK23DKf.png\n资料-Scholar\n 百科, http://baike.baidu.com/searchword/?word=%s&pic=1&sug=1&ie=utf-8\n Scholar, http://scholar.google.com/scholar?hl=zh-CN&q=%s&btnG=&lr=, https://i.imgur.com/hJVSUU5.png\n 学术, http://xueshu.baidu.com/s?wd=%s\n 知乎, http://www.zhihu.com/search?q=%s\n 萌娘百科, http://zh.moegirl.org/index.php?search=%s\n Google Book, https://www.google.com/search?q=%s&btnG=%E6%90%9C%E7%B4%A2%E5%9B%BE%E4%B9%A6&tbm=bks&tbo=1&hl=zh-CN&gws_rd=ssl, https://i.imgur.com/xK23DKf.png\n WIKI--百科\n ZWIKI, http://zh.wikipedia.org/w/index.php?search=%s&button=&title=Special%3ASearch, https://zh.wikipedia.org/static/favicon/wikipedia.ico\n EWIKI, https://en.wikipedia.org/w/index.php?search=%s&button=&title=Special%3ASearch, https://zh.wikipedia.org/static/favicon/wikipedia.ico\n JWIKI, http://ja.wikipedia.org/w/index.php?search=%s&button=&title=Special%3ASearch, https://zh.wikipedia.org/static/favicon/wikipedia.ico\n 开发--百科\n stackoverflow, http://stackoverflow.com/search?q=%s, http://cdn.sstatic.net/stackoverflow/img/favicon.ico\n MDN, https://developer.mozilla.org/en-US/search?q=%s,https://developer.cdn.mozilla.net/media/img/favicon32.png\n github, https://github.com/search?q=%s\n krugle, http://opensearch.krugle.org/document/search/#query=%s,http://opensearch.krugle.org/media/images/favicon.ico\n npm, https://www.npmjs.org/search?q=%s, http://i.imgur.com/Ec0WrY8.png\n地图\n 百度, http://map.baidu.com/?newmap=1&ie=utf-8&s=s%26wd%3D%s\n Google, https://www.google.com/maps/search/%s/\n 搜狗, http://map.sogou.com/#lq=%s\n Bing, https://www.bing.com/ditu/?q=%s\n音乐\n 天天动听, http://www.dongting.com/#a=searchlist&q=%s\n Music, http://music.baidu.com/search?key=%s&ie=utf-8&oe=utf-8\n 搜狗, http://mp3.sogou.com/music.so?query=%s\n 一听, http://so.1ting.com/all.do?q=%s\n 虾米, http://www.xiami.com/search?key=%s\n piapro, http://piapro.jp/search/?view=audio&keyword=%s\n Lyric, http://music.baidu.com/search/lrc?key=%s\n图片-Flickr\n 百度, http://image.baidu.com/search/index?tn=baiduimage&word=%s\n Google, https://www.google.com.hk/search?tbm=isch&q=%s, https://i.imgur.com/xK23DKf.png\n 花瓣, http://huaban.com/search/?q=%s\n Picsearch, http://cn.picsearch.com/index.cgi?q=%s\n Flickr, http://www.flickr.com/search/?w=all&q=%s\n Pixiv, http://www.pixiv.net/search.php?s_mode=s_tag&word=%s\n dA, http://www.deviantart.com/?q=%s, UTF16\n , http://img.jpg4.info/index.php?feed=%s, https://i.imgur.com/qkOEi8O.png\n下载-nyaa\n dmhy, http://share.dmhy.org/topics/list?keyword=%s\n kickass, https://kat.cr/usearch/%s/, http://i.imgur.com/uz2GaPN.png\n BTSOW, http://www.bt2mag.com/search/%s, http://www.bt2mag.com/app/bts/View/img/btsow.com.favicon.ico\n BTDigg, https://btdigg.org/search?q=%s\n ed2000, https://www.baidu.com/s?wd=%s+site:ed2000.com&ie=utf-8, http://www.biaoqing.com/2000/favicon.ico\n 字幕--下载\n subom, http://www.subom.net/search/%s\n , http://subhd.com/search/%s, https://i.imgur.com/kC8RATC.png\n 射手网(伪), http://sub.makedie.me/sub/?searchword=%s\n nyaa--dmhy\n nyaa.se, http://www.nyaa.se/?page=search&term=%s, https://i.imgur.com/lfuirgg.png\n nyaa.eu, http://www.nyaa.eu/?page=search&term=%s, https://i.imgur.com/lfuirgg.png\n sukebei.nyaa.se, http://sukebei.nyaa.se/?page=search&cats=0_0&filter=0&term=%s, https://i.imgur.com/lfuirgg.png\n sukebei.nyaa.eu, http://sukebei.nyaa.eu/?page=search&cats=0_0&filter=0&term=%s, https://i.imgur.com/lfuirgg.png\n网购\n 一淘, http://s.etao.com/search?q=%s\n 京东, http://search.jd.com/Search?keyword=%s&enc=utf-8\n 淘宝, http://s.taobao.com/search?q=%s, http://www.taobao.com/favicon.ico\n 亚马逊, http://www.amazon.cn/s/ref=nb_ss?keywords=%s\netc\n AMO, https://addons.mozilla.org/zh-CN/firefox/search/?q=%s, https://addons.cdn.mozilla.net/favicon.ico\n 汉典, http://www.zdic.net/sousuo/?q=%s&tp=tp3\n',
  26. };
  27.  
  28. var MAIN_CSS = '#sej-container {\n box-shadow:0px 0px 3px #aaaaaa;\n opacity: 0.7;\n display:table;\n font-family: Comic Sans MS,"Microsoft YaHei",微软雅黑;\n position: relative;\n z-index: auto;\n padding: 1px 0 1px 10px;\n line-height: 1.5;\n font-size: 13px;\n}\n\n\n#sej-expanded-category {\n font-weight: bold;\n}\n#sej-expanded-category::after {\n content:":";\n}\n\n\n.sej-engine {\n line-height: 2;\n display: inline-block;\n margin: 0;\n border: none;\n padding: 0 4px;\n text-decoration: none;\n color: #120886 !important;\n transition: background-color 0.15s ease-in-out;\n}\na.sej-engine.only-icon {\n margin-left: 3px;\n margin-right: 3px;\n}\na.sej-engine.only-icon > span {\n display: none;\n}\na.sej-engine:link, a.sej-engine:visited{\n text-decoration: none;\n}\na.sej-engine:visited, a.sej-engine:visited *, a.sej-engine:active, a.sej-engine:active *{\n color: #120886 !important;\n}\n.sej-drop-list-trigger {\n\n}\n.sej-drop-list-trigger-shown {\n background-color: #DEEDFF !important;\n}\n.sej-drop-list-trigger::after {\n content: \'\';\n display: inline-block;\n margin: 0 0 0 3px;\n padding: 0;\n width: 0;\n height: 0;\n border-top: 6px solid #BCBCBC;\n border-right: 5px solid transparent;\n border-left: 5px solid transparent;\n border-bottom: 0px solid transparent;\n vertical-align: middle;\n transition: -webkit-transform 0.3s ease-in-out;\n transition: transform 0.3s ease-in-out;\n}\n.sej-drop-list-trigger-shown::after {\n -webkit-transform: rotate(180deg);\n transform: rotate(180deg);\n}\n.sej-engine:hover {\n background-color: #EAEAEA;\n}\n.sej-drop-list > .sej-engine {\n display: block;\n padding-top: 4px;\n padding-bottom: 4px;\n}\n.sej-drop-list > .sej-engine:hover {\n background-color: #DEEDFF;\n}\n\n.sej-engine-icon {\n display: inline-block;\n height: 16px;\n border: none;\n padding: 0;\n margin: 0 3px 0 0;\n vertical-align: text-bottom;\n}\n\n\n.sej-drop-list {\n position: absolute;\n display: none;\n opacity: 0.3;\n top: -10000px;\n left: 0;\n min-width: 120px;\n border: 1px solid #FAFAFA;\n padding: 5px 0;\n text-align: center;\n font-size: 13px;\n -moz-box-shadow: 2px 2px 5px #ccc;\n -webkit-box-shadow: 2px 2px 5px #ccc;\n box-shadow: 2px 2px 5px #ccc;\n background-color: white;\n transition: opacity 0.2s ease-in-out,\n top 0.2s ease-in-out;\n}';
  29.  
  30.  
  31. var categoryMap = {// rules 和 engineList 的对应
  32. 'web': '网页',
  33. 'map': '地图',
  34. 'video': '视频',
  35. 'music': '音乐',
  36. 'image': '图片',
  37. 'knowledge': '资料',
  38. 'sociality': '社交',
  39. 'shopping': '网购',
  40. 'download': '下载',
  41. };
  42.  
  43. function isTheSameCategory(c1, c2) {
  44. return (categoryMap[c1] || c1) == (categoryMap[c2] || c2);
  45. }
  46.  
  47.  
  48. var rules = [// 根据规则把搜索引擎列表插入到指定网站
  49. // 网页
  50. // /////////////第一个可以当模板看
  51. {
  52. name: "google网页搜索",// 你要加载的网站的名字(方便自己查找)
  53. enabled: true,// 是否启用
  54. url: /^https?:\/\/(www|encrypted)\.google\.(?!co\.jp)[^\/]{2,9}\/(webhp|search|#|$|\?)(?!.*tbm=)/,// 在哪个网站上加载,正则.
  55. mutationTitle: true, // 是否要监视标题的变化
  56. engineList: 'web',// 加载哪个类型的列表:
  57. style: '\
  58. border-bottom: 1px solid #E5E5E5;\
  59. border-top: 1px solid #E5E5E5;\
  60. width:100%;\
  61. padding-left: 15px;\
  62. ',// 给引擎列表的样式
  63. // 插入文档,相关
  64. // target 将引擎跳转工具栏插入到文档的某个元素
  65. // (请使用css匹配(请加上 'css;' 的前缀),比如: 'css;#subform_ctrl' );
  66. // keyword 使用 css选中一个form input元素 或者 该项是一个函数,使用返回值
  67. // where 四种:
  68. // 'beforeBegin'(插入到给定元素的前面) ;
  69. // 'afterBegin'(作为给定元素的第一个子元素) ;
  70. // 'beforeEnd' (作为给定元素的最后一个子元素) ;
  71. // 'afterEnd'(插入到给定元素的后面);.
  72. insertIntoDoc: {
  73. keyword: 'css;input[name="q"]',
  74. target: 'css;#top_nav',
  75. where: 'beforeBegin',
  76. },
  77. stylish: '',// 自定义样式
  78. },
  79. {
  80. name: "google.co.jp",
  81. enabled: true,
  82. url: /^https?:\/\/(www|encrypted)\.google\.co\.jp\/(webhp|search|#|$|\?)(?:.(?!&tbm=))*$/,
  83. mutationTitle: true,
  84. engineList: 'web',
  85. style: '\
  86. border-bottom: 1px solid #E5E5E5;\
  87. border-top: 1px solid #E5E5E5;\
  88. width:100%;\
  89. padding-left: 15px;\
  90. ',
  91.  
  92.  
  93. insertIntoDoc: {
  94. keyword: 'css;input[name="q"]',
  95. target: 'css;#top_nav',
  96. where: 'beforeBegin',
  97. },
  98. },
  99. {
  100. name: "baidu 网页搜索",
  101. url: /^https?:\/\/www\.baidu\.com\/(?:s(?!.*tn=baidulocal)|baidu(?!.*tn=baidulocal)|)/,
  102. mutationTitle: true,
  103. enabled: true,
  104. engineList: 'web',
  105. style: '\
  106. border-top:1px solid #D9E1F7;\
  107. border-bottom:1px solid #D9E1F7;\
  108. margin-left: 122px;\
  109. ',
  110. insertIntoDoc: {
  111. keyword: 'css;#kw',
  112. target: 'css;#container',
  113. where: 'beforeBegin',
  114. },
  115. },
  116. {
  117. name: "baidu 简洁搜索",//百度简洁搜索:https://www.baidu.com/s?wd=firefox&ie=utf-8&tn=baidulocal
  118. url: /^https?:\/\/www\.baidu\.com\/s\?.*tn=baidulocal/,
  119. enabled: true,
  120. engineList: 'web',
  121. style: '\
  122. border-top:1px solid #D9E1F7;\
  123. border-bottom:1px solid #D9E1F7;\
  124. margin-left: 122px;\
  125. ',
  126. insertIntoDoc: {
  127. keyword: 'css;input[name="wd"]',
  128. target: 'css;table[bgcolor="#e6e6e6"]',
  129. where: 'beforeBegin',
  130. },
  131. },
  132. {
  133. name: "必应网页搜索",
  134. url: /^https?:\/\/[^.]*\.bing\.com\/search/,
  135. enabled: true,
  136. engineList: 'web',
  137. style: '\
  138. border-collapse:separate;\
  139. border-top: 1px solid #E6E6E6;\
  140. border-bottom: 1px solid #E6E6E6;\
  141. margin-top:15px;\
  142. margin-left: 10px;\
  143. ',
  144. insertIntoDoc: {
  145. keyword: 'css;#sb_form_q',
  146. target: 'css;#b_header',
  147. where: 'beforeEnd',
  148. },
  149. stylish: '#b_content{ padding: 10px 0px 20px 100px !important; } .b_underSearchbox{margin:5px 20px 0px;}'
  150. },
  151. {
  152. name: "360搜索",
  153. url: /^https?:\/\/www\.haosou\.com\/s\?/,
  154. engineList: 'web',
  155. enabled: true,
  156. style: '\
  157. border-bottom: 1px solid #E0E0E0;\
  158. border-top: 1px solid #E0E0E0;\
  159. margin-left: 20px;\
  160. ',
  161. insertIntoDoc: {
  162. keyword: 'css;#keyword',
  163. target: 'css;#head',
  164. where: 'afterEnd',
  165. },
  166. stylish: '#header .inner{height: 116px !important;}'
  167. },
  168. {
  169. name: "搜狗网页搜索",
  170. url: /^https?:\/\/www\.sogou\.com\/(?:web|s)/,
  171. enabled: true,
  172. engineList: 'web',
  173. style: "\
  174. margin-bottom: 10px;\
  175. margin-left: 35px;\
  176. ",
  177. insertIntoDoc: {
  178. keyword: 'css;#upquery',
  179. target: 'css;#wrapper',
  180. where: 'beforeBegin',
  181. },
  182. stylish: '.header{ margin-bottom: 5px; }'
  183. },
  184. {
  185. name: "雅虎网页搜索",
  186. url: /^https?:\/\/search\.yahoo\.com\/search/,
  187. engineList: '网页',
  188. enabled: true,
  189. style: "\
  190. text-align:left;\
  191. border-top:1px solid #D4E9F7;\
  192. border-bottom:1px solid #D4E9F7;\
  193. ",
  194. insertIntoDoc: {
  195. keyword: 'css;#yschsp',
  196. target: 'css;#hd',
  197. where: 'afterEnd'
  198. },
  199. stylish: '#doc #sticky-hd ~ #bd {margin-top: 110px;}'
  200. },
  201. {
  202. name: "tw.yahoo",
  203. url: /^https?:\/\/tw\.search\.yahoo\.com\/search/,
  204. engineList: '网页',
  205. enabled: true,
  206. style: "\
  207. margin-left:15px;\
  208. margin-top:5px;\
  209. border-top:1px solid #D4E9F7;\
  210. border-bottom:1px solid #D4E9F7;\
  211. ",
  212. insertIntoDoc: {
  213. keyword: 'css;#yschsp',
  214. target: 'css;#sticky-hd',
  215. where: 'beforeEnd'
  216. },
  217. stylish: '#bd {margin-top: 105px!important;}'
  218. },
  219. {
  220. name: "yahoo.co.jp",
  221. url: /^https?:\/\/search\.yahoo\.co\.jp\/search/,
  222. engineList: '网页',
  223. enabled: true,
  224. style: "\
  225. margin:0px auto;\
  226. border:1px solid #D4E9F7;\
  227. ",
  228. insertIntoDoc: {
  229. keyword: 'css;#yschsp',
  230. target: 'css;#ygma',
  231. where: 'afterEnd'
  232. },
  233. },
  234. {
  235. name: "duckduckgo",
  236. url: /^https?:\/\/duckduckgo\.com\/\?/,
  237. engineList: '网页',
  238. enabled: true,
  239. style: "\
  240. margin-left:15px;\
  241. border:1px solid #D4E9F7;\
  242. ",
  243. insertIntoDoc: {
  244. keyword: 'css;#search_form_input',
  245. target: 'css;#zero_click_wrapper',
  246. where: 'afterEnd'
  247. },
  248. },
  249. // 知识
  250. {
  251. name: "谷歌学术",
  252. enabled: true,
  253. url: /^https?:\/\/scholar\.google(?:\.\D{1,3}){1,2}\/scholar\?/,
  254. engineList: "资料",
  255. style: '\
  256. border-bottom:1px solid #E5E5E5;\
  257. border-top:1px solid #E5E5E5;\
  258. z-index:999;\
  259. position:relative;\
  260. ',
  261. insertIntoDoc: {
  262. target: 'css;#gs_ab',
  263. keyword: 'css;input[name="q"]',
  264. where: 'beforeBegin'
  265. }
  266. },
  267. {
  268. name: "百度学术",
  269. url: /^https?:\/\/xueshu\.baidu\.com\/s\?/,
  270. enabled: true,
  271. engineList: '资料',
  272. style: '\
  273. border-bottom:1px solid #D9E1F7;\
  274. ',
  275. insertIntoDoc: {
  276. keyword: 'css;#kw',
  277. target: 'css;#head',
  278. where: 'afterEnd',
  279. },
  280. stylish: '#container{padding-top: 130px !important;}'
  281. },
  282. {
  283. name: "百度百科",
  284. url: /^https?:\/\/baike\.baidu\.com\/(search|view|subview)/,
  285. engineList: "资料",
  286. enabled: true,
  287. style: "\
  288. margin:0 auto;\
  289. z-index: 999999;\
  290. ",
  291. insertIntoDoc: {
  292. keyword: 'css;input#query',
  293. target: 'css;.header-wrapper',
  294. where: 'afterEnd',
  295. },
  296. },
  297. {
  298. name: "萌娘百科",
  299. url: /^https?:\/\/zh\.moegirl\.org\/./,
  300. engineList: "资料",
  301. enabled: true,
  302. style: "\
  303. z-index: 999999;\
  304. ",
  305. insertIntoDoc: {
  306. keyword: function () {
  307. if(document.getElementById('searchText'))return document.getElementById('searchText').value;
  308. else return document.getElementById('firstHeading').textContent;
  309. },
  310. target: 'css;#content',
  311. where: 'afterBegin',
  312. },
  313. },
  314. {
  315. name: "google book",
  316. enabled: true,
  317. url: /^https?:\/\/www\.google\.co.{1,3}\/search\?.*(&btnG=%E6)|(tbm=bks)/,
  318. mutationTitle: true,
  319. engineList: '资料',
  320. style: '\
  321. border-bottom: 1px solid #E5E5E5;\
  322. border-top: 1px solid #E5E5E5;\
  323. width:100%;\
  324. padding-left: 15px;\
  325. ',
  326.  
  327.  
  328. insertIntoDoc: {
  329. keyword: 'css;input[name="q"]',
  330. target: 'css;#top_nav',
  331. where: 'beforeBegin',
  332. },
  333. },
  334. {
  335. name: "互知识",
  336. url: /^https?:\/\/[a-z]{2,3}\.baike\.com\/[a-z]/,
  337. enabled: true,
  338. engineList: "资料",
  339. style: '\
  340. position:fixed;\
  341. top:80px;\
  342. right:2%;\
  343. width:90px;\
  344. z-index:99;\
  345. margin:0 auto;\
  346. ',
  347. insertIntoDoc: {
  348. keyword: function() {
  349. var input;
  350. if (document.getElementsByClassName('ac_input')[0] != undefined) {
  351. if (document.getElementsByClassName('ac_input')[0].value != "")
  352. input = document.getElementsByClassName('ac_input')[0].value;
  353. else if (document.getElementsByClassName('blue')[0].innerHTML != "") input = document.getElementsByClassName('blue')[0].innerHTML;
  354. else input = document.evaluate("//h1", document, null, 9, null).singleNodeValue.innerHTML;
  355. } else if (document.getElementsByClassName('blue')[0].innerHTML != "") input = document.getElementsByClassName('blue')[0].innerHTML;
  356. else input = document.evaluate("//h1", document, null, 9, null).singleNodeValue.innerHTML;
  357. return input;
  358. },
  359. target: 'css;body',
  360. where: 'afterbegin'
  361. }
  362. },
  363. {
  364. name: "wiki",
  365. url: /^https?:\/\/..\.wikipedia\.org\/w\/index\.php(?!.*\?search=)/,
  366. enabled: true,
  367. engineList: "资料",
  368. style: '\
  369. border-top:1px solid #D9E1F7;\
  370. border-bottom:1px solid #D9E1F7;\
  371. margin-top:5px;\
  372. ',
  373. insertIntoDoc: {
  374. keyword: 'css;#searchInput',
  375. target: 'css;#siteNotice',
  376. where: 'beforeBegin'
  377. }
  378. },
  379. {
  380. name: "wiki[ZH]",
  381. url: /^https?:\/\/zh\.wikipedia\.org\/(?:zh|wiki\/|w\/index.php\?search=)/,
  382. enabled: true,
  383. engineList: "资料",
  384. style: '\
  385. border-top:1px solid #D9E1F7;\
  386. border-bottom:1px solid #D9E1F7;\
  387. margin-top:5px;\
  388. ',
  389. insertIntoDoc: {
  390. keyword: function () {
  391. if(document.getElementById('searchText'))
  392. return document.getElementById('searchText').value;
  393. else return document.getElementById('firstHeading').childNodes[0].textContent;
  394. },
  395. target: 'css;#siteNotice',
  396. where: 'beforeBegin'
  397. }
  398. },
  399. {
  400. name: "wiki[EN]",
  401. url: /^https?:\/\/en\.wikipedia\.org\/(wiki\/|w\/index\.php\?search=)/,
  402. enabled: true,
  403. engineList: "资料",
  404. style: '\
  405. border-top:1px solid #D9E1F7;\
  406. border-bottom:1px solid #D9E1F7;\
  407. margin-top:5px;\
  408. ',
  409. insertIntoDoc: {
  410. keyword: function () {
  411. if(document.getElementById('searchText'))
  412. return document.getElementById('searchText').value;
  413. else return document.getElementById('firstHeading').childNodes[0].textContent;
  414. },
  415. target: 'css;#siteNotice',
  416. where: 'beforeBegin'
  417. }
  418. },
  419. {
  420. name: "wiki[JP]",
  421. url: /^https?:\/\/ja\.wikipedia\.org\/(wiki\/|w\/index\.php\?search=)/,
  422. enabled: true,
  423. engineList: "资料",
  424. style: '\
  425. border-top:1px solid #D9E1F7;\
  426. border-bottom:1px solid #D9E1F7;\
  427. margin-top:5px;\
  428. ',
  429. insertIntoDoc: {
  430. keyword: function () {
  431. if(document.getElementById('searchText'))
  432. return document.getElementById('searchText').value;
  433. else return document.getElementById('firstHeading').childNodes[0].textContent;
  434. },
  435. target: 'css;#siteNotice',
  436. where: 'beforeBegin'
  437. }
  438. },
  439. {
  440. name: "百度知道(search)",
  441. url: /^https?:\/\/zhidao\.baidu\.com\/search/,
  442. enabled: true,
  443. engineList: "资料",
  444. style: '\
  445. margin-bottom: 8px;\
  446. ',
  447. insertIntoDoc: {
  448. keyword: 'css;input#kw',
  449. target: 'css;#body',
  450. where: 'beforeBegin'
  451. },
  452. },
  453. {
  454. name: "百度知道(question)",
  455. url: /^https?:\/\/zhidao\.baidu\.com\/question/,
  456. enabled: true,
  457. engineList: "资料",
  458. style: '\
  459. width: 980px;\
  460. margin: 0 auto;\
  461. white-space: nowrap;\
  462. ',
  463. insertIntoDoc: {
  464. keyword: function() {
  465. return document.querySelector('#kw').value;
  466. },
  467. target: 'css;#body',
  468. where: 'beforeBegin'
  469. },
  470. endFix: function() { // 插入搜索条后修正绿色背景错位的问题
  471. var container = document.getElementById('sej-container');
  472. if (container && document.body.classList.contains('has-menu')) {
  473. document.body.style.backgroundPosition = '0px ' + ( 95 + container.clientHeight ) + 'px';
  474. }
  475. },
  476. },
  477. {
  478. name: "知乎",
  479. url: /^https?:\/\/www\.zhihu\.com\/search\?/,
  480. enabled: true,
  481. engineList: "资料",
  482. style: '\
  483. border-bottom:1px solid #D9E1F7;\
  484. margin: 0 auto;\
  485. ',
  486. insertIntoDoc: {
  487. keyword: 'css;input#q',
  488. target: 'css;.zu-top',
  489. where: 'afterEnd'
  490. },
  491. },
  492. {
  493. name: "百度文库",
  494. url: /^https?:\/\/wenku\.baidu\.com\/search\?/,
  495. enabled: true,
  496. engineList: "资料",
  497. style: '\
  498. border-top:1px solid #D9E1F7;\
  499. border-bottom:1px solid #D9E1F7;\
  500. ',
  501. insertIntoDoc: {
  502. keyword: 'css;input#kw',
  503. target: 'css;#hd',
  504. where: 'afterEnd'
  505. }
  506. },
  507. {
  508. name: "豆丁",
  509. url: /^https?:\/\/www\.docin\.com\/search\.do/,
  510. enabled: true,
  511. engineList: "资料",
  512. style: '\
  513. margin:0 auto;\
  514. padding-top:65px;\
  515. border-top:1px solid #00000;\
  516. border-bottom:1px solid #D9E1F7;\
  517. ',
  518. insertIntoDoc: {
  519. keyword: 'css;input#topsearch',
  520. target: 'css;.nav',
  521. where: 'beforeBegin'
  522. }
  523. },
  524. // 地图
  525. {
  526. name: "百度地图",
  527. url: /^https?:\/\/map\.baidu\.com\/\?newmap/,
  528. enabled: true,
  529. engineList: "map",
  530. style: '\
  531. margin-left:20px;\
  532. border-top:1px solid #00000;\
  533. border-bottom:1px solid #D9E1F7;\
  534. ',
  535. insertIntoDoc: {
  536. keyword: 'css;input#PoiSearch',
  537. target: 'css;#searchWrapper',
  538. where: 'beforeEnd'
  539. }
  540. },
  541. {
  542. name: "google地图",
  543. url: /^https?:\/\/www\.google\.co.{1,4}\/maps/,
  544. enabled: true,
  545. engineList: "map",
  546. style: '\
  547. margin-top: 3px;\
  548. ',
  549. insertIntoDoc: {
  550. keyword: 'css;input#searchboxinput',
  551. target: 'css;#omnibox',
  552. where: 'beforeEnd'
  553. },
  554. stylish:'.widget-pane-section-omnibox-spacer{height:90px !important;} .sej-drop-list-trigger{display:none;}',
  555. },
  556. {
  557. name: "搜狗地图",
  558. url: /^https?:\/\/map\.sogou\.com\/#/,
  559. enabled: true,
  560. engineList: "map",
  561. style: '\
  562. padding-left:15px;\
  563. display:block;\
  564. border-top:1px solid #00000;\
  565. border-bottom:1px solid #D9E1F7;\
  566. word-break:keep-all;\
  567. white-space:nowrap;\
  568. ',
  569. insertIntoDoc: {
  570. keyword: 'css;input#query',
  571. target: 'css;#search_form',
  572. where: 'afterEnd'
  573. },
  574. stylish: '.sej-drop-list-trigger {display:none;}'
  575. },
  576. {
  577. name: "Bing地图",
  578. url: /^https?:\/\/[^.]*\.bing\.com\/ditu\//,
  579. enabled: true,
  580. engineList: "map",
  581. style: '\
  582. display: inline-block;\
  583. margin-left:15px;\
  584. border-top:1px solid #00000;\
  585. border-bottom:1px solid #D9E1F7;\
  586. word-break:keep-all;\
  587. white-space:nowrap;\
  588. ',
  589. insertIntoDoc: {
  590. keyword: 'css;input#sb_form_q',
  591. target: 'css;#sw_content',
  592. where: 'beforeBegin'
  593. }
  594. },
  595. // 音乐
  596. {
  597. name: "天天动听",
  598. url: /^https?:\/\/www\.dongting\.com\/#/,
  599. enabled: true,
  600. engineList: "music",
  601. style: "\
  602. margin-left:23%;\
  603. background-color:#E2E2E2;\
  604. position: fixed;\
  605. right:0;\
  606. ",
  607. insertIntoDoc: {
  608. keyword: 'css;.searchBox',
  609. target: 'css;.head',
  610. where: 'beforeEnd'
  611. }
  612. },
  613. {
  614. name: "百度音乐",
  615. url: /^https?:\/\/music\.baidu\.com\/search/,
  616. enabled: true,
  617. engineList: "music",
  618. style: "\
  619. margin:0 auto;\
  620. ",
  621. insertIntoDoc: {
  622. keyword: 'css;#ww',
  623. target: 'css;.nav-wrapper',
  624. where: 'beforeBegin'
  625. }
  626. },
  627. {
  628. name: "qq音乐",
  629. url: /^https?:\/\/cgi\.music\.soso\.com/,
  630. enabled: true,
  631. engineList: "music",
  632. style: "\
  633. margin:2px auto;\
  634. ",
  635. insertIntoDoc: {
  636. keyword: 'css;#search_input',
  637. target: 'css;#search_result',
  638. where: 'beforeBegin'
  639. }
  640. },
  641. {
  642. name: "搜狗音乐",
  643. url: /^https?:\/\/mp3\.sogou\.com\/music\.so/,
  644. enabled: true,
  645. engineList: "music",
  646. style: "\
  647. margin:0 auto;\
  648. ",
  649. insertIntoDoc: {
  650. keyword: 'css;#queryinput',
  651. target: 'css;#header_sogou',
  652. where: 'afterEnd'
  653. }
  654. },
  655. {
  656. name: "音悦台",
  657. url: /^https?:\/\/so\.yinyuetai\.com\/mv\?/,
  658. enabled: true,
  659. engineList: "music",
  660. style: "\
  661. margin:0 auto;\
  662. ",
  663. insertIntoDoc: {
  664. keyword: 'css;input[name="keyword"]',
  665. target: 'css;.search_title',
  666. where: 'beforeBegin'
  667. },
  668. },
  669. {
  670. name: "一听音乐",
  671. url: /^https?:\/\/so\.1ting\.com\//,
  672. enabled: true,
  673. engineList: "music",
  674. style: "\
  675. margin:0 auto;\
  676. width: 960px;\
  677. ",
  678. insertIntoDoc: {
  679. keyword: 'css;#keyword',
  680. target: 'css;.nav',
  681. where: 'beforeBegin'
  682. }
  683. },
  684. {
  685. name: "songtaste",
  686. url: /^https?:\/\/www\.songtaste\.com\/search/,
  687. enabled: true,
  688. engineList: "music",
  689. style: "\
  690. margin:0 auto;\
  691. word-break:keep-all;\
  692. white-space:nowrap;\
  693. background-color:#E6E6E6;\
  694. ",
  695. insertIntoDoc: {
  696. keyword: 'css;#sb',
  697. target: 'css;head',
  698. where: 'beforeBegin'
  699. }
  700. },
  701. {
  702. name: "xiami",
  703. url: /^https?:\/\/www\.xiami\.com\/search/,
  704. enabled: true,
  705. engineList: "music",
  706. style: "\
  707. word-break:keep-all;\
  708. margin-right: 205px;\
  709. ",
  710. insertIntoDoc: {
  711. keyword: 'css;#search_text',
  712. target: 'css;.more_cols_left_inner',
  713. where: 'beforeBegin'
  714. }
  715. },
  716.  
  717. // 图片
  718. {
  719. name: "谷歌图片",
  720. url: /^https?:\/\/\w{2,10}\.google(?:\.\D{1,3}){1,2}\/search\?(.*tbs=sbi)|(.*tbm=isch)/,
  721. enabled: true,
  722. engineList: "image",
  723. style: '\
  724. border-top:1px solid #ccc;\
  725. border-bottom:1px solid #ccc;\
  726. ',
  727. insertIntoDoc: {
  728. keyword: 'css;input[name=q]',
  729. target: 'css;#top_nav',
  730. where: 'beforeBegin'
  731. }
  732. },
  733. {
  734. name: "百度图片",
  735. url: /^https?:\/\/image\.baidu\.c(om|n)\/search/,
  736. enabled: true,
  737. engineList: "image",
  738. style: '\
  739. margin-left:40px;\
  740. ',
  741. insertIntoDoc: {
  742. keyword: 'css;input#kw',
  743. target: 'css;#search',
  744. where: 'afterEnd'
  745. }
  746. },
  747. {
  748. name: "360图片",
  749. url: /^https?:\/\/\image\.so\.com\/i\?/,
  750. enabled: true,
  751. engineList: "image",
  752. style: '\
  753. word-break:keep-all;\
  754. white-space:nowrap;\
  755. position:relative;\
  756. z-index:50;\
  757. text-align:left;\
  758. ',
  759. insertIntoDoc: {
  760. keyword: 'css;input#search_kw',
  761. target: 'css;#searchBox',
  762. where: 'afterBegin'
  763. },
  764. etc: function() {
  765. document.getElementById("searchBox").style.height = '80px';
  766. }
  767. },
  768. {
  769. name: "bing图片",
  770. url: /^https?:\/\/.*\.bing\.com\/images\/search/,
  771. enabled: true,
  772. engineList: "image",
  773. style: '\
  774. top:-5px;\
  775. margin-left:5px;\
  776. border-collapse:separate;\
  777. ',
  778. insertIntoDoc: {
  779. keyword: 'css;#sb_form_q',
  780. target: 'css;#rfPane',
  781. where: 'beforeEnd'
  782. },
  783. etc: function() {
  784. document.getElementById("rf_hold").style.height = '120px';
  785. }
  786. },
  787. {
  788. name: "搜狗图片",
  789. url: /^https?:\/\/pic\.sogou\.com\/pic/,
  790. engineList: "image",
  791. enabled: true,
  792. style: "\
  793. top:-9px;\
  794. border-top:1px solid #BFBDEA;\
  795. border-bottom:1px solid #BFBDEA;\
  796. ",
  797. insertIntoDoc: {
  798. keyword: 'css;#form_querytext',
  799. target: 'css;.fix_area',
  800. where: 'beforeEnd'
  801. },
  802. etc: function() {
  803. document.getElementsByClassName("hd_fix")[0].style.height = '130px';
  804. document.getElementsByClassName("hd_fix")[0].nextElementSibling.style.height = '130px';
  805. }
  806. },
  807. {
  808. name: "有道图片",
  809. url: /^https?:\/\/image\.youdao\.com\/search/,
  810. engineList: "image",
  811. enabled: true,
  812. style: "\
  813. ",
  814. insertIntoDoc: {
  815. keyword: 'css;#query',
  816. target: 'css;#w',
  817. where: 'beforeBegin'
  818. }
  819. },
  820. {
  821. name: "花瓣",
  822. url: /^https?:\/\/huaban\.com\/search\/\?/,
  823. engineList: "image",
  824. enabled: true,
  825. style: "\
  826. width:100%;\
  827. background-color:#FFFFFF;\
  828. text-align:center;\
  829. ",
  830. insertIntoDoc: {
  831. keyword: 'css;#query',
  832. target: 'css;#header',
  833. where: 'beforeEnd'
  834. },
  835. stylish:'#page{padding-top: 75px;}',
  836. },
  837. {
  838. name: "flickr",
  839. url: /^https?:\/\/www\.flickr\.com\/search/,
  840. engineList: "image",
  841. enabled: true,
  842. style: "\
  843. position:fixed;\
  844. text-align:center;\
  845. top:65px;\
  846. left: 50%;\
  847. transform: translate(-50%, -50%);\
  848. width:auto;\
  849. z-index:1999;\
  850. background-color:#FFFFFF;\
  851. border-top:1px solid #EBF1FF;\
  852. border-bottom:1px solid #EBF1FF;\
  853. ",
  854. insertIntoDoc: {
  855. keyword: function() {
  856. var input = document.getElementById("gn-search-field");
  857. if (input) return input.value;
  858. else {
  859. var m = location.search.match(/q=([^&]+)/i);
  860. if (m) return true;
  861. }
  862. },
  863. target: 'css;body',
  864. where: 'beforeBegin'
  865. },
  866. endFix: function() {
  867. var container = document.getElementById('sej-container');
  868. if (container) {
  869. var height = (container.clientHeight + 3);
  870. document.getElementsByTagName("section")[0].style.setProperty("top", height + "px", "important");
  871. }
  872. }
  873. },
  874. {
  875. name: "picsearch",
  876. url: /^http:\/\/(..|...)\.picsearch\.com\/index\.cgi/,
  877. engineList: "image",
  878. enabled: true,
  879. style: "\
  880. margin-bottom:3px;\
  881. ",
  882. insertIntoDoc: {
  883. keyword: 'css;input[name=q]',
  884. target: 'css;#content',
  885. where: 'afterBegin'
  886. }
  887. },
  888. {
  889. name: "pixiv",
  890. url: /^http:\/\/www\.pixiv\.net\/search\.php/,
  891. engineList: "image",
  892. enabled: true,
  893. style: "\
  894. margin: 0 auto;\
  895. box-shadow:none;\
  896. ",
  897. insertIntoDoc: {
  898. keyword: 'css;input[name=word]',
  899. target: 'css;body',
  900. where: 'beforeBegin'
  901. }
  902. },
  903. {
  904. name: "deviantart",
  905. url: /^http:\/\/www\.deviantart\.com\/browse\/all\//,
  906. engineList: "image",
  907. enabled: true,
  908. style: "\
  909. margin-bottom:10px;\
  910. ",
  911. insertIntoDoc: {
  912. keyword: 'css;#searchInput',
  913. target: 'css;.browse-top-bar',
  914. where: 'afterEnd'
  915. }
  916. },
  917. {
  918. name: "jpg4",
  919. url: /^http:\/\/img\.jpg4\.info\//,
  920. engineList: "image",
  921. enabled: true,
  922. insertIntoDoc: {
  923. keyword: 'css;input[name="feed"]',
  924. target: 'css;div[align="center"]',
  925. where: 'beforeEnd'
  926. }
  927. },
  928.  
  929. // 下载
  930. {
  931. name: "我爱p2p",
  932. url: /^http:\/\/(?:oabt|www\.byhh)\.org\/\?topic_title=/,
  933. engineList: "下载",
  934. enabled: true,
  935. style: "\
  936. margin: 0 auto;\
  937. padding-left: 16px;\
  938. ",
  939. insertIntoDoc: {
  940. keyword: 'css;#username',
  941. target: 'css;#seamain',
  942. where: 'beforeEnd',
  943. },
  944. },
  945. {
  946. name: "dmhy",
  947. url: /^https?:\/\/share\.dmhy\.org\/topics\/list/,
  948. engineList: "download",
  949. enabled: true,
  950. style: "\
  951. margin:0 auto;\
  952. ",
  953. insertIntoDoc: {
  954. keyword: function(){var key=document.querySelector('#keyword').value;if(key)return key;else key=document.title.split(/「|」/)[1];return key;},
  955. target: 'css;.quick_search',
  956. where: 'afterEnd'
  957. }
  958. },
  959. {
  960. name: "kickass",
  961. url: /^https?:\/\/kat\.cr\/usearch\//,
  962. engineList: "download",
  963. enabled: true,
  964. style: "\
  965. ",
  966. insertIntoDoc: {
  967. keyword: 'css;#contentSearch',
  968. target: 'css;#menu',
  969. where: 'afterEnd'
  970. }
  971. },
  972. {
  973. name: "nyaa.se",
  974. url: /^https?:\/\/www\.nyaa\.se\/\?page/,
  975. engineList: "download",
  976. enabled: true,
  977. style: "\
  978. margin:0 auto;\
  979. top:44px;\
  980. ",
  981. insertIntoDoc: {
  982. keyword: 'css;.inputsearchterm',
  983. target: 'css;#topbar',
  984. where: 'afterEnd'
  985. }
  986. },
  987. {
  988. name: "nyaa.eu",
  989. url: /^https?:\/\/www\.nyaa\.eu\/\?page/,
  990. engineList: "download",
  991. enabled: true,
  992. style: "\
  993. margin:0 auto;\
  994. top:44px;\
  995. ",
  996. insertIntoDoc: {
  997. keyword: 'css;.inputsearchterm',
  998. target: 'css;#topbar',
  999. where: 'afterEnd'
  1000. }
  1001. },
  1002. {
  1003. name: "sukebei.nyaa.se",
  1004. url: /^https?:\/\/sukebei\.nyaa\.se\/\?page/,
  1005. engineList: "download",
  1006. enabled: true,
  1007. style: "\
  1008. margin:0 auto;\
  1009. top:44px;\
  1010. ",
  1011. insertIntoDoc: {
  1012. keyword: 'css;.inputsearchterm',
  1013. target: 'css;#topbar',
  1014. where: 'afterEnd'
  1015. }
  1016. },
  1017. {
  1018. name: "sukebei.nyaa.eu",
  1019. url: /^https?:\/\/sukebei\.nyaa\.eu\/\?page/,
  1020. engineList: "download",
  1021. enabled: true,
  1022. style: "\
  1023. margin:0 auto;\
  1024. top:44px;\
  1025. ",
  1026. insertIntoDoc: {
  1027. keyword: 'css;.inputsearchterm',
  1028. target: 'css;#topbar',
  1029. where: 'afterEnd'
  1030. }
  1031. },
  1032. {
  1033. name: "ed2000",
  1034. url: /^https?:\/\/www\.ed2000\.com\/FileList\.asp/,
  1035. engineList: "download",
  1036. enabled: true,
  1037. style: "\
  1038. border: 1px solid #E5E5E5;\
  1039. ",
  1040. insertIntoDoc: {
  1041. keyword: 'css;input[name=SearchWord]',
  1042. target: 'css;.topsearch',
  1043. where: 'afterEnd'
  1044. },
  1045. },
  1046. {
  1047. name: "bt2mag",
  1048. url: /^https?:\/\/www\.bt2mag\.com\/search\//,
  1049. enabled: true,
  1050. engineList: "download",
  1051. style: '\
  1052. word-break:keep-all;\
  1053. white-space:nowrap;\
  1054. margin:10px auto;\
  1055. ',
  1056. insertIntoDoc: {
  1057. keyword: 'css;.form-inline > div:nth-child(1) > input:nth-child(1)',
  1058. target: 'css;.fullsearch-form.search',
  1059. where: 'afterEnd'
  1060. }
  1061. },
  1062. {
  1063. name: "torrentkitty",
  1064. url: /^https?:\/\/(www\.)?torrentkitty\.(com|org)\/search\//,
  1065. enabled: true,
  1066. engineList: "download",
  1067. style: '\
  1068. border-top:1px solid #FFFFFF;\
  1069. border-bottom:1px solid #FFFFFF;\
  1070. margin:0 auto;\
  1071. margin-top:50px;\
  1072. ',
  1073. insertIntoDoc: {
  1074. keyword: function() {
  1075. return document.getElementsByTagName("h2")[0].innerHTML.slice(19, -1);
  1076. },
  1077. target: 'css;.wrapper',
  1078. where: 'afterEnd'
  1079. }
  1080. },
  1081. {
  1082. name: "BTDigg",
  1083. url: /^https?:\/\/btdigg\.org\/search\?/,
  1084. enabled: true,
  1085. engineList: "download",
  1086. style: '\
  1087. margin:0 auto;\
  1088. border-top:1px solid #D4E9F7;\
  1089. border-bottom:1px solid #D4E9F7;\
  1090. ',
  1091. insertIntoDoc: {
  1092. keyword: 'css;input#searchq',
  1093. target: 'css;.pager',
  1094. where: 'beforeBegin'
  1095. }
  1096. },
  1097.  
  1098. //字幕
  1099. {
  1100. name: "subom",
  1101. url: /^https?:\/\/www\.subom\.net\/search/,
  1102. engineList: "download",
  1103. enabled: true,
  1104. style: "\
  1105. margin: 0px auto;\
  1106. ",
  1107. insertIntoDoc: {
  1108. keyword: 'css;#search_box',
  1109. target: 'css;#container',
  1110. where: 'afterBegin'
  1111. }
  1112. },
  1113. {
  1114. name: "subhd",
  1115. url: /^https?:\/\/subhd\.com\/search/,
  1116. engineList: "download",
  1117. enabled: true,
  1118. style: "\
  1119. text-align:center;\
  1120. display:block;\
  1121. top: -10px;\
  1122. ",
  1123. insertIntoDoc: {
  1124. keyword: 'css;#sn',
  1125. target: 'css;.container.list',
  1126. where: 'beforeBegin'
  1127. }
  1128. },
  1129. {
  1130. name: "射手网(伪)",
  1131. url: /^https?:\/\/sub\.makedie\.me\/sub\/\?searchword/,
  1132. engineList: "download",
  1133. enabled: true,
  1134. style: "\
  1135. text-align:center;\
  1136. margin:0 auto;\
  1137. ",
  1138. insertIntoDoc: {
  1139. keyword: 'css;b',
  1140. target: 'css;#site_header',
  1141. where: 'afterEnd'
  1142. }
  1143. },
  1144. // 购物
  1145. {
  1146. name: "一淘",
  1147. url: /^https?:\/\/s8?\.etao\.com\/search/,
  1148. enabled: true,
  1149. engineList: "shopping",
  1150. style: "\
  1151. border-top:1px solid #D4E9F7;\
  1152. border-bottom:1px solid #D4E9F7;\
  1153. margin:0 auto;\
  1154. word-break:keep-all;\
  1155. white-space:nowrap;\
  1156. ",
  1157. insertIntoDoc: {
  1158. keyword: 'css;#J_searchIpt',
  1159. target: 'css;#etao-header-bd',
  1160. where: 'beforeBegin'
  1161. }
  1162. },
  1163. {
  1164. name: "京东",
  1165. url: /^https?:\/\/search\.jd\.com\/(S|s)earch\?/i,
  1166. enabled: true,
  1167. engineList: "shopping",
  1168. style: "\
  1169. margin:0 auto;\
  1170. border-bottom:1px solid #E5E5E5;\
  1171. border-top:1px solid #E5E5E5;\
  1172. margin-bottom:3px;\
  1173. ",
  1174. insertIntoDoc: {
  1175. keyword: 'css;#key',
  1176. target: 'css;div[id*="nav-201"]',
  1177. where: 'beforeBegin'
  1178. }
  1179. },
  1180. {
  1181. name: "淘宝搜索",
  1182. url: /^https?:\/\/s\.taobao\.com\/search/,
  1183. enabled: true,
  1184. engineList: "shopping",
  1185. style: "\
  1186. width:100%;\
  1187. text-align:center;\
  1188. ",
  1189. insertIntoDoc: {
  1190. keyword: function() {
  1191. var input = document.querySelector('#q');
  1192. if (input) {
  1193. return input.value;
  1194. } else {
  1195. var m = location.search.match(/q=([^&]+)/);
  1196. if (m) {
  1197. return true;
  1198. }
  1199. }
  1200. },
  1201. target: 'css;body',
  1202. where: 'beforeBegin',
  1203. },
  1204. },
  1205. {
  1206. name: "易迅",
  1207. url: /^https?:\/\/searchex\.yixun\.com\/html\?/,
  1208. enabled: true,
  1209. engineList: "shopping",
  1210. style: "\
  1211. text-align: center;\
  1212. background-color:#FFFFFF;\
  1213. ",
  1214. insertIntoDoc: {
  1215. keyword: 'css;#q_show',
  1216. target: 'css;.ic_header',
  1217. where: 'beforeEnd'
  1218. }
  1219. },
  1220. {
  1221. name: "苏宁",
  1222. url: /^https?:\/\/(search)\.suning\.com\//,
  1223. enabled: true,
  1224. engineList: "shopping",
  1225. style: "\
  1226. border-top:1px solid #E5E5E5;\
  1227. margin:0 auto;\
  1228. ",
  1229. insertIntoDoc: {
  1230. keyword: 'css;#searchKeywords',
  1231. target: 'css;.g-header',
  1232. where: 'afterEnd'
  1233. }
  1234. },
  1235. {
  1236. name: "天猫",
  1237. url: /^https?:\/\/list\.tmall\.com\/\/?search/,
  1238. enabled: true,
  1239. engineList: "shopping",
  1240. style: "\
  1241. margin:0 auto;\
  1242. border-bottom:1px solid #E5E5E5;\
  1243. border-top:1px solid #E5E5E5;\
  1244. margin-bottom:3px;\
  1245. ",
  1246. insertIntoDoc: {
  1247. keyword: 'css;#mq',
  1248. target: 'css;#mallNav',
  1249. where: 'beforeBegin'
  1250. }
  1251. },
  1252. {
  1253. name: "亚马逊",
  1254. url: /^https?:\/\/www\.amazon\.cn\/s\/ref/,
  1255. enabled: true,
  1256. engineList: "shopping",
  1257. style: "\
  1258. border-top:1px solid #E5E5E5;\
  1259. ",
  1260. insertIntoDoc: {
  1261. keyword: 'css;#twotabsearchtextbox',
  1262. target: 'css;#navbar',
  1263. where: 'beforeEnd'
  1264. }
  1265. },
  1266. {
  1267. name: "当当",
  1268. url: /^https?:\/\/search\.dangdang\.com\/\?key/,
  1269. enabled: true,
  1270. engineList: "shopping",
  1271. style: "\
  1272. margin:0 auto;\
  1273. border-bottom:1px solid #E5E5E5;\
  1274. border-top:1px solid #E5E5E5;\
  1275. margin-bottom:3px;\
  1276. ",
  1277. insertIntoDoc: {
  1278. keyword: 'css;#key_S',
  1279. target: 'css;#bd',
  1280. where: 'beforeBegin'
  1281. }
  1282. },
  1283. {
  1284. name: "拍拍",
  1285. url: /^https?:\/\/s\.paipai\.com\/[a-z]/,
  1286. enabled: true,
  1287. engineList: "shopping",
  1288. style: "\
  1289. text-align:left;\
  1290. ",
  1291. insertIntoDoc: {
  1292. keyword: 'css;#KeyWord',
  1293. target: 'css;.mod_s',
  1294. where: 'beforeEnd'
  1295. }
  1296. },
  1297. {
  1298. name: "QQ网购",
  1299. url: /^https?:\/\/se?\.wanggou\.com\/[a-z]/,
  1300. enabled: true,
  1301. engineList: "shopping",
  1302. style: "\
  1303. margin:0 auto;\
  1304. background-color:#C8C8C8;\
  1305. border-bottom:1px solid #E5E5E5;\
  1306. border-top:1px solid #E5E5E5;\
  1307. margin-bottom:3px;\
  1308. ",
  1309. insertIntoDoc: {
  1310. keyword: 'css;#KeyWord',
  1311. target: 'css;.wg_header',
  1312. where: 'afterEnd'
  1313. }
  1314. },
  1315. {
  1316. name: "360购物",
  1317. url: /^https?:\/\/s\.mall\.360\.cn\/search/,
  1318. enabled: true,
  1319. engineList: "shopping",
  1320. style: "\
  1321. margin:0 auto;\
  1322. word-break:keep-all;\
  1323. white-space:nowrap;\
  1324. border-bottom:1px solid #E5E5E5;\
  1325. border-top:1px solid #E5E5E5;\
  1326. ",
  1327. insertIntoDoc: {
  1328. keyword: 'css;#mall_keyword',
  1329. target: 'css;.header',
  1330. where: 'afterEnd'
  1331. }
  1332. },
  1333.  
  1334. // 词典
  1335. {
  1336. name: "汉典",
  1337. url: /^https?:\/\/www\.zdic\.net\/sousuo/,
  1338. enabled: true,
  1339. engineList: "etc",
  1340. style: "\
  1341. word-break:keep-all;\
  1342. white-space:nowrap;\
  1343. margin:0 auto;\
  1344. border-bottom:1px solid #D4E9F7;\
  1345. border-top:1px solid #D4E9F7;\
  1346. ",
  1347. insertIntoDoc: {
  1348. keyword: 'css;#q',
  1349. target: 'css;.secpan',
  1350. where: 'afterEnd'
  1351. }
  1352. },
  1353. ];
  1354.  
  1355. if (typeof exports !== 'undefined') {
  1356. exports.rules = rules;
  1357. }
  1358.  
  1359. reloadDebug();
  1360.  
  1361. // --------------------可设置项结束------------------------
  1362.  
  1363. var debug;
  1364.  
  1365. function reloadDebug() {
  1366. debug = prefs.debug ? console.debug.bind(console) : function() {};
  1367. }
  1368.  
  1369. if (typeof String.prototype.startsWith != 'function') {
  1370. String.prototype.startsWith = function(str) {
  1371. return this.slice(0, str.length) == str;
  1372. };
  1373. }
  1374.  
  1375.  
  1376. function getPostFormHTML(url, args, newTab) {// 获取 method 为 POST 的表单的 HTML
  1377. var form = '<form method="post"' +
  1378. ' action="' + url + '"' +
  1379. (newTab ? ' target="_blank"' : '') +
  1380. '>';
  1381. for (var arg in args) {
  1382. var input = '<input type="hidden"' +
  1383. ' name="' + arg + '"' +
  1384. ' value="' + args[arg] + '"' +
  1385. ' />';
  1386. form += input;
  1387. }
  1388. form += '</form>';
  1389. return form;
  1390. }
  1391.  
  1392. function wrapToHide(html) {// 包装 HTML 元素代码以隐藏该元素
  1393. return '<span style="display:none;">' + html + '</span>';
  1394. }
  1395.  
  1396. function toRE(obj) {
  1397. if (obj instanceof RegExp) {
  1398. return obj;
  1399. } else if (obj instanceof Array) {
  1400. return new RegExp(obj[0], obj[1]);
  1401. } else {
  1402. return new RegExp(obj);
  1403. }
  1404. }
  1405.  
  1406. function getMStr(func) {
  1407. var lines = func.toString();
  1408. lines = lines.substring(lines.indexOf("/*") + 3, lines.lastIndexOf("*/"));
  1409. return lines;
  1410. }
  1411. //xpath 获取单个元素
  1412. /*function getElementByXPath(xPath, contextNode, doc) {
  1413. doc = doc || document;
  1414. contextNode = contextNode || doc;
  1415. return doc.evaluate(xPath, contextNode, null, 9, null).singleNodeValue;
  1416. };*/
  1417.  
  1418. // 事件支持检测.
  1419. // 比如 eventSupported('fullscreenchange', document);
  1420. function eventSupported(eventName, elem) {
  1421. elem = elem || document.createElement('div');
  1422. var prefix = ['o', 'ms', 'moz', 'webkit', ''];
  1423.  
  1424. var l = prefix.length;
  1425. var pEventName;
  1426. var isFunction;
  1427. var setAttr;
  1428.  
  1429. while(l --) {
  1430. pEventName = 'on' + prefix[l] + eventName;
  1431.  
  1432. if (pEventName in elem) return pEventName.slice(2);
  1433. else if (typeof elem.setAttribute == 'function') { // setAttribute 是元素节点的方法
  1434. setAttr = false;
  1435. if (!elem.hasAttribute(pEventName)) {
  1436. setAttr = true;
  1437. elem.setAttribute(pEventName, 'return;');
  1438. };
  1439.  
  1440. isFunction = typeof elem[pEventName] == 'function';
  1441.  
  1442. if (setAttr) elem.removeAttribute(pEventName);
  1443.  
  1444. if (isFunction) {
  1445. return pEventName.slice(2);
  1446. };
  1447. };
  1448. };
  1449.  
  1450. return false;
  1451. };
  1452.  
  1453.  
  1454. var data = (function () {// 保存指定对象相关数据
  1455. 'use strict';
  1456.  
  1457. var cache = {
  1458. objs: [],
  1459. data: {},
  1460. };
  1461.  
  1462.  
  1463. function data(obj, key, value) {
  1464. var id = cache.objs.indexOf(obj);
  1465. if (id == -1) {id = cache.objs.push(obj) - 1;};
  1466. if (!cache.data[id])cache.data[id] = {};//初始化
  1467. if (typeof value == 'undefined') {// 取值
  1468. return typeof key == 'undefined' ? cache.data[id] : cache.data[id][key];
  1469. } else {
  1470. return cache.data[id][key] = value;
  1471. };
  1472. };
  1473.  
  1474. return data;
  1475. })();
  1476.  
  1477. // 为mouseleave mouseenter事件做个兼容
  1478. // 需要 eventSupported, data函数支持
  1479. var mouseEventListener = (function () {
  1480.  
  1481. var support = {
  1482. mouseleave : eventSupported('mouseleave'),
  1483. mouseenter : eventSupported('mouseenter'),
  1484. };
  1485.  
  1486. var map = {
  1487. mouseleave : 'mouseout',
  1488. mouseenter : 'mouseover',
  1489. };
  1490.  
  1491. return {
  1492. add : function (type, ele, callback) { //事件类型,元素,监听函数
  1493. if (support[type]) {
  1494. ele.addEventListener(type, callback, false); //mouseleave,enter不冒泡,所以在冒泡阶段监听事件,不要担心子孙元素进出发生的事件冒泡上来。
  1495. } else {
  1496. var listener = data(callback, 'mouseELListener');
  1497. if (!listener) {
  1498. listener = function (e) {
  1499. var relatedTarget = e.relatedTarget; //mouseout,去往的元素;mouseover,来自的元素
  1500. // 当mouseout(离开ele)去往的元素不是自己的子孙元素
  1501. // 当mouseover(进入ele)来自的元素不是自己的子孙元素
  1502. if (!ele.contains(relatedTarget)) { // contains函数,自己.contains(自己) 返回true
  1503. callback.call(ele, e);
  1504. };
  1505. };
  1506. data(callback, 'mouseELListener', listener);
  1507. };
  1508.  
  1509. ele.addEventListener(map[type], listener, true);
  1510. };
  1511. },
  1512. remove : function (type, ele, callback) {
  1513. if (support[type]) {
  1514. ele.removeEventListener(type, callback, false);
  1515. } else {
  1516. ele.removeEventListener(map[type], data(callback, 'mouseELListener'), true);
  1517. };
  1518. },
  1519. };
  1520. })();
  1521.  
  1522.  
  1523. function getScrolled(container) {//获取已滚动的距离
  1524. if (container) {
  1525. return {
  1526. x:container.scrollLeft,
  1527. y:container.scrollTop,
  1528. };
  1529. };
  1530. return {
  1531. x: 'scrollX' in window ? window.scrollX : ('pageXOffset' in window ? window.pageXOffset : document.documentElement.scrollLeft || document.body.scrollLeft),
  1532. y: 'scrollY' in window ? window.scrollY : ('pageYOffset' in window ? window.pageYOffset : document.documentElement.scrollTop || document.body.scrollTop),
  1533. };
  1534. };
  1535.  
  1536. function getElement(selector) {
  1537. if (selector.indexOf('css;') == 0) {
  1538. return document.querySelector(selector.slice(4));
  1539. } else {
  1540. return "";
  1541. };
  1542. };
  1543.  
  1544. function toUTF16(str) { //说是UTF16,但其实是dA专用的,是对转义字符进行编码
  1545. var length = str.length;
  1546. var ret = [];
  1547. var character;
  1548. var charCode;
  1549. var gCode;
  1550. var neReg = /[\dA-z]/;
  1551. for (var i = 0; i < length; i++) {
  1552. charCode = str.charCodeAt(i);
  1553. if (charCode <= 128) {
  1554. character = str.charAt(i);
  1555. if (neReg.test(character)) { /*ascii的数字字母不编码*/
  1556. ret.push(character);
  1557. } else {
  1558. ret.push('%' + charCode.toString(16));
  1559. };
  1560. } else {
  1561. gCode = charCode.toString();
  1562. if (gCode) {
  1563. while (gCode.length < 4) {
  1564. gCode = '0' + gCode;
  1565. };
  1566. ret.push('%26%23' + gCode + '%3B');
  1567. } else {
  1568. /*字库里面没有.*/
  1569. };
  1570. };
  1571. };
  1572. return ret.join('');
  1573. };
  1574.  
  1575.  
  1576. function parseDataStr(str, opt) {// 转换文本数据为 engineList 对象
  1577. if (typeof opt == 'undefined') {
  1578. opt = {};
  1579. }
  1580.  
  1581.  
  1582. str = str.replace(/[\n\r]+[\s\/]*-\s*(\S+):/g, '_POST_ $1:');// 提前处理下特殊的 post 方式
  1583.  
  1584. var parseArgs = function(str) {
  1585. var arr = str.replace(/,/g, ', ').split(/\s*, \s*/);
  1586. var args = {};
  1587. arr.forEach(function(s){
  1588. var argArr = s.split(/\s*: \s*/);
  1589. args[argArr[0]] = argArr[1];
  1590. });
  1591. return args;
  1592. };
  1593.  
  1594. var isEncoding = function(str) {
  1595. str = str.trim().toLowerCase();
  1596. return ['utf-8', 'gb', 'utf16'].some(function(e) {
  1597. return str.indexOf(e) == 0;
  1598. });
  1599. };
  1600.  
  1601. var parseLine = function (line) {
  1602. line = line.trim();
  1603.  
  1604. if (!line) return;
  1605.  
  1606. if (line.indexOf('//') == 0) {
  1607. if (opt.commentLine) line = line.replace(/^\/\/\s*/, '');// 包含注释行
  1608. else return;
  1609. }
  1610.  
  1611. var engine = {};
  1612.  
  1613. if (line.indexOf('_POST_') != -1) {
  1614. engine.method = 'POST';
  1615. var two = line.split(/\s*_POST_\s*/);
  1616. line = two[0];
  1617. engine.args = parseArgs(two[1]);
  1618. }
  1619.  
  1620. var arr = line.replace(/,/g, ', ').split(/\s*, \s*/);
  1621. if (arr.length === 1) { // 分类
  1622. return line;
  1623. }
  1624.  
  1625. engine.name = arr[0];
  1626. engine.url = arr[1];
  1627. engine.host = parseUri(engine.url).host;
  1628.  
  1629. // 处理编码和图标
  1630. if (arr[2] && isEncoding(arr[2])) {
  1631. engine.encoding = arr[2];
  1632. engine.favicon = arr[3];
  1633. } else {
  1634. engine.favicon = arr[2];
  1635. }
  1636.  
  1637. if (!engine.favicon) {
  1638. engine.favicon = getFaviconUrl(engine.url, opt.iconType);
  1639. }
  1640.  
  1641. return engine;
  1642. };
  1643.  
  1644. var list = {},
  1645. type;
  1646.  
  1647. str.split(/[\n\r]+/).forEach(function(line){
  1648. var engine = parseLine(line);
  1649. if (!engine) {
  1650. return;
  1651. }
  1652.  
  1653. if (typeof engine === 'string') {
  1654. type = line.trim();
  1655. list[type] = [];
  1656. } else list[type].push(engine);
  1657. });
  1658.  
  1659. return list;
  1660. }
  1661.  
  1662. function getFaviconUrl(url, type) {
  1663. var uri = parseUri(url);
  1664. switch(type) {
  1665. case 0:
  1666. return 'https://www.google.com/s2/favicons?domain=' + uri.host;
  1667. default:
  1668. return uri.protocol + '://' + uri.host + '/favicon.ico';
  1669. }
  1670. }
  1671.  
  1672. // parseUri 1.2.2
  1673. // (c) Steven Levithan <stevenlevithan.com>
  1674. // MIT License
  1675. var parseUri = function(str) {
  1676. var o = parseUri.options,
  1677. m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
  1678. uri = {},
  1679. i = 14;
  1680.  
  1681. while (i--) uri[o.key[i]] = m[i] || "";
  1682.  
  1683. uri[o.ds.name] = {};
  1684. uri[o.ds.name][0] = {};
  1685. uri[o.ds.name][0]['key'] = (uri.protocol ? uri.protocol : 'http') + '://' + uri.host + (uri.port ? ':' + uri.port : '') + '/';
  1686. uri[o.ds.name][0]['val'] = '/';
  1687. var i = 0,
  1688. tempsub = '/',
  1689. subs = uri[o.key[10]].substr(1).split('/');
  1690. for (var j = 1; j < (subs.length + 1); j++, i++) {
  1691. tempsub += tempsub === '/' ? subs[i] : '/' + subs[i];
  1692. if (subs[i]) {
  1693. uri[o.ds.name][j] = {};
  1694. uri[o.ds.name][j]['key'] = subs[i];
  1695. uri[o.ds.name][j]['val'] = tempsub;
  1696. }
  1697. }
  1698.  
  1699. uri[o.q.name] = {};
  1700. uri[o.key[12]].replace(o.q.parser, function($0, $1, $2) {
  1701. if ($1) uri[o.q.name][$1] = $2;
  1702. });
  1703. uri[o.aq.name] = {};
  1704. uri[o.key[13]].replace(o.aq.parser, function($0, $1, $2) {
  1705. if ($1) uri[o.aq.name][$1] = $2;
  1706. });
  1707.  
  1708. return uri;
  1709. };
  1710. parseUri.options = {
  1711. strictMode: false,
  1712. key: ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"],
  1713. q: {
  1714. name: "queryKey",
  1715. parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  1716. },
  1717. aq: {
  1718. name: "anchorqueryKey",
  1719. parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  1720. },
  1721. ds: {
  1722. name: "directorySub"
  1723. },
  1724. parser: {
  1725. strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
  1726. loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
  1727. }
  1728. };
  1729.  
  1730. if (typeof exports !== 'undefined') {
  1731. exports.parseDataStr = parseDataStr;
  1732. exports.parseUri = parseUri;
  1733. }
  1734.  
  1735. function DropDownList(a, list) {// 列表对象
  1736. this.a = a;
  1737. this.list = list;
  1738. this.init();
  1739. };
  1740. DropDownList.zIndex = 100000000;
  1741.  
  1742. DropDownList.prototype = {
  1743. hidden: true,
  1744. showDelay: 233,
  1745. hideDelay: 266,
  1746. aShownClass: 'sej-drop-list-trigger-shown',
  1747.  
  1748. init: function () {
  1749. var a = this.a;
  1750. var list = this.list;
  1751. var self = this;
  1752.  
  1753. mouseEventListener.add('mouseenter', a, function () {// 进入显示
  1754. clearTimeout(self.hideTimerId);
  1755.  
  1756. if (self.hidden) {
  1757. self.showTimerId = setTimeout(function () {
  1758. self.show();
  1759. }, self.showDelay);
  1760. } else {
  1761. var style = list.style;
  1762. style.zIndex = DropDownList.zIndex ++;
  1763. style.opacity = 0.96;
  1764. };
  1765. });
  1766.  
  1767. // 离开隐藏
  1768. mouseEventListener.add('mouseleave', a, function () {
  1769. clearTimeout(self.showTimerId);
  1770.  
  1771. if (!self.hidden) {
  1772. list.style.opacity = 0.3;
  1773. self.hideTimerId = setTimeout(function () {
  1774. self.hide();
  1775. }, self.hideDelay);
  1776. };
  1777. });
  1778.  
  1779. mouseEventListener.add('mouseenter', list, function () {
  1780. clearTimeout(self.hideTimerId);
  1781.  
  1782. var style = list.style;
  1783. style.zIndex = DropDownList.zIndex ++;
  1784. style.opacity = 0.96;
  1785. });
  1786.  
  1787. mouseEventListener.add('mouseleave', list, function () {
  1788.  
  1789. list.style.opacity = 0.3;
  1790. self.hideTimerId = setTimeout(function () {
  1791. self.hide();
  1792. }, self.hideDelay);
  1793. });
  1794. },
  1795. show: function () {
  1796. if (!this.hidden) return;
  1797. this.hidden = false;
  1798.  
  1799. var scrolled = getScrolled();
  1800. var aBCRect = this.a.getBoundingClientRect();
  1801.  
  1802. var style = this.list.style;
  1803.  
  1804. var top, left;
  1805. if (this.a.dataset.horizontal) { // 向右展开
  1806. top = scrolled.y + aBCRect.top;
  1807. left = scrolled.x + aBCRect.left + this.a.clientWidth;
  1808. } else { // 默认的向下展开
  1809. top = scrolled.y + aBCRect.bottom;
  1810. left = scrolled.x + aBCRect.left;
  1811. }
  1812.  
  1813. left=left-25;//使用居中样式的调整
  1814. style.top = top + 6 + 'px';
  1815. style.left = left + 'px';
  1816. style.zIndex = DropDownList.zIndex ++;
  1817. style.display = 'block';
  1818.  
  1819. setTimeout(function () {
  1820. style.opacity = 0.96;
  1821. style.top = top + 'px';
  1822. }, 30);
  1823.  
  1824. this.a.classList.add(this.aShownClass);
  1825.  
  1826. },
  1827. hide: function () {
  1828. if (this.hidden) return;
  1829. this.hidden = true;
  1830.  
  1831. var style = this.list.style;
  1832. style.display = 'none';
  1833. style.opacity = 0.3;
  1834.  
  1835. this.a.classList.remove(this.aShownClass);
  1836.  
  1837. },
  1838. };
  1839.  
  1840. function addGlobalStyle() {
  1841. // 添加全局样式和自定义样式
  1842. var style = document.getElementById('sej-style');
  1843. if (!style) {
  1844. style = document.createElement('style');
  1845. style.id = 'sej-style';
  1846. style.type = 'text/css';
  1847. style.textContent = MAIN_CSS + '\n' + (matchedRule.stylish || '');
  1848. document.head.appendChild(style);
  1849. }
  1850. }
  1851.  
  1852. function addContainer(iTarget, iInput) {
  1853. var pageEncoding = (document.characterSet || document.charset).toLowerCase();
  1854. // 创建dom
  1855. var aPattern = '<a href="" class="sej-engine"' + (prefs.openInNewTab ? ' target="_blank" ' : ' ') +
  1856. 'encoding="$encoding$" url="$url$" onclick="$onclick$" _title="$title$">' +
  1857. '<img src="$favicon$" class="sej-engine-icon" />$form$<span>$name$</span></a>';
  1858.  
  1859. var container = document.createElement('sejspan');
  1860. container.id = 'sej-container';
  1861.  
  1862. container.addEventListener('mousedown', mousedownhandler, true);
  1863. if (matchedRule.style) {
  1864. container.style.cssText = matchedRule.style;
  1865. }
  1866.  
  1867. var dropLists = [];
  1868.  
  1869. // 根据搜索列表的类型得到数据
  1870. var engineListDataStr = engineListData[prefs.engineListDataType] || engineListData.normal;
  1871. var allEngineList = parseDataStr(engineListDataStr);
  1872. var isFirstDropList = true;
  1873. var isMatched = false; // 当前搜索只匹配一次
  1874.  
  1875. Object.keys(allEngineList).forEach(function (categoryStr) {
  1876. var categoryArr = categoryStr.split('-');
  1877.  
  1878. var category = {
  1879. str: categoryStr,
  1880. name: categoryArr[0],
  1881. icon: categoryArr[1],
  1882. insert: categoryArr[2]
  1883. };
  1884.  
  1885. var engines = [];
  1886.  
  1887. var engineList = allEngineList[categoryStr];
  1888. engineList.forEach(function (engine) {
  1889. if (matchedRule.engineList && !isMatched && toRE(matchedRule.url).test(engine.url)) { // 去掉跳转到当前引擎的引擎
  1890. isMatched = true; // 去除当前搜索只匹配一次
  1891. return;
  1892. }
  1893.  
  1894. var a = aPattern.replace('$encoding$', (engine.encoding || 'utf-8').toLowerCase())
  1895. .replace('$url$', engine.url)
  1896. .replace('$name$', engine.name)
  1897. .replace('$title$', engine.name);
  1898. if (engine.favicon) {
  1899. a = a.replace('$favicon$', engine.favicon);
  1900. } else {
  1901. a = a.replace('src="$favicon$"', '');
  1902. }
  1903.  
  1904. if (engine.method && engine.method.toUpperCase() == 'POST') {
  1905. var f = wrapToHide(getPostFormHTML(engine.url, engine.args, prefs.openInNewTab));
  1906. a = a.replace('$form$', f);
  1907. a = a.replace('$onclick$', "this.getElementsByTagName('form')[0].submit();return false;");
  1908. } else {
  1909. a = a.replace('$form$', '');
  1910. a = a.replace('onclick="$onclick$"', '');
  1911. }
  1912.  
  1913. engines.push(a);
  1914. });
  1915.  
  1916. // 非空列表
  1917. if (!engines.length) return;
  1918.  
  1919. // 插入一个节点给 insertBefore 用
  1920. var lastInsertTitle = category.name;
  1921. engines = engines.join('') + '<span class="sej-engine" _title="' + lastInsertTitle + '" style="display: none;"></span>';
  1922.  
  1923. if (isTheSameCategory(category.name, matchedRule.engineList)) {
  1924. container.innerHTML = '<sejspan id="sej-expanded-category">'+ category.name +'</sejspan>' + engines;
  1925. } else {
  1926. var dropList = document.createElement('sejspan');
  1927. dropList.className = 'sej-drop-list';
  1928. dropList.innerHTML = engines;
  1929.  
  1930. // 有子 droplist
  1931. var a = dropList.firstElementChild.cloneNode(true);
  1932. a.className = a.className + ' sej-drop-list-trigger';
  1933. a.lastChild.textContent = category.name;
  1934.  
  1935. // 更改图标
  1936. if (category.icon) {
  1937. var e = engineList[category.icon - 1];
  1938. if (e && e.favicon) { // 数字匹配
  1939. a.firstChild.src = e.favicon;
  1940. } else { // 名称匹配
  1941. for (var i = 0; i < engineList.length; i++) {
  1942. if (engineList[i].name == category.icon) {
  1943. a.firstChild.src = engineList[i].favicon;
  1944. break;
  1945. }
  1946. };
  1947. }
  1948. }
  1949.  
  1950. // 是否为第一个 droplist
  1951. if (isFirstDropList) {
  1952. a.className += ' first';
  1953. isFirstDropList = false;
  1954. }
  1955.  
  1956. // 重新插入的位置
  1957. if (typeof category.insert !== 'undefined') {
  1958. a.dataset.horizontal = true;
  1959. a.dataset.insert = category.insert;
  1960. }
  1961.  
  1962. dropLists.push({
  1963. a: a,
  1964. dropList: dropList
  1965. });
  1966. };
  1967. });
  1968.  
  1969. dropLists.forEach(function (item, index) {
  1970. var a = item.a,
  1971. dropList = item.dropList;
  1972.  
  1973. // 移到某个类别里面
  1974. var ins;
  1975. var insert = a.dataset.insert;
  1976. if (typeof insert !== 'undefined') {
  1977. ins = document.querySelector('.sej-engine[_title="' + insert + '"]:not(.sej-drop-list-trigger)');
  1978. }
  1979.  
  1980. if (ins) {
  1981. ins.parentNode.insertBefore(a, ins);
  1982. } else {
  1983. container.appendChild(a);
  1984. }
  1985.  
  1986. if (a.dataset.horizontal && a.parentNode.id === container.id) { // 如果是顶层,菜单不需要修正
  1987. a.removeAttribute('data-horizontal');
  1988.  
  1989. // 插入到第一个类别前面
  1990. // ins = container.querySelector('a.sej-engine.first');
  1991. ins = container.querySelector('a.sej-engine:not(.sej-drop-list-trigger)');
  1992. ins.parentNode.insertBefore(a, ins);
  1993. }
  1994.  
  1995. if (prefs.position == 'left') { // 如果再左边的话,修正弹出菜单的位置
  1996. a.dataset.horizontal = true;
  1997. }
  1998. document.body.appendChild(dropList);
  1999.  
  2000. dropList.addEventListener('mousedown', mousedownhandler, true);
  2001.  
  2002. new DropDownList(a, dropList);
  2003. });
  2004.  
  2005. var insertWhere = matchedRule.insertIntoDoc.where;// 设置插入的位置
  2006.  
  2007. switch (insertWhere.toLowerCase()) {// 插入到文档中
  2008. case 'beforebegin' :
  2009. iTarget.parentNode.insertBefore(container, iTarget);
  2010. break;
  2011. case 'afterbegin' :
  2012. if (iTarget.firstChild) {
  2013. iTarget.insertBefore(container, iTarget.firstChild);
  2014. } else {
  2015. iTarget.appendChild(container);
  2016. }
  2017. break;
  2018. case 'beforeend' :
  2019. iTarget.appendChild(container);
  2020. break;
  2021. case 'afterend' :
  2022. if (iTarget.nextSibling) {
  2023. iTarget.parentNode.insertBefore(container, iTarget.nextSibling);
  2024. } else {
  2025. iTarget.parentNode.appendChild(container);
  2026. }
  2027. break;
  2028.  
  2029. };
  2030.  
  2031. var isTwoLine = container.clientHeight / container.children[1].clientHeight > 2;
  2032.  
  2033. // 插入后调整下,如果变成两行,隐藏文字
  2034. if (prefs.hideEnglineLabel == 2 || (prefs.hideEnglineLabel == 1 && isTwoLine)) {
  2035. [].forEach.call(document.querySelectorAll('#sej-container > a[class="sej-engine"] > span'), function(span) {
  2036. var link = span.parentNode;
  2037. link.classList.add('only-icon');
  2038. link.setAttribute('title', span.textContent);
  2039. });
  2040. }
  2041.  
  2042. if (typeof matchedRule.endFix == 'function') {
  2043. try {
  2044. matchedRule.endFix();
  2045. } catch(ex) {
  2046. console.error('endFix 错误', ex);
  2047. }
  2048. }
  2049.  
  2050. function mousedownhandler(e) {
  2051. var target = e.target;
  2052. if(!target.href)target = target.parentNode;
  2053.  
  2054. // if (!target || target.className.indexOf('sej-engine') == -1) return;
  2055. if (!target || !this.contains(target)) return;
  2056.  
  2057. var value;
  2058. if (typeof iInput == 'function') value = iInput();
  2059. else {
  2060. if (iInput.nodeName == 'INPUT' || iInput.localName == 'textarea') value = iInput.value;
  2061. else value = iInput.textContent;
  2062. }
  2063.  
  2064. // 根据后代元素中是否存在 form 元素,判断提交方式并进行处理
  2065. // 如果没有 form 元素,将会使用 GET 方法提交;如果有,将会使用 POST 方法提交
  2066. var forms = target.getElementsByTagName('form');
  2067. if (forms.length == 0) { // 提交方式为 GET
  2068. // 处理编码
  2069. var encoding = target.getAttribute('encoding');
  2070. if (encoding == 'utf-8') value = encodeURIComponent(value);
  2071. else if (encoding.indexOf('gb') == 0) console.log('不再收录gbk编码的引擎')
  2072. else if (encoding == 'utf16') value = toUTF16(value);
  2073.  
  2074. target.href = target.getAttribute('url').replace(/%s/g, value); // 替换“全部”关键词
  2075. }
  2076. else{ // 提交方式为 POST
  2077. var inputs = target.getElementsByTagName('input');
  2078. for (var i = 0; i < inputs.length; i++) inputs[i].value = inputs[i].value.replace(/%s/g, value); // // 替换“全部”关键词
  2079. }
  2080. }
  2081. }
  2082.  
  2083. function run() {
  2084. // 百度搜索插入到顶部搜索条下面就会造成页面部分元素的消失,所以需要每个部分都判断下是否存在
  2085. // 判断插入位置和输入框是否存在
  2086. var iTarget = getElement(matchedRule.insertIntoDoc.target);
  2087. var iInput;
  2088. if (typeof matchedRule.insertIntoDoc.keyword == 'function') {
  2089. iInput = matchedRule.insertIntoDoc.keyword;
  2090. if (!iInput()) {
  2091. return;
  2092. }
  2093. } else {
  2094. iInput = getElement(matchedRule.insertIntoDoc.keyword);
  2095. }
  2096. debug('插入的位置为 %o', iTarget);
  2097. debug('匹配的输入框为 %o', iInput);
  2098.  
  2099. if (!iTarget || !iInput) {
  2100. debug('不存在插入的位置或匹配的输入框', iTarget, iInput);
  2101. return;
  2102. }
  2103.  
  2104. addGlobalStyle();
  2105.  
  2106. // 判断是否存在
  2107. var container = document.getElementById('sej-container'),
  2108. sejspan = document.querySelector('sejspan.sej-drop-list');
  2109.  
  2110. if (!container || !sejspan) {
  2111. if (container) {
  2112. container.parentNode.removeChild(container);
  2113. }
  2114. addContainer(iTarget, iInput);
  2115. }
  2116. }
  2117.  
  2118. function remove() {
  2119. var elems = document.querySelectorAll('#sej-container, sejspan.sej-drop-list');
  2120. if (!elems) return;
  2121.  
  2122. [].forEach.call(elems, function(elem) {
  2123. elem.parentNode.removeChild(elem);
  2124. });
  2125. }
  2126.  
  2127. // iframe 禁止加载
  2128. if (window.self != window.top) return;
  2129.  
  2130. var matchedRule;
  2131.  
  2132. rules.some(function (rule) {
  2133. if (toRE(rule.url).test(location.href)) {
  2134. matchedRule = rule;
  2135. if (typeof rule.etc == 'function') {
  2136. try {
  2137. rule.etc();
  2138. } catch(ex) {
  2139. console.error('执行 etc 错误', ex);
  2140. }
  2141. }
  2142. return true;
  2143. };
  2144. });
  2145.  
  2146.  
  2147. debug('匹配的规则为', matchedRule);
  2148.  
  2149. if (!matchedRule || !matchedRule.enabled) return;
  2150.  
  2151. run();
  2152.  
  2153. if (matchedRule.mutationTitle) {
  2154. debug('添加标题节点监视器: title');
  2155.  
  2156. var watch = document.querySelector('title');
  2157. var observer = new MutationObserver(function(mutations){
  2158. debug('标题发生了变化', document.title);
  2159. run();
  2160. });
  2161. observer.observe(watch, {childList: true, subtree: true, characterData: true});
  2162. }
  2163.  
  2164.  
  2165. })()