searchEngineJumpCE-modify by ted423

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

当前为 2016-01-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name searchEngineJumpCE-modify by ted423
  3. // @author NLF && ywzhaiqi
  4. // @contributor ted423
  5. // @description 方便的在各个引擎之间跳转。可自定义搜索列表的 NLF 修改版。
  6. // @version 8.1601.06.1
  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. border-top:1px solid #ccc;\
  674. border-bottom:1px solid #ccc;\
  675. ',
  676. insertIntoDoc: {
  677. keyword: 'css;input[name=q]',
  678. target: 'css;#top_nav',
  679. where: 'beforeBegin'
  680. }
  681. },
  682. {
  683. name: "百度图片",
  684. url: /^https?:\/\/image\.baidu\.c(om|n)\/search/,
  685. enabled: true,
  686. engineList: "image",
  687. style: '\
  688. margin-left:40px;\
  689. ',
  690. insertIntoDoc: {
  691. keyword: 'css;input#kw',
  692. target: 'css;#search',
  693. where: 'afterEnd'
  694. }
  695. },
  696. {
  697. name: "360图片",
  698. url: /^https?:\/\/\image\.so\.com\/i\?/,
  699. enabled: true,
  700. engineList: "image",
  701. style: '\
  702. word-break:keep-all;\
  703. white-space:nowrap;\
  704. position:relative;\
  705. z-index:50;\
  706. text-align:left;\
  707. ',
  708. insertIntoDoc: {
  709. keyword: 'css;input#search_kw',
  710. target: 'css;#searchBox',
  711. where: 'afterBegin'
  712. },
  713. etc: function() {
  714. document.getElementById("searchBox").style.height = '80px';
  715. }
  716. },
  717. {
  718. name: "bing图片",
  719. url: /^https?:\/\/.*\.bing\.com\/images\/search/,
  720. enabled: true,
  721. engineList: "image",
  722. style: '\
  723. top:-5px;\
  724. margin-left:5px;\
  725. border-collapse:separate;\
  726. ',
  727. insertIntoDoc: {
  728. keyword: 'css;#sb_form_q',
  729. target: 'css;#rfPane',
  730. where: 'beforeEnd'
  731. },
  732. etc: function() {
  733. document.getElementById("rf_hold").style.height = '120px';
  734. }
  735. },
  736. {
  737. name: "搜狗图片",
  738. url: /^https?:\/\/pic\.sogou\.com\/pic/,
  739. engineList: "image",
  740. enabled: true,
  741. style: "\
  742. top:-9px;\
  743. border-top:1px solid #BFBDEA;\
  744. border-bottom:1px solid #BFBDEA;\
  745. ",
  746. insertIntoDoc: {
  747. keyword: 'css;#form_querytext',
  748. target: 'css;.fix_area',
  749. where: 'beforeEnd'
  750. },
  751. etc: function() {
  752. document.getElementsByClassName("hd_fix")[0].style.height = '130px';
  753. document.getElementsByClassName("hd_fix")[0].nextElementSibling.style.height = '130px';
  754. }
  755. },
  756. {
  757. name: "有道图片",
  758. url: /^https?:\/\/image\.youdao\.com\/search/,
  759. engineList: "image",
  760. enabled: true,
  761. style: "\
  762. ",
  763. insertIntoDoc: {
  764. keyword: 'css;#query',
  765. target: 'css;#w',
  766. where: 'beforeBegin'
  767. }
  768. },
  769. {
  770. name: "花瓣",
  771. url: /^https?:\/\/huaban\.com\/search\/\?/,
  772. engineList: "image",
  773. enabled: true,
  774. style: "\
  775. width:100%;\
  776. background-color:#FFFFFF;\
  777. text-align:center;\
  778. ",
  779. insertIntoDoc: {
  780. keyword: 'css;#query',
  781. target: 'css;#header',
  782. where: 'beforeEnd'
  783. },
  784. stylish:'#page{padding-top: 75px;}',
  785. },
  786. {
  787. name: "flickr",
  788. url: /^https?:\/\/www\.flickr\.com\/search/,
  789. engineList: "image",
  790. enabled: true,
  791. style: "\
  792. position:fixed;\
  793. text-align:center;\
  794. top:65px;\
  795. left: 50%;\
  796. transform: translate(-50%, -50%);\
  797. width:auto;\
  798. z-index:1999;\
  799. background-color:#FFFFFF;\
  800. border-top:1px solid #EBF1FF;\
  801. border-bottom:1px solid #EBF1FF;\
  802. ",
  803. insertIntoDoc: {
  804. keyword: function() {
  805. var input = document.getElementById("gn-search-field");
  806. if (input) return input.value;
  807. else {
  808. var m = location.search.match(/q=([^&]+)/i);
  809. if (m) return true;
  810. }
  811. },
  812. target: 'css;body',
  813. where: 'beforeBegin'
  814. },
  815. endFix: function() {
  816. var container = document.getElementById('sej-container');
  817. if (container) {
  818. var height = (container.clientHeight + 3);
  819. document.getElementsByTagName("section")[0].style.setProperty("top", height + "px", "important");
  820. }
  821. }
  822. },
  823. {
  824. name: "picsearch",
  825. url: /^http:\/\/(..|...)\.picsearch\.com\/index\.cgi/,
  826. engineList: "image",
  827. enabled: true,
  828. style: "\
  829. margin-bottom:3px;\
  830. ",
  831. insertIntoDoc: {
  832. keyword: 'css;input[name=q]',
  833. target: 'css;#content',
  834. where: 'afterBegin'
  835. }
  836. },
  837. {
  838. name: "pixiv",
  839. url: /^http:\/\/www\.pixiv\.net\/search\.php/,
  840. engineList: "image",
  841. enabled: true,
  842. style: "\
  843. margin: 0 auto;\
  844. box-shadow:none;\
  845. ",
  846. insertIntoDoc: {
  847. keyword: 'css;input[name=word]',
  848. target: 'css;body',
  849. where: 'beforeBegin'
  850. }
  851. },
  852. {
  853. name: "deviantart",
  854. url: /^https?:\/\/www\.deviantart\.com\/browse\/all\//,
  855. engineList: "image",
  856. enabled: true,
  857. style: "\
  858. margin-bottom:10px;\
  859. ",
  860. insertIntoDoc: {
  861. target: 'css;.browse-top-bar',
  862. where: 'afterEnd'
  863. }
  864. },
  865. {
  866. name: "jpg4",
  867. url: /^http:\/\/img\.jpg4\.info\//,
  868. engineList: "image",
  869. enabled: true,
  870. insertIntoDoc: {
  871. target: 'css;form[name="formMAIN"]',
  872. where: 'beforeEnd'
  873. }
  874. },
  875.  
  876. // 下载
  877. {
  878. name: "cili008",
  879. url: /^http:\/\/cili008\.com\/\?topic_title/,
  880. engineList: "下载",
  881. enabled: true,
  882. insertIntoDoc: {
  883. target: 'css;.header-box',
  884. where: 'afterEnd',
  885. },
  886. },
  887. {
  888. name: "dmhy",
  889. url: /^https?:\/\/share\.dmhy\.org\/topics\/list/,
  890. engineList: "download",
  891. enabled: true,
  892. insertIntoDoc: {
  893. keyword: function(){var key=document.querySelector('#keyword').value;if(key)return key;else key=document.title.split(/「|」/)[1];return key;},
  894. target: 'css;.quick_search',
  895. where: 'afterEnd'
  896. }
  897. },
  898. {
  899. name: "kickass",
  900. url: /^https?:\/\/kat\.cr\/usearch\//,
  901. engineList: "download",
  902. enabled: true,
  903. insertIntoDoc: {
  904. target: 'css;#menu',
  905. where: 'afterEnd'
  906. },
  907. },
  908. {
  909. name: "nyaa",
  910. url: /^https?:\/\/www\.nyaa\.(se|eu)\/\?page=search/,
  911. engineList: "download",
  912. enabled: true,
  913. style: "\
  914. top:44px;\
  915. position: fixed;\
  916. left: 50%;\
  917. transform: translate(-50%, 0px);\
  918. white-space: nowrap;\
  919. ",
  920. insertIntoDoc: {
  921. target: 'css;#topbar',
  922. where: 'afterEnd'
  923. },
  924. stylish:'#main{padding-top:70px;}',
  925. },
  926. {
  927. name: "sukebei.nyaa",
  928. url: /^https?:\/\/sukebei\.nyaa\.(se|eu)\/\?page=search/,
  929. engineList: "download",
  930. enabled: true,
  931. style: "\
  932. top:44px;\
  933. position: fixed;\
  934. left: 50%;\
  935. transform: translate(-50%, 0px);\
  936. white-space: nowrap;\
  937. ",
  938. insertIntoDoc: {
  939. target: 'css;#topbar',
  940. where: 'afterEnd'
  941. },
  942. stylish:'#main{padding-top:70px;}',
  943. },
  944. {
  945. name: "xiaohx",
  946. url: /^https?:\/\/www\.xiaohx\.net\/search\?/,
  947. engineList: "download",
  948. enabled: true,
  949. insertIntoDoc: {
  950. target: 'css;.header_box',
  951. where: 'afterEnd'
  952. },
  953. },
  954. {
  955. name: "ed2000",
  956. url: /^https?:\/\/www\.ed2000\.com\/FileList\.asp/,
  957. engineList: "download",
  958. enabled: true,
  959. style: "\
  960. word-break:keep-all;\
  961. white-space:nowrap;\
  962. left: 50%;\
  963. transform: translate(-50%, 0);\
  964. ",
  965. insertIntoDoc: {
  966. target: 'css;.topsearch',
  967. where: 'afterEnd'
  968. },
  969. },
  970. {
  971. name: "bt2mag",
  972. url: /^https?:\/\/www\.bt2mag\.com\/search\//,
  973. enabled: true,
  974. engineList: "download",
  975. style: '\
  976. word-break:keep-all;\
  977. white-space:nowrap;\
  978. margin:10px auto;\
  979. ',
  980. insertIntoDoc: {
  981. target: 'css;.fullsearch-form.search',
  982. where: 'afterEnd'
  983. },
  984. etc: function(){
  985. if(window.location.href.indexOf('%20')!=-1)window.location.href=window.location.href.replace('%20','+');
  986. }
  987. },
  988. {
  989. name: "torrentkitty",
  990. url: /^https?:\/\/(www\.)?torrentkitty\.(net|org)\/search\//,
  991. enabled: true,
  992. engineList: "download",
  993. style: '\
  994. background-color:#FFFFFF;\
  995. margin-top:50px;\
  996. ',
  997. insertIntoDoc: {
  998. keyword: function() {
  999. return document.getElementsByTagName("h2")[0].innerHTML.slice(19, -1);
  1000. },
  1001. target: 'css;.wrapper',
  1002. where: 'afterEnd'
  1003. }
  1004. },
  1005. {
  1006. name: "BTDigg",
  1007. url: /^https?:\/\/btdigg\.org\/search\?/,
  1008. enabled: true,
  1009. engineList: "download",
  1010. insertIntoDoc: {
  1011. target: 'css;.pager',
  1012. where: 'beforeBegin'
  1013. }
  1014. },
  1015.  
  1016. //字幕
  1017. {
  1018. name: "subom",
  1019. url: /^https?:\/\/www\.subom\.net\/search/,
  1020. engineList: "download",
  1021. enabled: true,
  1022. insertIntoDoc: {
  1023. target: 'css;#container',
  1024. where: 'afterBegin'
  1025. }
  1026. },
  1027. {
  1028. name: "subhd",
  1029. url: /^https?:\/\/subhd\.com\/search/,
  1030. engineList: "download",
  1031. enabled: true,
  1032. style: "\
  1033. top: -10px;\
  1034. ",
  1035. insertIntoDoc: {
  1036. target: 'css;.container.list',
  1037. where: 'beforeBegin'
  1038. }
  1039. },
  1040. {
  1041. name: "射手网(伪)",
  1042. url: /^https?:\/\/sub\.makedie\.me\/sub\/\?s/,
  1043. engineList: "download",
  1044. enabled: true,
  1045. insertIntoDoc: {
  1046. target: 'css;#site_header',
  1047. where: 'afterEnd'
  1048. }
  1049. },
  1050. // 购物
  1051. {
  1052. name: "一淘",
  1053. url: /^https?:\/\/s8?\.etao\.com\/search/,
  1054. enabled: true,
  1055. engineList: "shopping",
  1056. insertIntoDoc: {
  1057. target: 'css;#etao-header-bd',
  1058. where: 'beforeBegin'
  1059. }
  1060. },
  1061. {
  1062. name: "京东",
  1063. url: /^https?:\/\/search\.jd\.com\/(S|s)earch\?/i,
  1064. enabled: true,
  1065. engineList: "shopping",
  1066. insertIntoDoc: {
  1067. target: 'css;div[id*="nav-201"]',
  1068. where: 'beforeBegin'
  1069. }
  1070. },
  1071. {
  1072. name: "淘宝搜索",
  1073. url: /^https?:\/\/(s|haosou\.ai)\.taobao\.com\/search/,
  1074. enabled: true,
  1075. change:'runAtComplete',
  1076. engineList: "shopping",
  1077. style: "\
  1078. width:100%;\
  1079. text-align:center;\
  1080. ",
  1081. insertIntoDoc: {
  1082. target: 'css;body',
  1083. where: 'beforeBegin',
  1084. },
  1085. },
  1086. {
  1087. name: "易迅",
  1088. url: /^https?:\/\/searchex\.yixun\.com\/html\?/,
  1089. enabled: true,
  1090. engineList: "shopping",
  1091. style: "\
  1092. text-align: center;\
  1093. background-color:#FFFFFF;\
  1094. ",
  1095. insertIntoDoc: {
  1096. target: 'css;.ic_header',
  1097. where: 'beforeEnd'
  1098. }
  1099. },
  1100. {
  1101. name: "苏宁",
  1102. url: /^https?:\/\/search\.suning\.com\//,
  1103. enabled: true,
  1104. engineList: "shopping",
  1105. style: "\
  1106. border-bottom:1px solid #E5E5E5;\
  1107. ",
  1108. insertIntoDoc: {
  1109. target: 'css;.ng-header',
  1110. where: 'afterEnd'
  1111. }
  1112. },
  1113. {
  1114. name: "天猫",
  1115. url: /^https?:\/\/list\.tmall\.com\/\/?search/,
  1116. enabled: true,
  1117. engineList: "shopping",
  1118. style: "\
  1119. border-top:1px solid #E5E5E5;\
  1120. margin-bottom:3px;\
  1121. ",
  1122. insertIntoDoc: {
  1123. target: 'css;#header',
  1124. where: 'afterEnd'
  1125. }
  1126. },
  1127. {
  1128. name: "亚马逊",
  1129. url: /^https?:\/\/www\.amazon\.cn\/s\/ref/,
  1130. enabled: true,
  1131. engineList: "shopping",
  1132. style: "\
  1133. width: 100%;\
  1134. text-align: center;\
  1135. ",
  1136. insertIntoDoc: {
  1137. target: 'css;#navbar',
  1138. where: 'beforeEnd'
  1139. }
  1140. },
  1141. {
  1142. name: "当当",
  1143. url: /^https?:\/\/search\.dangdang\.com\/\?key/,
  1144. enabled: true,
  1145. engineList: "shopping",
  1146. insertIntoDoc: {
  1147. target: 'css;#bd',
  1148. where: 'beforeBegin'
  1149. }
  1150. },
  1151. {
  1152. name: "拍拍",
  1153. url: /^https?:\/\/(www|duobao)\.paipai\.com\/(list)?\?/,
  1154. enabled: true,
  1155. engineList: "shopping",
  1156. insertIntoDoc: {
  1157. keyword: 'css;input[type="text"]',
  1158. target: 'css;#toTop',
  1159. where: 'afterEnd'
  1160. }
  1161. },
  1162. // 词典
  1163. {
  1164. name: "汉典",
  1165. url: /^https?:\/\/www\.zdic\.net\/sousuo/,
  1166. enabled: true,
  1167. engineList: "etc",
  1168. insertIntoDoc: {
  1169. target: 'css;.secpan',
  1170. where: 'afterEnd'
  1171. }
  1172. },
  1173. ];
  1174.  
  1175. if (typeof exports !== 'undefined') {
  1176. exports.rules = rules;
  1177. }
  1178.  
  1179. reloadDebug();
  1180.  
  1181. // --------------------可设置项结束------------------------
  1182.  
  1183. var debug;
  1184.  
  1185. function reloadDebug() {
  1186. debug = prefs.debug ? console.debug.bind(console) : function() {};
  1187. }
  1188.  
  1189. if (typeof String.prototype.startsWith != 'function') {
  1190. String.prototype.startsWith = function(str) {
  1191. return this.slice(0, str.length) == str;
  1192. };
  1193. }
  1194.  
  1195.  
  1196. function getPostFormHTML(url, args, newTab) {// 获取 method 为 POST 的表单的 HTML
  1197. var form = '<form method="post"' +
  1198. ' action="' + url + '"' +
  1199. (newTab ? ' target="_blank"' : '') +
  1200. '>';
  1201. for (var arg in args) {
  1202. var input = '<input type="hidden"' +
  1203. ' name="' + arg + '"' +
  1204. ' value="' + args[arg] + '"' +
  1205. ' />';
  1206. form += input;
  1207. }
  1208. form += '</form>';
  1209. return form;
  1210. }
  1211.  
  1212. function wrapToHide(html) {// 包装 HTML 元素代码以隐藏该元素
  1213. return '<span style="display:none;">' + html + '</span>';
  1214. }
  1215.  
  1216. function toRE(obj) {
  1217. if (obj instanceof RegExp) {
  1218. return obj;
  1219. } else if (obj instanceof Array) {
  1220. return new RegExp(obj[0], obj[1]);
  1221. } else {
  1222. return new RegExp(obj);
  1223. }
  1224. }
  1225.  
  1226. function getMStr(func) {
  1227. var lines = func.toString();
  1228. lines = lines.substring(lines.indexOf("/*") + 3, lines.lastIndexOf("*/"));
  1229. return lines;
  1230. }
  1231.  
  1232. // 事件支持检测.
  1233. // 比如 eventSupported('fullscreenchange', document);
  1234. function eventSupported(eventName, elem) {
  1235. elem = elem || document.createElement('div');
  1236. var prefix = ['o', 'ms', 'moz', 'webkit', ''];
  1237.  
  1238. var l = prefix.length;
  1239. var pEventName;
  1240. var isFunction;
  1241. var setAttr;
  1242.  
  1243. while(l --) {
  1244. pEventName = 'on' + prefix[l] + eventName;
  1245.  
  1246. if (pEventName in elem) return pEventName.slice(2);
  1247. else if (typeof elem.setAttribute == 'function') { // setAttribute 是元素节点的方法
  1248. setAttr = false;
  1249. if (!elem.hasAttribute(pEventName)) {
  1250. setAttr = true;
  1251. elem.setAttribute(pEventName, 'return;');
  1252. };
  1253.  
  1254. isFunction = typeof elem[pEventName] == 'function';
  1255.  
  1256. if (setAttr) elem.removeAttribute(pEventName);
  1257.  
  1258. if (isFunction) {
  1259. return pEventName.slice(2);
  1260. };
  1261. };
  1262. };
  1263.  
  1264. return false;
  1265. };
  1266.  
  1267.  
  1268. var data = (function () {// 保存指定对象相关数据
  1269. 'use strict';
  1270.  
  1271. var cache = {
  1272. objs: [],
  1273. data: {},
  1274. };
  1275.  
  1276.  
  1277. function data(obj, key, value) {
  1278. var id = cache.objs.indexOf(obj);
  1279. if (id == -1) {id = cache.objs.push(obj) - 1;};
  1280. if (!cache.data[id])cache.data[id] = {};//初始化
  1281. if (typeof value == 'undefined') {// 取值
  1282. return typeof key == 'undefined' ? cache.data[id] : cache.data[id][key];
  1283. } else {
  1284. return cache.data[id][key] = value;
  1285. };
  1286. };
  1287.  
  1288. return data;
  1289. })();
  1290.  
  1291. // 为mouseleave mouseenter事件做个兼容
  1292. // 需要 eventSupported, data函数支持
  1293. var mouseEventListener = (function () {
  1294.  
  1295. var support = {
  1296. mouseleave : eventSupported('mouseleave'),
  1297. mouseenter : eventSupported('mouseenter'),
  1298. };
  1299.  
  1300. var map = {
  1301. mouseleave : 'mouseout',
  1302. mouseenter : 'mouseover',
  1303. };
  1304.  
  1305. return {
  1306. add : function (type, ele, callback) { //事件类型,元素,监听函数
  1307. if (support[type]) {
  1308. ele.addEventListener(type, callback, false); //mouseleave,enter不冒泡,所以在冒泡阶段监听事件,不要担心子孙元素进出发生的事件冒泡上来。
  1309. } else {
  1310. var listener = data(callback, 'mouseELListener');
  1311. if (!listener) {
  1312. listener = function (e) {
  1313. var relatedTarget = e.relatedTarget; //mouseout,去往的元素;mouseover,来自的元素
  1314. // 当mouseout(离开ele)去往的元素不是自己的子孙元素
  1315. // 当mouseover(进入ele)来自的元素不是自己的子孙元素
  1316. if (!ele.contains(relatedTarget)) { // contains函数,自己.contains(自己) 返回true
  1317. callback.call(ele, e);
  1318. };
  1319. };
  1320. data(callback, 'mouseELListener', listener);
  1321. };
  1322.  
  1323. ele.addEventListener(map[type], listener, true);
  1324. };
  1325. },
  1326. remove : function (type, ele, callback) {
  1327. if (support[type]) {
  1328. ele.removeEventListener(type, callback, false);
  1329. } else {
  1330. ele.removeEventListener(map[type], data(callback, 'mouseELListener'), true);
  1331. };
  1332. },
  1333. };
  1334. })();
  1335.  
  1336.  
  1337. function getScrolled(container) {//获取已滚动的距离
  1338. if (container) {
  1339. return {
  1340. x:container.scrollLeft,
  1341. y:container.scrollTop,
  1342. };
  1343. };
  1344. return {
  1345. x: 'scrollX' in window ? window.scrollX : ('pageXOffset' in window ? window.pageXOffset : document.documentElement.scrollLeft || document.body.scrollLeft),
  1346. y: 'scrollY' in window ? window.scrollY : ('pageYOffset' in window ? window.pageYOffset : document.documentElement.scrollTop || document.body.scrollTop),
  1347. };
  1348. };
  1349.  
  1350. function getElement(selector) {
  1351. if (selector.indexOf('css;') == 0) {
  1352. return document.querySelector(selector.slice(4));
  1353. } else {
  1354. return "";
  1355. };
  1356. };
  1357.  
  1358. function toUTF16(str) { //说是UTF16,但其实是dA专用的,是对转义字符进行编码
  1359. var length = str.length;
  1360. var ret = [];
  1361. var character;
  1362. var charCode;
  1363. var gCode;
  1364. var neReg = /[\dA-z]/;
  1365. for (var i = 0; i < length; i++) {
  1366. charCode = str.charCodeAt(i);
  1367. if (charCode <= 128) {
  1368. character = str.charAt(i);
  1369. if (neReg.test(character)) { /*ascii的数字字母不编码*/
  1370. ret.push(character);
  1371. } else {
  1372. ret.push('%' + charCode.toString(16));
  1373. };
  1374. } else {
  1375. gCode = charCode.toString();
  1376. if (gCode) {
  1377. while (gCode.length < 4) {
  1378. gCode = '0' + gCode;
  1379. };
  1380. ret.push('%26%23' + gCode + '%3B');
  1381. } else {
  1382. /*字库里面没有.*/
  1383. };
  1384. };
  1385. };
  1386. return ret.join('');
  1387. };
  1388.  
  1389.  
  1390. function parseDataStr(str, opt) {// 转换文本数据为 engineList 对象
  1391. if (typeof opt == 'undefined') {
  1392. opt = {};
  1393. }
  1394.  
  1395.  
  1396. str = str.replace(/[\n\r]+[\s\/]*-\s*(\S+):/g, '_POST_ $1:');// 提前处理下特殊的 post 方式
  1397.  
  1398. var parseArgs = function(str) {
  1399. var arr = str.replace(/,/g, ', ').split(/\s*, \s*/);
  1400. var args = {};
  1401. arr.forEach(function(s){
  1402. var argArr = s.split(/\s*: \s*/);
  1403. args[argArr[0]] = argArr[1];
  1404. });
  1405. return args;
  1406. };
  1407.  
  1408. var isEncoding = function(str) {
  1409. str = str.trim().toLowerCase();
  1410. return ['utf-8', 'gb', 'utf16'].some(function(e) {
  1411. return str.indexOf(e) == 0;
  1412. });
  1413. };
  1414.  
  1415. var parseLine = function (line) {
  1416. line = line.trim();
  1417.  
  1418. if (!line) return;
  1419.  
  1420. if (line.indexOf('//') == 0) {
  1421. if (opt.commentLine) line = line.replace(/^\/\/\s*/, '');// 包含注释行
  1422. else return;
  1423. }
  1424.  
  1425. var engine = {};
  1426.  
  1427. if (line.indexOf('_POST_') != -1) {
  1428. engine.method = 'POST';
  1429. var two = line.split(/\s*_POST_\s*/);
  1430. line = two[0];
  1431. engine.args = parseArgs(two[1]);
  1432. }
  1433.  
  1434. var arr = line.replace(/,/g, ', ').split(/\s*, \s*/);
  1435. if (arr.length === 1) { // 分类
  1436. return line;
  1437. }
  1438.  
  1439. engine.name = arr[0];
  1440. engine.url = arr[1];
  1441. engine.host = parseUri(engine.url).host;
  1442.  
  1443. // 处理编码和图标
  1444. if (arr[2] && isEncoding(arr[2])) {
  1445. engine.encoding = arr[2];
  1446. engine.favicon = arr[3];
  1447. } else {
  1448. engine.favicon = arr[2];
  1449. }
  1450.  
  1451. if (!engine.favicon) {
  1452. engine.favicon = getFaviconUrl(engine.url, opt.iconType);
  1453. }
  1454.  
  1455. return engine;
  1456. };
  1457.  
  1458. var list = {},
  1459. type;
  1460.  
  1461. str.split(/[\n\r]+/).forEach(function(line){
  1462. var engine = parseLine(line);
  1463. if (!engine) {
  1464. return;
  1465. }
  1466.  
  1467. if (typeof engine === 'string') {
  1468. type = line.trim();
  1469. list[type] = [];
  1470. } else list[type].push(engine);
  1471. });
  1472.  
  1473. return list;
  1474. }
  1475.  
  1476. function getFaviconUrl(url, type) {
  1477. var uri = parseUri(url);
  1478. switch(type) {
  1479. case 0:
  1480. return 'https://www.google.com/s2/favicons?domain=' + uri.host;
  1481. default:
  1482. return uri.protocol + '://' + uri.host + '/favicon.ico';
  1483. }
  1484. }
  1485.  
  1486. // parseUri 1.2.2
  1487. // (c) Steven Levithan <stevenlevithan.com>
  1488. // MIT License
  1489. var parseUri = function(str) {
  1490. var o = parseUri.options,
  1491. m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
  1492. uri = {},
  1493. i = 14;
  1494.  
  1495. while (i--) uri[o.key[i]] = m[i] || "";
  1496.  
  1497. uri[o.ds.name] = {};
  1498. uri[o.ds.name][0] = {};
  1499. uri[o.ds.name][0]['key'] = (uri.protocol ? uri.protocol : 'http') + '://' + uri.host + (uri.port ? ':' + uri.port : '') + '/';
  1500. uri[o.ds.name][0]['val'] = '/';
  1501. var i = 0,
  1502. tempsub = '/',
  1503. subs = uri[o.key[10]].substr(1).split('/');
  1504. for (var j = 1; j < (subs.length + 1); j++, i++) {
  1505. tempsub += tempsub === '/' ? subs[i] : '/' + subs[i];
  1506. if (subs[i]) {
  1507. uri[o.ds.name][j] = {};
  1508. uri[o.ds.name][j]['key'] = subs[i];
  1509. uri[o.ds.name][j]['val'] = tempsub;
  1510. }
  1511. }
  1512.  
  1513. uri[o.q.name] = {};
  1514. uri[o.key[12]].replace(o.q.parser, function($0, $1, $2) {
  1515. if ($1) uri[o.q.name][$1] = $2;
  1516. });
  1517. uri[o.aq.name] = {};
  1518. uri[o.key[13]].replace(o.aq.parser, function($0, $1, $2) {
  1519. if ($1) uri[o.aq.name][$1] = $2;
  1520. });
  1521.  
  1522. return uri;
  1523. };
  1524. parseUri.options = {
  1525. strictMode: false,
  1526. key: ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"],
  1527. q: {
  1528. name: "queryKey",
  1529. parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  1530. },
  1531. aq: {
  1532. name: "anchorqueryKey",
  1533. parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  1534. },
  1535. ds: {
  1536. name: "directorySub"
  1537. },
  1538. parser: {
  1539. strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
  1540. loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
  1541. }
  1542. };
  1543.  
  1544. if (typeof exports !== 'undefined') {
  1545. exports.parseDataStr = parseDataStr;
  1546. exports.parseUri = parseUri;
  1547. }
  1548.  
  1549. function DropDownList(a, list) {// 列表对象
  1550. this.a = a;
  1551. this.list = list;
  1552. this.init();
  1553. };
  1554. DropDownList.zIndex = 100000000;
  1555.  
  1556. DropDownList.prototype = {
  1557. hidden: true,
  1558. showDelay: 233,
  1559. hideDelay: 266,
  1560. aShownClass: 'sej-drop-list-trigger-shown',
  1561.  
  1562. init: function () {
  1563. var a = this.a;
  1564. var list = this.list;
  1565. var self = this;
  1566.  
  1567. mouseEventListener.add('mouseenter', a, function () {// 进入显示
  1568. clearTimeout(self.hideTimerId);
  1569.  
  1570. if (self.hidden) {
  1571. self.showTimerId = setTimeout(function () {
  1572. self.show();
  1573. }, self.showDelay);
  1574. } else {
  1575. var style = list.style;
  1576. style.zIndex = DropDownList.zIndex ++;
  1577. style.opacity = 0.96;
  1578. };
  1579. });
  1580.  
  1581. // 离开隐藏
  1582. mouseEventListener.add('mouseleave', a, function () {
  1583. clearTimeout(self.showTimerId);
  1584.  
  1585. if (!self.hidden) {
  1586. list.style.opacity = 0.3;
  1587. self.hideTimerId = setTimeout(function () {
  1588. self.hide();
  1589. }, self.hideDelay);
  1590. };
  1591. });
  1592.  
  1593. mouseEventListener.add('mouseenter', list, function () {
  1594. clearTimeout(self.hideTimerId);
  1595.  
  1596. var style = list.style;
  1597. style.zIndex = DropDownList.zIndex ++;
  1598. style.opacity = 0.96;
  1599. });
  1600.  
  1601. mouseEventListener.add('mouseleave', list, function () {
  1602.  
  1603. list.style.opacity = 0.3;
  1604. self.hideTimerId = setTimeout(function () {
  1605. self.hide();
  1606. }, self.hideDelay);
  1607. });
  1608. },
  1609. show: function () {
  1610. if (!this.hidden) return;
  1611. this.hidden = false;
  1612.  
  1613. var scrolled = getScrolled();
  1614. var aBCRect = this.a.getBoundingClientRect();
  1615.  
  1616. var style = this.list.style;
  1617.  
  1618. var top, left;
  1619. if (this.a.dataset.horizontal) { // 向右展开
  1620. top = scrolled.y + aBCRect.top;
  1621. left = scrolled.x + aBCRect.left + this.a.clientWidth;
  1622. } else { // 默认的向下展开
  1623. top = scrolled.y + aBCRect.bottom;
  1624. left = scrolled.x + aBCRect.left;
  1625. }
  1626.  
  1627. left=left-25;//使用居中样式的调整
  1628. style.top = top + 6 + 'px';
  1629. style.left = left + 'px';
  1630. style.zIndex = DropDownList.zIndex ++;
  1631. style.display = 'block';
  1632.  
  1633. setTimeout(function () {
  1634. style.opacity = 0.96;
  1635. style.top = top + 'px';
  1636. }, 30);
  1637.  
  1638. this.a.classList.add(this.aShownClass);
  1639.  
  1640. },
  1641. hide: function () {
  1642. if (this.hidden) return;
  1643. this.hidden = true;
  1644.  
  1645. var style = this.list.style;
  1646. style.display = 'none';
  1647. style.opacity = 0.3;
  1648.  
  1649. this.a.classList.remove(this.aShownClass);
  1650.  
  1651. },
  1652. };
  1653.  
  1654. function addGlobalStyle() {
  1655. // 添加全局样式和自定义样式
  1656. var style = document.getElementById('sej-style');
  1657. if (!style) {
  1658. style = document.createElement('style');
  1659. style.id = 'sej-style';
  1660. style.type = 'text/css';
  1661. style.textContent = MAIN_CSS + '\n' + (matchedRule.stylish || '');
  1662. document.head.appendChild(style);
  1663. }
  1664. }
  1665.  
  1666. function addContainer(iTarget, iInput) {
  1667. var pageEncoding = (document.characterSet || document.charset).toLowerCase();
  1668. // 创建dom
  1669. var aPattern = '<a href="" class="sej-engine"' + (prefs.openInNewTab ? ' target="_blank" ' : ' ') +
  1670. 'encoding="$encoding$" url="$url$" onclick="$onclick$" _title="$title$">' +
  1671. '<img src="$favicon$" class="sej-engine-icon" />$form$<span>$name$</span></a>';
  1672.  
  1673. var container = document.createElement('sejspan');
  1674. container.id = 'sej-container';
  1675.  
  1676. container.addEventListener('mousedown', mousedownhandler, true);
  1677. if (matchedRule.style) {
  1678. container.style.cssText = matchedRule.style;
  1679. }
  1680.  
  1681. var dropLists = [];
  1682.  
  1683. // 根据搜索列表的类型得到数据
  1684. var engineListDataStr = engineListData[prefs.engineListDataType] || engineListData.normal;
  1685. var allEngineList = parseDataStr(engineListDataStr);
  1686. var isFirstDropList = true;
  1687. var isMatched = false; // 当前搜索只匹配一次
  1688.  
  1689. Object.keys(allEngineList).forEach(function (categoryStr) {
  1690. var categoryArr = categoryStr.split('-');
  1691.  
  1692. var category = {
  1693. str: categoryStr,
  1694. name: categoryArr[0],
  1695. icon: categoryArr[1],
  1696. insert: categoryArr[2]
  1697. };
  1698.  
  1699. var engines = [];
  1700.  
  1701. var engineList = allEngineList[categoryStr];
  1702. engineList.forEach(function (engine) {
  1703. if (matchedRule.engineList && !isMatched && toRE(matchedRule.url).test(engine.url)) { // 去掉跳转到当前引擎的引擎
  1704. isMatched = false; // 去除当前搜索只匹配一次
  1705. return;
  1706. }
  1707.  
  1708. var a = aPattern.replace('$encoding$', (engine.encoding || 'utf-8').toLowerCase())
  1709. .replace('$url$', engine.url)
  1710. .replace('$name$', engine.name)
  1711. .replace('$title$', engine.name);
  1712. if (engine.favicon) {
  1713. a = a.replace('$favicon$', engine.favicon);
  1714. } else {
  1715. a = a.replace('src="$favicon$"', '');
  1716. }
  1717.  
  1718. if (engine.method && engine.method.toUpperCase() == 'POST') {
  1719. var f = wrapToHide(getPostFormHTML(engine.url, engine.args, prefs.openInNewTab));
  1720. a = a.replace('$form$', f);
  1721. a = a.replace('$onclick$', "this.getElementsByTagName('form')[0].submit();return false;");
  1722. } else {
  1723. a = a.replace('$form$', '');
  1724. a = a.replace('onclick="$onclick$"', '');
  1725. }
  1726.  
  1727. engines.push(a);
  1728. });
  1729.  
  1730. // 非空列表
  1731. if (!engines.length) return;
  1732.  
  1733. // 插入一个节点给 insertBefore 用
  1734. var lastInsertTitle = category.name;
  1735. engines = engines.join('') + '<span class="sej-engine" _title="' + lastInsertTitle + '" style="display: none;"></span>';
  1736.  
  1737. if (isTheSameCategory(category.name, matchedRule.engineList)) {
  1738. container.innerHTML = '<sejspan id="sej-expanded-category">'+ category.name +'</sejspan>' + engines;
  1739. } else {
  1740. var dropList = document.createElement('sejspan');
  1741. dropList.className = 'sej-drop-list';
  1742. dropList.innerHTML = engines;
  1743.  
  1744. // 有子 droplist
  1745. var a = dropList.firstElementChild.cloneNode(true);
  1746. a.className = a.className + ' sej-drop-list-trigger';
  1747. a.lastChild.textContent = category.name;
  1748.  
  1749. // 更改图标
  1750. if (category.icon) {
  1751. var e = engineList[category.icon - 1];
  1752. if (e && e.favicon) { // 数字匹配
  1753. a.firstChild.src = e.favicon;
  1754. } else { // 名称匹配
  1755. for (var i = 0; i < engineList.length; i++) {
  1756. if (engineList[i].name == category.icon) {
  1757. a.firstChild.src = engineList[i].favicon;
  1758. break;
  1759. }
  1760. };
  1761. }
  1762. }
  1763.  
  1764. // 是否为第一个 droplist
  1765. if (isFirstDropList) {
  1766. a.className += ' first';
  1767. isFirstDropList = false;
  1768. }
  1769.  
  1770. // 重新插入的位置
  1771. if (typeof category.insert !== 'undefined') {
  1772. a.dataset.horizontal = true;
  1773. a.dataset.insert = category.insert;
  1774. }
  1775.  
  1776. dropLists.push({
  1777. a: a,
  1778. dropList: dropList
  1779. });
  1780. };
  1781. });
  1782.  
  1783. dropLists.forEach(function (item, index) {
  1784. var a = item.a,
  1785. dropList = item.dropList;
  1786.  
  1787. // 移到某个类别里面
  1788. var ins;
  1789. var insert = a.dataset.insert;
  1790. if (typeof insert !== 'undefined') {
  1791. ins = document.querySelector('.sej-engine[_title="' + insert + '"]:not(.sej-drop-list-trigger)');
  1792. }
  1793.  
  1794. if (ins) {
  1795. ins.parentNode.insertBefore(a, ins);
  1796. } else {
  1797. container.appendChild(a);
  1798. }
  1799.  
  1800. if (a.dataset.horizontal && a.parentNode.id === container.id) { // 如果是顶层,菜单不需要修正
  1801. a.removeAttribute('data-horizontal');
  1802.  
  1803. // 插入到第一个类别前面
  1804. // ins = container.querySelector('a.sej-engine.first');
  1805. ins = container.querySelector('a.sej-engine:not(.sej-drop-list-trigger)');
  1806. ins.parentNode.insertBefore(a, ins);
  1807. }
  1808.  
  1809. if (prefs.position == 'left') { // 如果再左边的话,修正弹出菜单的位置
  1810. a.dataset.horizontal = true;
  1811. }
  1812. document.body.appendChild(dropList);
  1813.  
  1814. dropList.addEventListener('mousedown', mousedownhandler, true);
  1815.  
  1816. new DropDownList(a, dropList);
  1817. });
  1818.  
  1819. var insertWhere = matchedRule.insertIntoDoc.where;// 设置插入的位置
  1820.  
  1821. switch (insertWhere.toLowerCase()) {// 插入到文档中
  1822. case 'beforebegin' :
  1823. iTarget.parentNode.insertBefore(container, iTarget);
  1824. break;
  1825. case 'afterbegin' :
  1826. if (iTarget.firstChild) {
  1827. iTarget.insertBefore(container, iTarget.firstChild);
  1828. } else {
  1829. iTarget.appendChild(container);
  1830. }
  1831. break;
  1832. case 'beforeend' :
  1833. iTarget.appendChild(container);
  1834. break;
  1835. case 'afterend' :
  1836. if (iTarget.nextSibling) {
  1837. iTarget.parentNode.insertBefore(container, iTarget.nextSibling);
  1838. } else {
  1839. iTarget.parentNode.appendChild(container);
  1840. }
  1841. break;
  1842.  
  1843. };
  1844.  
  1845. var isTwoLine = container.clientHeight / container.children[1].clientHeight > 2;
  1846.  
  1847. // 插入后调整下,如果变成两行,隐藏文字
  1848. if (prefs.hideEnglineLabel == 2 || (prefs.hideEnglineLabel == 1 && isTwoLine)) {
  1849. [].forEach.call(document.querySelectorAll('#sej-container > a[class="sej-engine"] > span'), function(span) {
  1850. var link = span.parentNode;
  1851. link.classList.add('only-icon');
  1852. link.setAttribute('title', span.textContent);
  1853. });
  1854. }
  1855.  
  1856. if (typeof matchedRule.endFix == 'function') {
  1857. try {
  1858. matchedRule.endFix();
  1859. } catch(ex) {
  1860. console.error('endFix 错误', ex);
  1861. }
  1862. }
  1863.  
  1864. function mousedownhandler(e) {
  1865. var target = e.target;
  1866. if(!target.href)target = target.parentNode;
  1867.  
  1868. // if (!target || target.className.indexOf('sej-engine') == -1) return;
  1869. if (!target || !this.contains(target)) return;
  1870.  
  1871. var value;
  1872. if (typeof iInput == 'function') value = iInput();
  1873. else {
  1874. if (iInput.nodeName == 'INPUT' || iInput.localName == 'textarea') value = iInput.value;
  1875. else value = iInput.textContent;
  1876. }
  1877.  
  1878. // 根据后代元素中是否存在 form 元素,判断提交方式并进行处理
  1879. // 如果没有 form 元素,将会使用 GET 方法提交;如果有,将会使用 POST 方法提交
  1880. var forms = target.getElementsByTagName('form');
  1881. if (forms.length == 0) { // 提交方式为 GET
  1882. // 处理编码
  1883. var encoding = target.getAttribute('encoding');
  1884. if (encoding == 'utf-8') value = encodeURIComponent(value);
  1885. else if (encoding.indexOf('gb') == 0) console.log('不再收录gbk编码的引擎')
  1886. else if (encoding == 'utf16') value = toUTF16(value);
  1887.  
  1888. target.href = target.getAttribute('url').replace(/%s/g, value); // 替换“全部”关键词
  1889. }
  1890. else{ // 提交方式为 POST
  1891. var inputs = target.getElementsByTagName('input');
  1892. for (var i = 0; i < inputs.length; i++) inputs[i].value = inputs[i].value.replace(/%s/g, value); // // 替换“全部”关键词
  1893. }
  1894. }
  1895. }
  1896.  
  1897. function run() {
  1898. // 百度搜索插入到顶部搜索条下面就会造成页面部分元素的消失,所以需要每个部分都判断下是否存在
  1899. // 判断插入位置和输入框是否存在
  1900. var iTarget = getElement(matchedRule.insertIntoDoc.target);
  1901. var iInput;
  1902. if(matchedRule.insertIntoDoc.keyword){
  1903. if (typeof matchedRule.insertIntoDoc.keyword == 'function') {
  1904. iInput = matchedRule.insertIntoDoc.keyword;
  1905. if (!iInput()) {
  1906. return;
  1907. }
  1908. } else {
  1909. iInput = getElement(matchedRule.insertIntoDoc.keyword);
  1910. }
  1911. }
  1912. else{
  1913. iInput=document.querySelector('input[type="search"],input[name][value]:not([type]),input[type="text"][value][name]');
  1914. if(!iInput){iInput=document.querySelector('input[autocomplete="off"]:not([type]),input[type="text"]');}
  1915. }
  1916. debug('插入的位置为 %o', iTarget);
  1917. debug('匹配的输入框为 %o', iInput);
  1918.  
  1919. if (!iTarget || !iInput) {
  1920. debug('不存在插入的位置或匹配的输入框', iTarget, iInput);
  1921. return;
  1922. }
  1923.  
  1924. addGlobalStyle();
  1925.  
  1926. // 判断是否存在
  1927. var container = document.getElementById('sej-container'),
  1928. sejspan = document.querySelector('sejspan.sej-drop-list');
  1929.  
  1930. if (!container || !sejspan) {
  1931. if (container) {
  1932. container.parentNode.removeChild(container);
  1933. }
  1934. addContainer(iTarget, iInput);
  1935. }
  1936. }
  1937.  
  1938. function remove() {
  1939. var elems = document.querySelectorAll('#sej-container, sejspan.sej-drop-list');
  1940. if (!elems) return;
  1941.  
  1942. [].forEach.call(elems, function(elem) {
  1943. elem.parentNode.removeChild(elem);
  1944. });
  1945. }
  1946.  
  1947. // iframe 禁止加载
  1948. if (window.self != window.top) return;
  1949.  
  1950. var matchedRule;
  1951.  
  1952. rules.some(function (rule) {
  1953. if (toRE(rule.url).test(location.href)) {
  1954. matchedRule = rule;
  1955. if (typeof rule.etc == 'function') {
  1956. try {
  1957. rule.etc();
  1958. } catch(ex) {
  1959. console.error('执行 etc 错误', ex);
  1960. }
  1961. }
  1962. return true;
  1963. };
  1964. });
  1965.  
  1966.  
  1967. debug('匹配的规则为', matchedRule);
  1968.  
  1969. if (!matchedRule || !matchedRule.enabled) return;
  1970.  
  1971. if (matchedRule.change) {
  1972. if(matchedRule.change=="mutationTitle"){
  1973. run();
  1974. debug('添加标题节点监视器: title');
  1975.  
  1976. var watch = document.querySelector('title');
  1977. var observer = new MutationObserver(function(mutations){
  1978. debug('标题发生了变化', document.title);
  1979. run();
  1980. });
  1981. observer.observe(watch, {childList: true, subtree: true, characterData: true});
  1982. }
  1983. if(matchedRule.change=="runAtComplete"){
  1984. document.onreadystatechange = function() {
  1985. debug('onreadystatechange');
  1986. if (document.readyState == "complete"){
  1987. run();
  1988. }
  1989. }
  1990. }
  1991. }
  1992. else run();
  1993.  
  1994.  
  1995. })()