searchEngineJumpCE-modify by ted423

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

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

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