searchEngineJumpCE-modify by ted423

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

目前为 2016-12-15 提交的版本,查看 最新版本

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