searchEngineJumpCE-modify by ted423

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

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