BaiduMonkeyY

改善百度的搜索结果界面,提高阅读效率

  1. // ==UserScript==
  2. // @name BaiduMonkeyY
  3. // @namespace http://userstyles.org
  4. // @description 改善百度的搜索结果界面,提高阅读效率
  5. // @version 15.7.2
  6. // @author 【原BaiduMonkeyR脚本作者是SUCCESS】修改自BaiduMonkeyW的版本
  7. // @include https://www.baidu.com/s*
  8. // @include https://www.baidu.com/baidu*
  9. // @include https://www.baidu.com/#*
  10. // @include https://www.baidu.com/
  11. // @run-at document-start
  12. // @require http://code.jquery.com/jquery-1.11.0.min.js
  13. // @grant GM_getMetadata
  14. // @grant GM_addStyle
  15. // @grant GM_xmlhttpRequest
  16. // @grant GM_log
  17. // @grant GM_info
  18. // @grant GM_getValue
  19. // @grant GM_setValue
  20. // ==/UserScript==
  21.  
  22.  
  23. console.log("Documtnt start");
  24.  
  25. var url=window.location.href;
  26. console.log(url);
  27. if (url.indexOf("http://www.baidu.com/#")>=0)
  28. {
  29. console.log("redirect to s?");
  30. window.location.href=url.replace("http://www.baidu.com/#","http://www.baidu.com/s?");
  31. return;
  32. }
  33. else if (url=="http://www.baidu.com/")
  34. {
  35. ajaxSend(window.wrappedJSObject.XMLHttpRequest,callback);
  36. console.log("get mainpage’s ajax,then add callback ");
  37. return;
  38. }
  39. addEventListener('DOMContentLoaded', baiduMeiHua, false);
  40. console.log("Documtnt DOMContentLoaded Evented!!");
  41.  
  42. function baiduMeiHua(){
  43. var url=window.location.href;
  44. console.log(url);
  45. if (url.indexOf("http://www.baidu.com/#")>=0)
  46. {
  47. console.log("redirect to baidu?");
  48. window.location.href=url.replace("http://www.baidu.com/#","http://www.baidu.com/baidu?");
  49. return;
  50. }
  51.  
  52. console.log("Start MeiHua");
  53. // 检查新版本
  54. //setTimeout(checkUpdate, 1000);
  55.  
  56. var isChrome = /Chrome/.test(navigator.userAgent);
  57.  
  58. var scriptUrl = 'https://gf.qytechs.cn/zh-CN/scripts/18704-baidumonkeyy';
  59. var scriptVersion='15.7.1';
  60. var installUrl='https://gf.qytechs.cn/scripts/18704-baidumonkeyy/code/BaiduMonkeyY.user.js';
  61. if (!isChrome){
  62. if (typeof(GM_getMetadata)!='undefined') //兼容Scriptish
  63. {
  64. scriptVersion = GM_getMetadata("version");
  65. }
  66. else
  67. if (typeof(GM_info)!='undefined')
  68. {
  69. scriptVersion = GM_info.script.version;
  70. }
  71. }
  72.  
  73. var NextPageLink;
  74. var pageCount = 1; // 翻页计数
  75. var ResultNum = 1; // 搜索结果计数
  76. var IsLoadingNext; // 是否正在加载下一页
  77. var relatedSearch = matchNode('//div[@id="rs"]').snapshotItem(0);
  78. var defaultCSS = '\
  79. .bm_MultiColDiv .rest {\n\
  80. background-color: #EBEFF9 !important;\n\
  81. padding-Left: 0.5em !important;\n\
  82. padding-right: 0.5em !important;\n\
  83. margin-top: 0.5em !important;\n\
  84. padding-top: 0.3em !important;\n\
  85. margin-bottom: 0.2em !important;\n\
  86. padding-bottom: 0.3em !important;\n\
  87. }\n\
  88. .bm_MultiColDiv .bm_num {\n\
  89. font-size: 11pt !important;\n\
  90. font-weight: bold !important;\n\
  91. }\
  92. ';
  93.  
  94. /***********************************************************************************
  95. * 设置参数
  96. ***********************************************************************************/
  97. // GreaseMonkey 的 getValue() 有一些限制,所以重定义一个 getValue()
  98. //var getValue = function(n,v){var gmv=isChrome?localStorage.getItem(n):GM_getValue(n);return (gmv==undefined || gmv.length < 1) ? v : gmv;};
  99. //var setValue = function(n,v){var gmv=isChrome?localStorage.setItem(n,v):GM_setValue(n,v);};
  100. var getValue, setValue;
  101. if(isChrome){
  102. getValue = function(n,v){var gmv=localStorage.getItem(n);return (gmv==undefined || gmv.length < 1) ? v : gmv;};
  103. setValue = function(n,v){var gmv=localStorage.setItem(n,v);};
  104. }else{
  105. getValue = function(n,v){var gmv=GM_getValue(n);return (gmv==undefined || gmv.length < 1) ? v : gmv;};
  106. setValue = function(n,v){var gmv=GM_setValue(n,v);};
  107. }
  108.  
  109. var Pref = { _:null
  110. // 分栏数量,默认 2
  111. ,columns : Number(getValue('numcol', 2))
  112. // 搜索结果的排列方向:1-横向;2-纵向(默认)
  113. ,direction : Number(getValue('direction', 2))
  114.  
  115. // 显示模式:1-紧凑;2-对齐,但比较松散(默认);3-对齐,但比较松散;4-对齐,但比较松散
  116. ,displayMode : Number(getValue('mode', 2))
  117.  
  118. // 是否自动加载下一页,默认 关闭
  119. ,AutoNextPage : toBoolean(getValue('AutoNextPage',false))
  120. ,Focus2NextPageKeys : getValue('Focus2NextPageKeys', 'ctrl+40')
  121. ,Focus2PrevPageKeys : getValue('Focus2PrevPageKeys', 'ctrl+38')
  122. // 是否隐藏自动翻页分隔符,默认 不隐藏
  123. ,HideAutoNextPage : toBoolean(getValue('HideAutoNextPage', false))
  124. // 下一页是否包含相关搜索,默认 不包含
  125. ,NextPageWithRS : toBoolean(getValue('NextPageWithRS', false))
  126. // 让搜索结果适合屏幕宽度,默认 打开
  127. ,fitwidth : toBoolean(getValue('fitwidth', true))
  128. // 移除页面右侧的广告,默认 打开
  129. ,removeAd : toBoolean(getValue('removeAd', true))
  130.  
  131. // 给搜索结果条目添加序号,默认 关闭
  132. ,addResultNum : toBoolean(getValue('addResultNums',false))
  133.  
  134. // 搜索结果条目添加序号时与标题同行,默认 关闭
  135. ,addResultNum_h : toBoolean(getValue('addResultNums_h',false))
  136.  
  137. // 添加缩略图预览,默认 关闭
  138. ,addPreview : toBoolean(getValue('addPreviews', false))
  139. // 缩略图大小,默认 100%
  140. ,PreviewSize : Number(getValue('PreviewSize', 100))
  141.  
  142. // 添加 Favicon,默认 关闭
  143. ,addFavicon : toBoolean(getValue('addFavicons', false))
  144.  
  145. // 若没有 Favicon 则显示空白,默认 否
  146. ,addFavicon_h : toBoolean(getValue('addFavicons_h',false))
  147.  
  148. // 添加“在此站点中搜索”
  149. ,searchSite : toBoolean(getValue('searchSite', false))
  150.  
  151. // 禁止百度记录我的点击情况,默认 关闭
  152. ,DisableTracking : toBoolean(getValue('DisableTracking', false))
  153. // 快捷键定位到搜索框
  154. ,Focus2Keyword : toBoolean(getValue('Focus2Keyword',false))
  155. ,Focus2KeywordKeys : getValue('Focus2KeywordKeys', 'alt+83')
  156. // 快捷键定位到搜索框后的动作:1-清除全部文字(默认);2-紧跟文字之后;3-选中全部文字
  157. ,Focus2KeywordAction : Number(getValue('Focus2KeywordAction',1))
  158.  
  159. // 在页面上部添加其他搜索引擎
  160. ,EnableSearchInOtherEngines : toBoolean(getValue('SearchInOtherEngines', false))
  161. // 其他搜索引擎地址
  162. ,OtherEngines : getValue('OtherEngines', '搜索searx |https://searx.me/?q={word}')
  163. // 其他搜索引擎打开方式,默认“在新页面打开”
  164. ,OtherEnginesTarget : getValue('OtherEnginesTarget','_blank')
  165. // 跟随搜索框浮动
  166. ,OtherEnginsFloat : toBoolean(getValue('OtherEnginsFloat',false))
  167. // CSS
  168. ,CSS : getValue('CSS', defaultCSS)
  169. ,customizeCSS : getValue('customizeCSS', '')
  170. // 自动检查更新
  171. ,lastCheck : Number(getValue('lastCheck', 0))
  172. ,skipVersion : Number(getValue('skipVersion', 0))
  173. ,newVersion : Number(getValue('newVersion', 0))
  174. };
  175.  
  176. /*********************************************************************************************
  177. * 开始处理
  178. *********************************************************************************************/
  179. //var t0 = new Date().getTime();
  180. var IsBaiduTuijian=0;
  181. var OldPrefColumns=Pref.columns;
  182. var OldPrefFitwidth=Pref.fitwidth;
  183.  
  184. /*
  185. if (matchNode('//div[@class="op_newvideo_left"]').snapshotLength>0
  186. | matchNode('//div[@class="op_newvideo_right"]').snapshotLength>0
  187. | matchNode('//div[@class="result-op"]').snapshotLength>0
  188. | matchNode('//div[@id="app-div"]').snapshotLength>0
  189. | matchNode('//div[contains(@class,"op_new")]').snapshotLength>0 //发现搜索“风云”时 出来的class是op_new_video_tvplay_left等
  190. )
  191.  
  192. {
  193. //addPreferences();
  194. //return;
  195. Pref.columns=1;
  196. Pref.fitwidth=false;
  197. IsBaiduTuijian=1;
  198. }
  199. */
  200.  
  201. var sRestTDAttribute='(@class="c-default" or @class="f" or @class="c-container")';
  202. //var sRestElementReal='//table[floor(@id div 1) = ceiling(@id div 1)]/tbody/tr/td['+sRestTDAttribute+' and not (descendant::div[@id="app-div"] or descendant::div[starts-with(@class,"op")] or descendant::a[text() = "推广"])]';
  203. //var sRestElementTuiGuang1='//table[floor(@id div 1) = ceiling(@id div 1)]/tbody/tr/td['+sRestTDAttribute+' and (descendant::div[@id="app-div"] or descendant::div[starts-with(@class,"op")] or descendant::a[text() = "推广"])]';
  204. //var sRestElementTuiGuang2='//div[@id="content_left"]/*[contains(@class,"result-op")]';
  205.  
  206.  
  207. var sRestAttribute='(@class="result" or contains(@class," result ") or starts-with(@class,"result ") or @class="rest")';
  208. var sRestElementReal='//div[floor(@id div 1)=ceiling(@id div 1) and '+sRestAttribute+' and not (descendant::div[@id="app-div"] or descendant::div[starts-with(@class,"op")] or descendant::a[text() = "推广"])]';
  209. var sRestElementTuiGuang1='//div[floor(@id div 1)=ceiling(@id div 1) and '+sRestAttribute+' and (descendant::div[@id="app-div"] or descendant::div[starts-with(@class,"op")] or descendant::a[text() = "推广"])]';
  210. var sRestElementTuiGuang2='//div[@id="content_left"]/*[contains(@class,"result-op")] | //div[@id="content_left"]/*[contains(@class,"c-frame")] ';
  211.  
  212. var sRestElementTuiGuang=sRestElementTuiGuang1+' | '+sRestElementTuiGuang2;
  213. var sRestElementAll=sRestElementReal+' | '+sRestElementTuiGuang;
  214.  
  215. switch (matchNode(sRestElementAll).snapshotLength > 0) {
  216. // 若存在搜索结果
  217. case true:
  218. doit();
  219.  
  220. // 自动加载下一页
  221. if (Pref.AutoNextPage) {
  222. NextPageLink = matchNode('//p[@id="page"]/a[text() = "下一页>"]').snapshotItem(0);
  223.  
  224. // 删除第一页的页面导航条
  225. var nav = matchNode('//p[@id="page"]').snapshotItem(0);
  226. if (nav)
  227. nav.parentNode.removeChild(nav);
  228. IsLoadingNext = false;
  229. setTimeout(loadNextPage,1000);
  230. window.addEventListener('scroll', watch_scroll, true);
  231.  
  232. // 快捷键定位到下一页
  233. var shift_Next = /shift/.test(Pref.Focus2NextPageKeys);
  234. var alt_Next = /alt/.test(Pref.Focus2NextPageKeys);
  235. var ctrl_Next = /ctrl/.test(Pref.Focus2NextPageKeys);
  236. var tmp = Pref.Focus2NextPageKeys.split('+');
  237. var keycode_Next = tmp[tmp.length - 1];
  238.  
  239. window.addEventListener('keydown', function(event){
  240. if ((event.altKey == alt_Next) && (event.ctrlKey == ctrl_Next) && (event.shiftKey == shift_Next) && (event.keyCode == keycode_Next) && (event.target.localName != 'INPUT') && !document.getElementById('preferences')) {
  241. var nextSplit = Pref.HideAutoNextPage?matchNode('//div[contains(@class,"bm_nextpage")]'):matchNode('//p[contains(@class,"bm_nav")]');
  242. var i, len = nextSplit.snapshotLength, headerOffset = (Pref.floatInput && Pref.floatInputPos==1)?document.getElementById('bm_header').offsetHeight:0;
  243. for(i=0;i<len;i++){
  244. if(window.scrollY<nextSplit.snapshotItem(i).offsetTop - headerOffset){
  245. window.scrollTo(0, nextSplit.snapshotItem(i).offsetTop - headerOffset);
  246. break;
  247. }
  248. }
  249.  
  250. event.preventDefault();
  251. event.stopPropagation();
  252. }
  253. }, true);
  254.  
  255. // 快捷键定位到上一页
  256. var shift_Prev = /shift/.test(Pref.Focus2PrevPageKeys);
  257. var alt_Prev = /alt/.test(Pref.Focus2PrevPageKeys);
  258. var ctrl_Prev = /ctrl/.test(Pref.Focus2PrevPageKeys);
  259. tmp = Pref.Focus2PrevPageKeys.split('+');
  260. var keycode_Prev = tmp[tmp.length - 1];
  261.  
  262. window.addEventListener('keydown', function(event){
  263. if ((event.altKey == alt_Prev) && (event.ctrlKey == ctrl_Prev) && (event.shiftKey == shift_Prev) && (event.keyCode == keycode_Prev) && (event.target.localName != 'INPUT') && !document.getElementById('preferences')) {
  264. var prevSplit = Pref.HideAutoNextPage?matchNode('//div[contains(@class,"bm_nextpage")]'):matchNode('//p[contains(@class,"bm_nav")]');
  265. var i, len = prevSplit.snapshotLength, headerOffset = (Pref.floatInput && Pref.floatInputPos==1)?document.getElementById('bm_header').offsetHeight:0;
  266. for(i=len-1;i>=0;i--){
  267. if(window.scrollY>prevSplit.snapshotItem(i).offsetTop - headerOffset){
  268. window.scrollTo(0, prevSplit.snapshotItem(i).offsetTop - headerOffset);
  269. break;
  270. }
  271. }
  272. if(i<0){window.scrollTo(0,0);}
  273. event.preventDefault();
  274. event.stopPropagation();
  275. }
  276. }, true);
  277. }
  278.  
  279. // 若不存在搜索结果
  280. case false:
  281.  
  282. // 禁止百度记录我的点击情况
  283. if(Pref.DisableTracking){
  284. removeTracking(document.body);
  285. }
  286.  
  287. // 设置“相关搜索”提示框的样式
  288. var tip=matchNode('//div[parent::div[@id="wrapper"] and descendant::td[text() = "相关搜索"]]').snapshotItem(0);
  289. if(tip){
  290. tip.setAttribute('style','background-color: rgb(239, 242, 250); height: 60px; width: 100%; clear: both; margin-top: 0.5em;');
  291. }
  292.  
  293. // 添加 “BaiduMonkeyW 设置”
  294. addPreferences();
  295.  
  296. // 添加其他搜索引擎
  297. if (Pref.EnableSearchInOtherEngines) {
  298. addSearchInOtherEngines();
  299. }
  300. // 快捷键定位到搜索框
  301. if (Pref.Focus2Keyword) {
  302. var shift = /shift/.test(Pref.Focus2KeywordKeys);
  303. var alt = /alt/.test(Pref.Focus2KeywordKeys);
  304. var ctrl = /ctrl/.test(Pref.Focus2KeywordKeys);
  305. var tmp = Pref.Focus2KeywordKeys.split('+');
  306. var keycode = tmp[tmp.length - 1];
  307. var lastKeyWord = '';
  308. window.addEventListener('keydown', function(event){
  309. if ((event.altKey == alt) && (event.ctrlKey == ctrl) && (event.shiftKey == shift) && (event.keyCode == keycode) && (event.target.localName != 'INPUT')) {
  310. with (document.getElementsByName("wd")[0]) {
  311. value = value.replace(/\s*$/, '') + ' ';
  312. focus();
  313. switch (Pref.Focus2KeywordAction) {
  314. case 1:
  315. lastKeyWord = value;
  316. value = '';
  317. break;
  318. case 2:
  319. break;
  320. case 3:
  321. select(); }
  322. }
  323. event.preventDefault();
  324. event.stopPropagation();
  325. }
  326. }, true);
  327. // 如果已选择“清除全部文字”,那么当输入框失去焦点且没有文字的时候,填入上一次的搜索字词
  328. if (Pref.Focus2KeywordAction == 1) {
  329. document.getElementsByName("wd")[0].addEventListener('blur', function(event){
  330. var input = event.target;
  331. if (input.value == '' && lastKeyWord != '') {
  332. input.value = lastKeyWord;
  333. }
  334. }, false);
  335. }
  336. }
  337.  
  338. }
  339.  
  340. /*********************************************************************************************
  341. * 各功能函数
  342. *********************************************************************************************/
  343. function doit(){
  344. var css = '\
  345. /* 添加圆角效果等 */ \
  346. .rest {display: ' + (isChrome?(Pref.columns==1?'table':'inline-table'):'table') + '; -moz-border-radius: 0.75em;-webkit-border-radius: 0.75em;} .bm_MultiColDiv {padding-right: 0.5em;}\
  347. /* 添加推广链接内容框的样式 */ \
  348. /* #popDiv {-moz-column-count: ' + Pref.columns + '; -moz-column-gap: 0.5em; -webkit-column-count: ' + Pref.columns + '; -webkitcolumn-gap: 0.5em; margin-top: 1em; -moz-border-radius: 0.75em;} */ \
  349. #popDiv {-moz-column-count: 1; -moz-column-gap: 0.5em; -webkit-column-count: 1; -webkitcolumn-gap: 0.5em; margin-top: 1em; -moz-border-radius: 0.75em;} \
  350. /* .bm_SingleColDiv {padding-left: 0.5em;padding-right: 0.5em;} */ \
  351. /* 让搜索结果条目顶部对齐 */ \
  352. .f {vertical-align: top;} \
  353. /* 百度默认的关键字样式 */ \
  354. .bm_kw {color: #c60a00; font-style: normal;}'
  355. +
  356. // 让搜索结果适合屏幕宽度
  357. (Pref.fitwidth?' .bm_MultiColDiv .f {width: 200em !important;}':'')
  358. +
  359. // 添加预览缩略图的样式
  360. (Pref.addPreview?' .bm_previewimg {border: 1px solid rgb(187, 187, 187); margin: 2px 4px 5px 0px; width: ' + 111 * Number(Pref.PreviewSize) / 100 + 'px; height: ' + 82 * Number(Pref.PreviewSize) / 100 + 'px; background-position: center center; background-repeat: no-repeat;}':'')
  361. +
  362. // 添加 favicon 的样式
  363. (Pref.addFavicon?' .bm_favicon {visibility: hidden; margin: 0 4px -3px 0; width: 16px; height: 16px;;}':'')
  364. +
  365. // 若没有 favicon 则显示空白
  366. (Pref.addFavicon_h?'':'.bm_favicon {display: none;}')
  367. +
  368. // 添加分栏样式
  369. ' .bm_MultiColDiv {-moz-column-count: ' + Pref.columns + '; -moz-column-gap: 0.2em; -webkit-column-count: ' + Pref.columns + '; -webkit-column-gap: 0.2em;}'
  370. +
  371. // 隐藏自动翻页分隔符
  372. (Pref.HideAutoNextPage?' .bm_nav {display: none !important;}':'')
  373. +
  374. // 添加翻页分隔符的样式
  375. (Pref.AutoNextPage?' .bm_nav {font-size: small; background: rgb(230, 230, 230) none repeat scroll 0% 0%; clear: both; line-height: 20px; text-align: center; margin-top: 0.7em;} .bm_nav .n {font-size: small !important;}':'')
  376. +Pref.CSS + Pref.customizeCSS;
  377. GM_addStyle(css);
  378.  
  379.  
  380. // 设置分栏格式
  381. movePops_and_MultiCol(document.body, pageCount, Pref);
  382.  
  383. // 给搜索结果条目添加序号
  384. if(Pref.addResultNum){
  385. addResultNums(document.body);
  386. }
  387.  
  388. // 移动贴吧栏目至上部
  389. var tbAs = matchNode('//a[starts-with(@href, "http://tieba.baidu.com/f?kw=")][parent::td[not('+sRestTDAttribute+')]]');
  390. var biTds = matchNode('//table[@class="bi"]/descendant::td').snapshotItem(1);
  391. var len = tbAs.snapshotLength;
  392. if (biTds && len > 0) {
  393. for (var i = 0; i < len; i++) {
  394. biTds.appendChild(tbAs.snapshotItem(i));
  395. biTds.innerHTML += '&nbsp&nbsp&nbsp&nbsp';
  396. }
  397. }
  398.  
  399. // 去除右侧的广告
  400. if (Pref.removeAd) {
  401. var adTable = matchNode('//div[@id="content_right"]').snapshotItem(0);
  402. if (adTable) {
  403. adTable.style.display='none';
  404. }
  405. var contentLeft = matchNode('//div[@id="content_left"]').snapshotItem(0);
  406. if (contentLeft) {
  407. contentLeft.style.width='100%';
  408. }
  409. }
  410.  
  411. // 添加缩略图预览
  412. if(Pref.addPreview){
  413. addPreviews(document.body);
  414. }
  415.  
  416. // 添加站点 Favicon
  417. if(Pref.addFavicon){
  418. addFavicons(document.body);
  419. }
  420.  
  421. // 添加“在此站点中搜索”
  422. if(Pref.searchSite){
  423. addseatchSite(document.body);
  424. }
  425.  
  426. // 统一格式,美化版面
  427. // 只有一列或者“紧凑”模式时不需要统一格式
  428. if (Pref.columns > 1 && Pref.displayMode > 1) {
  429. format('bm_page_' + pageCount, Pref);
  430. }
  431. // 把关键字放到<em>标签中,以便控制样式
  432. var kw, kws = matchNode('//font[@color="#c60a00"]');
  433. len = kws.snapshotLength;
  434. for (var i = 0; i < len; i++) {
  435. kw = kws.snapshotItem(i);
  436. var em = document.createElement('em');
  437. em.innerHTML = kw.innerHTML;
  438. em.setAttribute('class','bm_kw');
  439. kw.parentNode.replaceChild(em,kw);
  440. }
  441. }
  442.  
  443. // 用 XPath 匹配元素
  444. function matchNode(xpath, context){
  445. return document.evaluate(context?(xpath.indexOf('.')==0?xpath:'.' + xpath):xpath, context || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  446. }
  447.  
  448. // 添加 “BaiduMonkeyW 设置 ” //用户登录(不可用)后 页面会执行一个脚本 对id=u的元素重新写值,导致脚本设置按钮丢失。现在改为在u前添加一个元素。
  449. //2013-2-4 因为百度登录(不可用)后,最上边一行有时候会很长,导致和设置按钮重叠,现在改为放在第二行。
  450. function addPreferences(){
  451. var titDiv = matchNode('//div[@id="u"]').snapshotItem(0);
  452. if(titDiv){
  453. var prefDiv = document.createElement('div');
  454. with (prefDiv) {
  455. setAttribute('style', 'position: absolute; top: 4px; right:20%; font-size:12px; white-space:pre; z-index: 101; ');
  456. innerHTML = '<span></span>';
  457. }
  458. var preferences = document.createElement('a');
  459. with (preferences) {
  460. setAttribute('href', 'javascript: void(0);');
  461. innerHTML = 'BaiduMonkeyY 设置';
  462. addEventListener('click', function(){
  463. SetPreferences();
  464. }, false);
  465. }
  466. prefDiv.insertBefore(preferences, prefDiv.firstChild);
  467. //当显示了baidu视频推荐的时候,设置按钮下显示提示信息。
  468. if (IsBaiduTuijian== 1)
  469. {
  470. //prefDiv.insertBefore(document.createElement('br'), prefDiv.lastChild);
  471. var videoTip=document.createElement('span');
  472. with (videoTip) {
  473. setAttribute('style', 'color:red;');
  474. innerHTML='该页面有百度的整合信息,暂时单栏以适应显示结果!';
  475. }
  476. prefDiv.insertBefore(videoTip, prefDiv.firstChild);
  477. //prefDiv.appendChild(videoTip);
  478. }
  479. //titDiv.appendChild(preferences);
  480. titDiv.parentNode.insertBefore(prefDiv, titDiv.nextSibling);
  481. }
  482. }
  483.  
  484. // 添加 其他搜索引擎
  485. function addSearchInOtherEngines(){
  486. //var div = matchNode('//div[@id="tool"]/span[descendant::a[@href="#"]]').snapshotItem(0);
  487. //2011-10-15 发现11.8版本无法添加其他搜索引擎链接 查了代码原来 百度去掉了 div[id=tool]的元素,现在改掉这一点 加在查询按钮后。
  488. //var div = matchNode('//form[@class="fm"]/span[@class="tools"]/span[@id="setf"]').snapshotItem(0);
  489. //2012-10-24 发现无法添加其他搜索引擎链接 查了代码 原来 百度去掉了span[@id="setf"]的元素,现在改掉这一点 加在查询按钮后。
  490. //var div = matchNode('//form[@class="fm"]/span[@class="tools"]').snapshotItem(0);
  491. //2013-4-16 其他搜索引擎再次消失,发现tools在fm下不显示,这次新建立一个div放其他的东西
  492. //2013-4-18 终于发现了为啥tools下内容不显示,原来是ABP给隐藏了。现在这样处理后,如果没有ABP,那么将会显示推荐
  493. //所以这里先去掉推荐
  494. var div = matchNode('//form[@class="fm"]/span[@class="tools"]').snapshotItem(0);
  495. if (div)
  496. div.innerHTML='';
  497. //然后添加其他搜索引擎,看来以后尽量少在页面的广告内替换东西,最好的方法是去掉广告,新增div
  498. var div = matchNode('//form[@class="fm"]').snapshotItem(0);
  499. if (div)
  500. {
  501. var OtherEnginesWith=window.Width-650;//自动设置显示区域宽度为剩余空间
  502. div=div.appendChild(document.createElement('div'));
  503. div.style.display='none'; // 将 div 隐藏,避免浏览器频繁重绘。最后将 div 设为可见。
  504. div.setAttribute('style', 'max-width:'+OtherEnginesWith+'px;position: absolute;top:0px;left:650px;align:center;');
  505. var keyword = document.getElementsByName('wd')[0].value;
  506. var keywordGB = String(document.body.innerHTML.match(/word=[^'"&]+['"&]/i)).replace(/word=|['"&]/ig, '');
  507. var engines = Pref.OtherEngines.split(/\n/);
  508. for (i = 0; i < engines.length; i++) {
  509. var engine = engines[i].split('|');
  510. if (engine.length > 1) {
  511. var searchEngine = document.createElement('a');
  512. searchEngine.setAttribute('href', engines[i].replace(engine[0] + '|', '').replace(/{word}/ig, encodeURIComponent(keyword)).replace(/{gb:word}/ig, keywordGB));
  513. searchEngine.setAttribute('target', Pref.OtherEnginesTarget);
  514. searchEngine.innerHTML = engine[0].replace(/{word}|{gb:word}/ig, keyword.replace('<', '&lt;').replace('>', '&gt;'));
  515. //div.innerHTML = div.innerHTML+'<br/>'+searchEngine.outerHTML;
  516. //div.appendChild(document.createTextNode(' | '));
  517. div.appendChild(searchEngine);
  518. div.appendChild(document.createElement('br'));
  519. }
  520. }
  521. div.style.display='';
  522. }
  523. }
  524.  
  525. // 给搜索结果条目添加序号
  526. function addResultNums(doc){
  527. //div[@id="content_left" or @class="bm_nextpage"]/ }
  528. var resTds = matchNode(sRestElementReal, doc);
  529. console.log('restds:'+resTds.snapshotLength);
  530. for (var i = 0; i < resTds.snapshotLength; i++) {
  531. var num = document.createElement('span');
  532. num.setAttribute('class','bm_num');
  533. num.innerHTML = '&nbsp;' + (ResultNum++) + '&nbsp;';
  534. var resTd = resTds.snapshotItem(i);
  535. if (Pref.addResultNum_h) {
  536. //在标题最前边同一行添加序号
  537. var resLinks=matchNode('//descendant::*[@class="t" and child::a]', resTd);
  538. if (resLinks.snapshotLength==1)
  539. {
  540. var resLink = resLinks.snapshotItem(0);
  541. resLink.insertBefore(num, resLink.firstChild);
  542. }
  543. }
  544. else {
  545. //在标题上一行添加序号(表格采用H3,会保持单独以后那个,造成序号也是单独一行)
  546. resTd.insertBefore(num, resTd.firstChild);
  547. }
  548. }
  549. }
  550.  
  551. function isAmazonCOM(href) {
  552. return href.toLowerCase().indexOf("www.amazon.com") == 7;
  553. }
  554.  
  555. function getASIN(href) {
  556. var asin = href.match(/amazon.+\W+([0-9A-Z]{10})(\W+|$)/i);
  557. return asin ? asin[1] : null;
  558. }
  559.  
  560. function getFullDomain(href) {
  561. var domain = href.match(/http(?:s)?:\/\/[^\/]+/i);
  562. return domain ? domain[0].toLowerCase() : href;
  563. }
  564.  
  565. function getGPSub(href) {
  566. var site = getFullDomain(href);
  567. site = site.toLowerCase();
  568. if (site.indexOf("https://") == 0) {
  569. site = site.substring(8, site.length);
  570. }
  571. else if (site.indexOf("http://") == 0) {
  572. site = site.substring(7, site.length);
  573. }
  574. if (site.indexOf("www.") == 0) {
  575. site = site.substring(4, site.length);
  576. }
  577. return site.length > 0 ? ""+site.charAt(0) : "a";
  578. }
  579.  
  580. // 根据站点根域名的首字母分配 googlepreview 服务器,分散服务器压力
  581. function getImageURL(href) {
  582. var fullDomain = getFullDomain(href);
  583. var protocol = "unknown";
  584. var site = fullDomain;
  585. if (site.indexOf("http://") == 0) {
  586. site = site.substring(7, site.length);
  587. protocol = "http://";
  588. }
  589. else if (site.indexOf("https://") == 0) {
  590. site = site.substring(8, site.length);
  591. protocol = "https://";
  592. }
  593. var preview = "http://"+getGPSub(site)+".googlepreview.com/preview?s=" + protocol + site + "&ra=1";
  594. if (!isAmazonCOM(href)) {
  595. return preview;
  596. }
  597. var isbn = getASIN(href);
  598. if (isbn != null) {
  599. if (isAmazonCOM(href)) {
  600. return "http://images.amazon.com/images/P/" + isbn + ".01.TZZZZZZZ.jpg";
  601. }
  602. }
  603.  
  604. return preview;
  605. }
  606.  
  607. // 将字符串转换为二进制,否则 btoa() 方法出错
  608. function data_string(data){
  609. var data_string = '';
  610. for (var i = 0, il = data.length; i < il; i++)
  611. data_string += String.fromCharCode(data[i].charCodeAt(0) & 0xff);
  612. return data_string;
  613. };
  614.  
  615. /*
  616. * googlepreview 会检查 img 请求的 Referer ,如果发现不是来自 google 站点,则会返回 stop 的图片。
  617. * 所以需要用 xmlhttpRequest 发出请求,避免 Referer 。
  618. * 异步请求并得到图片的 base64 编码。(跨域获得图片的方法参见 Cross Domain Images in Userscript,http://pastebin.ca/1425789)
  619. */
  620. function getImg(img, imgUrl){
  621. GM_xmlhttpRequest({
  622. method: "GET",
  623. url: imgUrl,
  624. overrideMimeType: 'text/plain; charset=x-user-defined',
  625. onload: function(rsp) {
  626. img.src='data:image/jpg;base64,' + btoa(data_string(rsp.responseText));
  627. }
  628. });
  629. }
  630.  
  631. // 添加缩略图预览。先使用 thumbshots.org 的服务,如果不能访问则使用 googlepreview 的服务(提取自 googlepreview 扩展,部分修改)。
  632. function addPreviews(doc){
  633. //sina改版 造成链接位置更改
  634. //var resLinks = matchNode('//td[@class="f" and (child::a or child::font/a) and not(descendant::a[text() = "推广"])]/a', doc);
  635. var resLinks = matchNode('//td['+sRestTDAttribute+' and (child::h3/a)]/h3/a', doc);
  636. var i, len = resLinks.snapshotLength;
  637. for (i = 0; i < len; i++) {
  638. var resLink = resLinks.snapshotItem(i);
  639. var a = document.createElement('a');
  640. a.setAttribute('target','_blank');
  641. a.setAttribute('href',resLink.href);
  642. var imgBlank = document.createElement('img');
  643. with(imgBlank){
  644. setAttribute('class', 'bm_previewimg');
  645. setAttribute('align', 'left');
  646. src="data:image/gif;base64,R0lGODlhbwBSAKIAAMzMzP///+Xl5e/v79XV1d/f3/n5+QAAACH5BAAHAP8ALAAAAABvAFIAAAP/GLrc/jDKSau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd/wMOA8ZRg9l06nGAIHgiMwMNwFBMmnIjpYBjsEApIQyO4KggHBICgoxtCujjs2EAQBwPWjPbt3BgD0HWdyoWJ7SHsFYnMedWp1YkYBhYVPUIVEYmN6cIccfF1qCgBHO2JykYZMQAByBZ+ZmgUFdYmVXGdmkU9ZmK5+rJpOvD2Jv8IUs8M4vsYiZL5ITklhTFFwTQtQBsjJE4xlXWF8AFq4AlxyXrpvldkWkApu7XKr3H3loWOzpeoTwfjwU5j9i8IVKZYvQpprcY6Q8+epT0BOjmoVlPBqjJ8spxjO62So/9K4iS+WpAHZoqJEkihTquxAJko0Xy2L6HC5ssKdAWbGbfGjQ45OfDUn5KniackYdmBGjgrqY5yZpeGcQfnH1GbDOnme1NKitCoxLwHcgHWEy1Yfr2jTql3Ltq3bt3Djyp1Lt67du3jz6t3Lt6/fv4ADCx58qCU2Dj8iNDl8IXEMVXtWefgIAVwWApIzbHpBeQrBDZ0dAPAV+tfoBpjcgPOlSs8CVW/gUBZlMQ4znwLAhcVcZ6SjZlNQmXEXthZxlksb5Jl2msBwPh/z/OEy4HTuU6TZcPnhunrPd91u/Xhl+0m8zxqqV7tMppirPEvUJ9L10dWQb5cxA9nESIcu669m8IFOTwbo4gocmyG21DXedabTUuqddsuE+YGlxxALbJJbfnCcswN++V3DhhvwgRCMJ2u8VkCJTNDj2YS6tIOiAxoWE99oo3wDU1iXdIPeBt5V88lyLX74nGzb6fZRkEFKyMAmRLrxj3NnIAlEbmf0lqAHsqzWDm+soYKJI+DQdw+YMzawmWquKaCKExqiUhuWLVoRwjV2WgCNVoLlBkVmgA2SJ2GEFmrooYgmqlICADs=";
  647. }
  648. var img = document.createElement('img');
  649. with (img) {
  650. setAttribute('class', 'bm_previewimg');
  651. setAttribute('title', '');
  652. setAttribute('align', 'left');
  653. setAttribute('src', 'http://open.thumbshots.org/image.pxf?url=' + resLink.href);
  654. // GM_log(resLink.href);
  655. style.display='none';
  656. addEventListener("load", function(e){
  657. // 先移除空白图,再显示出真正的缩略图
  658. e.target.parentNode.removeChild(e.target.previousSibling);
  659. e.target.style.display = '';
  660. }, false);
  661. if(!isChrome){
  662. addEventListener("error", function(e){
  663. e.target.style.border = '1px solid blue';
  664. getImg(e.target, getImageURL((e.target.src.match(/\?url=.*/i) + '').replace(/\?url=/ig,'')));
  665. }, false);
  666. }
  667. }
  668. a.appendChild(imgBlank);
  669. a.appendChild(img);
  670. resLink.parentNode.insertBefore(a, resLink);
  671. }
  672. }
  673.  
  674. // 添加站点 Favicon
  675. function addFavicons(doc){
  676. //因为百度隐藏了真是的链接地址,而这里只要获取主站地址即可
  677. var resElements = matchNode('//td['+sRestTDAttribute+' and (descendant::*[@class="g" or @style="color:#008000" or @color="#008000"]) and descendant::*[@class="t"] and not(descendant::a[text() = "推广"])]', doc);
  678. var i, len = resElements.snapshotLength;
  679. for (i = 0; i < len; i++) {
  680. var resElement = resElements.snapshotItem(i);
  681. var resSites=matchNode('//descendant::*[@class="g" or @style="color:#008000" or @color="#008000"]', resElement);
  682. if (resSites.snapshotLength==1)
  683. {
  684. var base = resSites.snapshotItem(0).innerHTML.match(/[\w\.\-]+\//);
  685. base = 'http://'+base;
  686. }
  687. var resLinks=matchNode('//descendant::*[@class="t" and child::a]', resElement);
  688. if (resLinks.snapshotLength==1)
  689. {
  690. var resLink = resLinks.snapshotItem(0);
  691. }
  692. var img = document.createElement('img');
  693. with (img) {
  694. setAttribute('class','bm_favicon');
  695. addEventListener("load", function(e){
  696. e.target.style.display = 'inline';
  697. e.target.style.visibility = 'visible';
  698. }, false);
  699. src=base + 'favicon.ico';
  700. }
  701. if (resLink.firstChild.className=="bm_num")
  702. resLink.insertBefore(img, resLink.firstChild.nextSibling);
  703. else
  704. resLink.insertBefore(img, resLink.firstChild);
  705. }
  706. }
  707.  
  708. // 添加“在此站点中搜索”
  709. function addseatchSite(doc){
  710. if(location.href.indexOf(escape('site:'))>=0){
  711. return; // 如果已经是 site: 搜索了则退出
  712. }
  713.  
  714. // 将点击搜索按钮的 Javascript 添加到 head 中
  715. if (!document.getElementById('ClickSearchBtnJS')) {
  716. var head = document.getElementsByTagName("head")[0];
  717. var ClickSearchBtnJS = document.createElement('script');
  718. with(ClickSearchBtnJS){
  719. setAttribute('id', 'ClickSearchBtnJS');
  720. type = "application/x-javascript";
  721. innerHTML = '\
  722. function searchSite(url){\
  723. document.forms[0].wd.value += " site:" + url;\
  724. document.forms[0].submit();\
  725. }';
  726. }
  727. head.appendChild(ClickSearchBtnJS);
  728. }
  729. //百度网站在 百度快照 前写入了空格,采用这个normalize-space可以去掉前后的空格
  730. //var cacheLinks = matchNode('//a[text() = "百度快照"]',doc);
  731. var cacheLinks = matchNode('//a[normalize-space(text()) = "百度快照"]',doc);
  732. var i, len = cacheLinks.snapshotLength;
  733. for (i = 0; i < len; i++) {
  734. try {
  735. var cacheLink = cacheLinks.snapshotItem(i);
  736. var site = cacheLink.previousSibling.previousSibling.innerHTML.replace(/<[^>]*>/ig, '').split('/')[0];
  737. var a = document.createElement('a');
  738. with (a) {
  739. innerHTML = '在此站点中搜索';
  740. setAttribute('class', 'm');
  741. setAttribute('title', '在 ' + site + ' 中搜索');
  742. setAttribute('href', 'javascript:searchSite("' + site + '")');
  743. }
  744. cacheLink.parentNode.insertBefore(a, cacheLink.nextSibling);
  745. cacheLink.parentNode.insertBefore(document.createTextNode(' - '), cacheLink.nextSibling);
  746. }
  747. catch (e) {
  748. }
  749. }
  750. }
  751.  
  752. // 禁止百度记录我的点击情况
  753. function removeTracking(doc){
  754. var links = matchNode('//table[@class="rest"]/descendant::a[string-length(@onmousedown)>0]',doc);
  755. var i, len = links.snapshotLength;
  756. for (i = 0; i < len; i++) {
  757. links.snapshotItem(i).removeAttribute('onmousedown');
  758. }
  759. }
  760.  
  761. // 分栏
  762. function movePops_and_MultiCol(doc, pagecount, Pref){
  763. var i, len;
  764.  
  765. //2013-3-13:已经没有跟搜索结果同级别的br了 所以这句没有用了
  766. // 去除没用的 <br>
  767. // var Brs = matchNode('//br[preceding-sibling::table[tbody/tr/td['+sRestTDAttribute+']]]', doc);
  768. // len = Brs.snapshotLength;
  769. // for (i = 0; i < len; i++) {
  770. // Brs.snapshotItem(i).style.display='none';
  771. // }
  772. // 在第一个条目前插入一个 DIV ,id = bm_page_1,2,3,etc,用来容纳搜索结果条目。
  773. var firstTable;
  774. if (pagecount=='pref')//pagecount=='pref' 说明是预览界面
  775. {
  776. firstTable = matchNode('//table[tbody/tr/td['+sRestTDAttribute+']]',doc).snapshotItem(0);
  777. }
  778. else
  779. {
  780. firstTable = matchNode(sRestElementAll,doc).snapshotItem(0);
  781. }
  782. //alert(firstTable);
  783. var resContainer = document.createElement('div');
  784. resContainer.setAttribute('id', 'bm_page_' + pagecount);
  785. firstTable.parentNode.insertBefore(resContainer, firstTable);
  786. // 移动“推广”条目
  787. // var popTables = matchNode('//table[tbody/tr/td[(contains(@class,"f ") or @class="f") and descendant::a[text() = "推广"]]]',doc);
  788. //div[@id="content_left"]/
  789. var popTables = matchNode(sRestElementTuiGuang,doc);
  790. len = popTables.snapshotLength;
  791. console.log("tuiguang:"+len);
  792. if (len > 0) {
  793. // popContainer 用来盛放推广条目,将它添加在搜索结果 DIV 之前
  794. var popContainer = document.createElement('div');
  795. popContainer.setAttribute('class', 'containerTuiGuang'); //这里推广链接容器样式 ,但不处理格式
  796. popContainer.setAttribute('id', 'hi_abp_not_block_me');
  797. resContainer.parentNode.insertBefore(popContainer, resContainer);
  798. var popContainerTable = document.createElement('table');
  799. popContainerTable.innerHTML = '<span>&nbsp;&nbsp;&nbsp;&nbsp;</span><a id="togglePops" href="javascript: void(0);"><font size="-1">显示/关闭' + len + '条推广链接 </font></a><br><div id="popDiv" class="bm_MultiColDiv"></div><br>';
  800. popContainer.appendChild(popContainerTable);
  801.  
  802. var popDiv = document.getElementById('popDiv');
  803. //popDiv.style.display = 'none';
  804. // 添加显示、隐藏“推广”条目的事件
  805. document.getElementById('togglePops').addEventListener('click', function(){
  806. popDiv.style.display = popDiv.style.display == 'none' ? '' : 'none';
  807. }, false);
  808.  
  809. for (i = 0; i < len; i++) {
  810. var popTable = popTables.snapshotItem(i);
  811. var oldClass=popTable.getAttribute('class');
  812. popTable.setAttribute('class', oldClass+' restTuiGuang'); //这里推广链接宽度样式 可能需要和搜索结果不同, 所以暂定为restTuiGuang,但不处理格式
  813. //GM_log(popTable.outerHTML);
  814. popDiv.appendChild(popTable); // 移动结果 Table
  815. }
  816. }
  817.  
  818. // 移动搜索结果条目
  819. resContainer.setAttribute('id','bm_page_' + pagecount);
  820. // 如果打开了设置界面,那么不添加 class ,使得设置界面中的预览能够正常变化
  821. if(!document.getElementById('preferences')) resContainer.setAttribute('class','bm_MultiColDiv');
  822.  
  823. //var resTables = matchNode('//table[tbody/tr/td/@class="f"][not(descendant::a[text() = "推广"])]', doc);
  824. //div[@id="content_left" or @class="bm_nextpage"]/
  825. var resTables;
  826. if (pagecount=='pref') //pagecount=='pref' 说明是预览界面
  827. {
  828. resTables = matchNode('//table[tbody/tr/td['+sRestTDAttribute+']][not(descendant::div[@id="app-div"] or descendant::div[starts-with(@class,"op")] or descendant::a[text() = "推广"])]', doc);
  829. }
  830. else
  831. {
  832. resTables = matchNode(sRestElementReal, doc);
  833. }
  834. len = resTables.snapshotLength;
  835. //GM_log("restTableCount"+len);
  836. if (len > 0) {
  837. var cols = Pref.columns;
  838. var resTable;
  839. // 设置搜索结果的排列方向。1-横向;2-纵向
  840. switch (Pref.direction) {
  841. case 1:
  842. for (var j = 0; j < cols; j++) {
  843. for (i = j; i < len; i += cols) {
  844. resTable = resTables.snapshotItem(i);
  845. resTable.setAttribute('class', 'rest');
  846. resContainer.appendChild(resTable); // 移动结果 Table
  847. }
  848. }
  849. break;
  850. case 2:
  851. for (i = 0; i < len; i++) {
  852. resTable = resTables.snapshotItem(i);
  853. resTable.setAttribute('class', 'rest');
  854. resContainer.appendChild(resTable); // 移动结果 Table
  855. }
  856. break;
  857. }
  858. }
  859. }
  860.  
  861.  
  862. // 统一格式,美化版面
  863. function format(id, Pref){
  864. var i, j, len;
  865. var resContainer = document.getElementById(id);
  866. var resTables = matchNode('//div[@id="' + id + '"]/table[@class="rest" or @class="plus"]');
  867. len = resTables.snapshotLength;
  868. if (len > 0) {
  869. switch (Pref.displayMode) {
  870. case 1:
  871. break;
  872. case 2:
  873. /*
  874. * 由于使用的 -moz-column-count 样式分列,为了保持每一列顶部对齐,必须使得每列所包含的 child 数量一样,所以要插入 plusNum 个 table 充数
  875. */
  876. var modNum = len % Pref.columns;
  877. if (modNum > 0) {
  878. // plusNum 为统一格式而补充的 table 数量; insertIndex 为需要插入补充 table 的位置
  879. var plusNum = Pref.columns - modNum;
  880. var insertIndex = Math.floor(len / Pref.columns);
  881. for (i = 0; i < plusNum; i++) {
  882. var plustable = document.createElement('table');
  883. plustable.setAttribute('class', 'plus');
  884. plustable.innerHTML = '<br />';
  885. resContainer.insertBefore(plustable, resTables.snapshotItem(len - 1 - insertIndex * i).nextSibling);
  886. }
  887. }
  888. break;
  889. case 3:
  890. /*
  891. * 由于使用的 -moz-column-count 样式分列,为了保持每一列顶部对齐,必须使得每列所包含的 child 数量一样,所以要插入 plusNum 个 table 充数
  892. */
  893. var modNum = len % Pref.columns;
  894. if (modNum > 0) {
  895. // plusNum 为统一格式而补充的 table 数量; insertIndex 为需要插入补充 table 的位置
  896. var plusNum = Pref.columns - modNum;
  897. var insertIndex = Math.floor(len / Pref.columns);
  898. for (i = 1; i <= plusNum; i++) {
  899. var plustable = document.createElement('table');
  900. plustable.setAttribute('class', 'plus');
  901. plustable.innerHTML = '<br />';
  902. resContainer.insertBefore(plustable, resTables.snapshotItem(insertIndex * i));
  903. }
  904. }
  905. break;
  906. case 4:
  907. /*
  908. * 由于使用的 -moz-column-count 样式分列,为了保持每一列顶部对齐,必须使得每列所包含的 child 数量一样,所以要插入 plusNum 个 table 充数
  909. */
  910. var modNum = len % Pref.columns;
  911. if (modNum > 0) {
  912. // plusNum 为统一格式而补充的 table 数量。这些 table 将补充在末尾。
  913. var plusNum = Pref.columns - modNum;
  914. for (i = 0; i < plusNum; i++) {
  915. var plustable = document.createElement('table');
  916. plustable.setAttribute('class', 'plus');
  917. plustable.innerHTML = '<br />';
  918. resContainer.appendChild(plustable);
  919. }
  920. }
  921. break;
  922. }
  923.  
  924. var Highest, height, isDiff;
  925. var tables = matchNode('//div[@id="' + id + '"]/table[@class="rest" or @class="plus"]');
  926. len = tables.snapshotLength;
  927. var rows = len / Pref.columns;
  928.  
  929. var modTables = [];
  930. for (j = 0; j < rows; j++) {
  931. isDiff = false;
  932. Highest = tables.snapshotItem(j).offsetHeight;
  933. // 找出同一行 table 中的最大高度
  934. for (i = j+rows; i < len; i += rows) {
  935. height = tables.snapshotItem(i).offsetHeight;
  936. if (height != Highest) {
  937. isDiff = true;
  938. if (height > Highest) {
  939. Highest = height;
  940. }
  941. }
  942. }
  943.  
  944. if (isDiff == true) {
  945. // 将需要改变高度的 table 和其所需高度放入数组中
  946. for (i = j; i < len; i += rows) {
  947. var tmp = [];
  948. tmp.push(tables.snapshotItem(i));
  949. tmp.push(Highest);
  950. modTables.push(tmp);
  951. }
  952. }
  953. }
  954. // 让同一行的 table 具有相同的高度
  955. len = modTables.length;
  956. resContainer.style.display='none';
  957. for(i=0;i<len;i++){
  958. modTables[i][0].setAttribute('style', 'height: ' + (modTables[i][1]) + 'px !important;');
  959. }
  960. resContainer.style.display='';
  961.  
  962. }
  963. }
  964.  
  965. // 向 head 中添加 CSS 样式
  966. function addCSS(cssString){
  967. var head = document.getElementsByTagName("head")[0];
  968. var css = document.createElement('style');
  969. css.innerHTML = cssString;
  970. head.appendChild(css);
  971. return css;
  972. }
  973.  
  974. // CSS 样式设置有选项变动时,更新预览效果
  975. function cssOnChange(input){
  976. var i, len, cInput;
  977. var css = [];
  978. var inputs = matchNode('//input[@class="' + input.className + '"]');
  979. len = inputs.snapshotLength;
  980. for(i=0;i<len;i++){
  981. cInput = inputs.snapshotItem(i);
  982. if(cInput.value){
  983. css.push(' ' + cInput.name + ': ' + cInput.value + ' !important;');
  984. }
  985. }
  986.  
  987. var textarea = matchNode('//textarea[@id="' + input.className + '_gen"]').snapshotItem(0);
  988. if(css.length==0){ // 如果没有 CSS 设置,则清空 textarea
  989. textarea.innerHTML = textarea.value = ''; // 赋值 innerHTML 是为了可以使用 XPath
  990. }
  991. else{
  992. switch (input.className) {
  993. case 'css_holder':
  994. css.unshift('.rest {');
  995. break;
  996. case 'css_counter':
  997. css.unshift('.bm_num {');
  998. break;
  999. case 'css_keyword':
  1000. css.unshift('.bm_kw {');
  1001. break;
  1002. }
  1003. css.push('}');
  1004. textarea.innerHTML = textarea.value = css.join('\n'); // 赋值 innerHTML 是为了可以使用 XPath
  1005. }
  1006. prefOnChange();
  1007. }
  1008.  
  1009. // 设置界面有选项变动时,更新预览效果
  1010. var previewCss;
  1011. function prefOnChange(){
  1012. var i, len;
  1013. var numcol = document.getElementById('numcol');
  1014. var direction = document.getElementById('direction');
  1015. var mode = document.getElementById('mode');
  1016. var bm_pref_Pref = {
  1017. // 分栏数量,默认 2
  1018. columns : Number(numcol.options[numcol.selectedIndex].value)
  1019. // 搜索结果的排列方向:1-横向;2-纵向(默认)
  1020. ,direction : Number(direction.options[direction.selectedIndex].value)
  1021.  
  1022. // 显示模式:1-紧凑;2-对齐,但比较松散(默认);3-对齐,但比较松散;4-对齐,但比较松散
  1023. ,displayMode : Number(mode.options[mode.selectedIndex].value)
  1024.  
  1025. // 给搜索结果条目添加序号,默认 关闭
  1026. ,addResultNum : document.getElementById('addResultNums').checked
  1027.  
  1028. // 添加缩略图预览,默认 关闭
  1029. ,addPreview : document.getElementById('addPreviews').checked
  1030. // 缩略图大小,默认 100%
  1031. ,PreviewSize : isNaN(document.getElementById('PreviewSize').value)?'100':document.getElementById('PreviewSize').value
  1032.  
  1033. // 添加站点 Favicon,默认 关闭
  1034. ,addFavicon : document.getElementById('addFavicons').checked
  1035.  
  1036. // 让搜索结果适合屏幕宽度,默认 关闭
  1037. ,fitwidth : document.getElementById('fitwidth').checked
  1038.  
  1039. // 添加“在此站点中搜索”
  1040. ,searchSite : document.getElementById('searchSite').checked
  1041. }
  1042.  
  1043. // 阅读方向为“横向”时,排版模式将固定为“紧凑”或“对齐1”
  1044. if(bm_pref_Pref.direction==1 && bm_pref_Pref.displayMode>2){
  1045. bm_pref_Pref.displayMode=2;
  1046. document.getElementById('mode').options[1].selected=true;
  1047. }
  1048. // 获取 CSS 设置
  1049. var css = '';
  1050. var textareas = matchNode('//textarea[string-length(text())>0 and ancestor::table[@class="bm_pref_css"]]');
  1051. len = textareas.snapshotLength;
  1052. for (i = 0; i < len; i++) {
  1053. css += '#bm_pref_gui ' + textareas.snapshotItem(i).value + '\n';
  1054. }
  1055. css += '#bm_pref_gui ' + document.getElementById('customizeCSS').value;
  1056.  
  1057. if(previewCss) previewCss.parentNode.removeChild(previewCss);
  1058. previewCss = addCSS(css);
  1059.  
  1060. var bm_pref_res = document.getElementById('bm_pref_res').cloneNode(true);
  1061. bm_pref_res.removeAttribute('style');
  1062.  
  1063. var resLinks = matchNode('//td['+sRestTDAttribute+'][not(descendant::a[text() = "推广"])]/a', bm_pref_res);
  1064. var bm_pref_ResultNum = 1;
  1065. for (var i = 0; i < resLinks.snapshotLength; i++) {
  1066. var resLink = resLinks.snapshotItem(i);
  1067. // 添加缩略图预览
  1068. if (bm_pref_Pref.addPreview) {
  1069. var div = document.createElement('div');
  1070. div.setAttribute('style', 'border: 1px solid rgb(187, 187, 187); float: left; margin: 2px 4px 5px 0px; width: ' + 111 * Number(bm_pref_Pref.PreviewSize) / 100 + 'px; height: ' + 82 * Number(bm_pref_Pref.PreviewSize) / 100 + 'px; background-color: rgb(170, 170, 170);');
  1071. resLink.parentNode.insertBefore(div, resLink);
  1072. }
  1073. // 给搜索结果条目添加序号
  1074. if (bm_pref_Pref.addResultNum) {
  1075. var num = document.createElement('span');
  1076. num.setAttribute('class', 'bm_num');
  1077. num.innerHTML = '&nbsp;' + (bm_pref_ResultNum++) + '&nbsp;';
  1078. resLink.parentNode.insertBefore(num, resLink);
  1079. }
  1080. // 添加站点 Favicon
  1081. if (bm_pref_Pref.addFavicon) {
  1082. var div = document.createElement('div');
  1083. div.setAttribute('style', 'border: 1px solid rgb(187, 187, 187); margin: 3px 4px -3px 0px; width: 16px; height: 16px; background-color: rgb(170, 170, 170); display: inline-block;');
  1084. resLink.parentNode.insertBefore(div, resLink);
  1085. }
  1086. }
  1087.  
  1088. // 添加“在此站点中搜索”
  1089. if (bm_pref_Pref.searchSite) {
  1090. var cacheLinks = matchNode('//a[text() = "百度快照"]', bm_pref_res);
  1091. len = cacheLinks.snapshotLength;
  1092. for(i=0;i<len;i++){
  1093. var cacheLink = cacheLinks.snapshotItem(i);
  1094. var a = document.createElement('a');
  1095. with(a){
  1096. innerHTML = '在此站点中搜索';
  1097. setAttribute('class','m');
  1098. setAttribute('href','javascript: void(0);');
  1099. }
  1100. cacheLink.parentNode.insertBefore(a,cacheLink.nextSibling);
  1101. cacheLink.parentNode.insertBefore(document.createTextNode(' - '),cacheLink.nextSibling);
  1102. }
  1103. }
  1104.  
  1105. // 适合宽度
  1106. var divs = matchNode('//td['+sRestTDAttribute+']', bm_pref_res);
  1107. len = divs.snapshotLength;
  1108. for (i = 0; i < len; i++) {
  1109. if (bm_pref_Pref.fitwidth) {
  1110. divs.snapshotItem(i).setAttribute('style','width: 200em !important;');
  1111. }
  1112. else {
  1113. divs.snapshotItem(i).setAttribute('style','width: 32em !important;');
  1114. }
  1115. }
  1116. // 设置分栏格式
  1117. movePops_and_MultiCol(bm_pref_res, 'pref', bm_pref_Pref);
  1118. // 先清除现有的预览效果
  1119. var div = matchNode('//div[@id="bm_pref_res" and not(contains(@style,"display:"))]').snapshotItem(0);
  1120. if (div) div.parentNode.removeChild(div);
  1121.  
  1122. // 添加新的预览效果
  1123. document.getElementById('bm_pref_preview').appendChild(bm_pref_res);
  1124. // 设置分栏数量
  1125. var bm_pref_container = document.getElementById('bm_page_pref');
  1126. bm_pref_container.setAttribute('style','-moz-column-count: ' + bm_pref_Pref.columns + '; -moz-column-gap: 0.2em; -webkit-column-count: ' + bm_pref_Pref.columns + '; -webkit-column-gap: 0.2em;');
  1127.  
  1128. // 统一格式,美化版面
  1129. format('bm_page_pref', bm_pref_Pref);
  1130. }
  1131.  
  1132. // 添加 CSS 样式候选项
  1133. var lstVL=null;
  1134. function addList(target, options, style){
  1135. if (!target || !options)
  1136. return;
  1137. if (lstVL != null) {
  1138. lstVL.parentNode.removeChild(lstVL);
  1139. lstVL = null;
  1140. return;
  1141. }
  1142. var input;
  1143. var lst = document.createElement("div");
  1144. lst.className = "virtual-list";
  1145. if (target.nodeName.toUpperCase() == "INPUT") {
  1146. input = target;
  1147. lst.style.marginTop = input.offsetHeight + "px";
  1148. }
  1149. else {
  1150. input = target.previousSibling;
  1151. lst.style.marginLeft = -(input.offsetWidth) + "px";
  1152. }
  1153.  
  1154. lst.style.minWidth = (target.offsetWidth + input.offsetWidth - 4) + "px";
  1155. lstVL = lst;
  1156. var setVal = function(ev){
  1157. input.value = ev.target.innerHTML;
  1158. input.focus();
  1159. input.blur();
  1160. lstVL.parentNode.removeChild(lstVL);
  1161. lstVL = null;
  1162. cssOnChange(input);
  1163. };
  1164. var db = options.split(",");
  1165. var len = db.length;
  1166. for (var x = 0; x < len; x++) {
  1167. var p = document.createElement("span");
  1168. p.innerHTML = db[x];
  1169. p.addEventListener("click", setVal, false);
  1170. if (input.value == db[x])
  1171. p.className = "selected";
  1172. lst.appendChild(p);
  1173. }
  1174. target.appendChild(lst);
  1175. return false;
  1176. };
  1177. function getColor(ev){
  1178. var x = ev.layerX - 10, y= ev.layerY - 10;
  1179. var Rmx = 0, Gmx = 0, Bmx = 0;
  1180. if (y <= 32) {
  1181. Rmx = 255;
  1182. Gmx = (y / 32) * 255;
  1183. Bmx = 0;
  1184. }
  1185. else
  1186. if (y <= 64) {
  1187. y = y - 32;
  1188. Rmx = 255 - (y / 32) * 255;
  1189. Gmx = 255;
  1190. Bmx = 0;
  1191. }
  1192. else
  1193. if (y <= 96) {
  1194. y = y - 64;
  1195. Rmx = 0;
  1196. Gmx = 255;
  1197. Bmx = (y / 32) * 255;
  1198. }
  1199. else
  1200. if (y <= 128) {
  1201. y = y - 96;
  1202. Rmx = 0;
  1203. Gmx = 255 - (y / 32) * 255;
  1204. Bmx = 255;
  1205. }
  1206. else
  1207. if (y <= 160) {
  1208. y = y - 128;
  1209. Rmx = (y / 32) * 255;
  1210. Gmx = 0;
  1211. Bmx = 255;
  1212. }
  1213. else {
  1214. y = y - 160;
  1215. Rmx = 255;
  1216. Gmx = 0;
  1217. Bmx = 255 - (y / 32) * 255;
  1218. };
  1219. var r, g, b;
  1220. if (x <= 50) {
  1221. r = Math.abs(Math.floor(Rmx * x / 50));
  1222. g = Math.abs(Math.floor(Gmx * x / 50));
  1223. b = Math.abs(Math.floor(Bmx * x / 50));
  1224. }
  1225. else {
  1226. x -= 50;
  1227. r = Math.abs(Math.floor(Rmx + (x / 50) * (255 - Rmx)));
  1228. g = Math.abs(Math.floor(Gmx + (x / 50) * (255 - Gmx)));
  1229. b = Math.abs(Math.floor(Bmx + (x / 50) * (255 - Bmx)));
  1230. };
  1231. r = r>255?255:r;
  1232. g = g>255?255:g;
  1233. b = b>255?255:b;
  1234. var c = "#";
  1235. c += Math.floor(r / 16).toString(16);
  1236. c += (r % 16).toString(16);
  1237. c += Math.floor(g / 16).toString(16);
  1238. c += (g % 16).toString(16);
  1239. c += Math.floor(b / 16).toString(16);
  1240. c += (b % 16).toString(16);
  1241. return c.toUpperCase();
  1242. };
  1243. function addColorPicker(target){
  1244. var cp = document.getElementById("colorpicker");
  1245. if (cp) {
  1246. cp.parentNode.removeChild(cp);
  1247. return;
  1248. }
  1249. cp = document.createElement("div");
  1250. cp.id = "colorpicker";
  1251. var input;
  1252. if (target.nodeName.toUpperCase() == "INPUT") {
  1253. input = target;
  1254. cp.style.marginTop = input.offsetHeight + "px";
  1255. }
  1256. else {
  1257. input = target.previousSibling;
  1258. cp.style.marginLeft = "-100px";
  1259. }
  1260. var pre = document.createElement("span");
  1261. var img = document.createElement("img");
  1262. with (img) {
  1263. src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAADACAIAAAB9DVH7AAAABGdBTUEAALGPC/xhBQAAAAd0SU1FB9IIDwckH4KetsUAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAAsdEVYdENyZWF0aW9uIFRpbWUAVGh1IDE1IEF1ZyAyMDAyIDE5OjM0OjU1ICsxMjAwuqQvdAAABmlJREFUeNrtneGJHEcUhIWw4QQS7P3TDycgcAICRyBwAgJHIByBUAbCEQhnIGcghyBnIIdwCzJIYIOFxPT8ebd1Va97unt2a6hfu7Nzs9PfvVdTM9tz/15ZrooeFz0pelr0rOh50Yuil0Wvi94UvS16V/S+6EPRTdH/UQ+vFv3weNGPTxb99HTRz88W/fJ80a8vFr16uei314t+f7Poj7eL/ny36K/3i/7+sOjm5qu+LffveaEX7mB9R+iK0ENCB0WPisAGHxSBHfu+6NS3Ew6Wl5MHa1qO1k8BoNa/DoBivmD+39DL3QdrNsSui5gNMjsmImaycmRNwtF1ENPycqUqNsEG1sHLSJ/16LS26481xctkTemzIj6VPgsAxezYnX7dPmtun7U2puY+S+qPoFHaZ+3BZ63jxgz7dj6rnV93zTqPPKvSZ4ENMnmWfdZ8PguMGzPsa2Gq5EjKRZ1nTeyzVhOcs/LNI9OclbfP2nmeJZ0SAp/VlyPXrJ4+C5yvM+diPX2W86wLyLOAmvusLYuXyRqbZzGlqnlk6uuG++yGQ8qZJPusnZN1evncSMegVlue6GCZrAw1n4riKyss6x2k8ZWoI6E+9JmsRmSB4w04AmUorszgE1n7FLS+VckRRsxk1ZEVjy7DEaAmIrZdzQL0SazdipjJ2sw6gBGQ+mOsYkzNqqxQ68fJCuWatRlZkQjwFsMRU8WYmhUrlMQaQMzdcHTNyvVHQITks4Bxl3pfRMw1awOypHYG1pHQyNUsaR1p57H/MllD86zKkYyMNEHDedbceVau1wBqbghJbTHXnZ1nTZNnSYiBxsQkCgxHOcTA9zJZffMsMEqAGulMkKlZoGNKiDnP2lWexUSUADpQs0AGm2t5Pjcc3Q1zASnIGGLmKdUscHFI8n3OsybOs1rd0CD5rIgYuAze8DYIkzX0RPpzazGIgVcY6O58xWSNJOuqkQ7Ery+kV+JNrolXTNY2ZHWg5nD6xzsAHwkWIHfDvmSBAy8BtYLwIAjgA6CLW17XYSYIiN+LYs1k1ZLFHHgwbpGaVjUrAsXgA6hZV3bNGu2zwOBUVjGpZsW31u3E4pVri7cUL5PVvhtWAgWqT85nRWokoECpQlXMZG1YsySgwMqAI6lR5oBKWnmTlSQrx0hcBzDCcBTXkf567QmgydpTniWhkXP5YJ0mYJqs7nmW1H0YNK4JgYwh169ds/qSxThdCSiGNaZmMecGElDOs/aQZwGgDsoFG2C4JI4YoFyzpjk3rGyUTJouicn7nWftIc+SfM1BuTzD+Cwm789dLnQ3HJ3BS6UqvsLco5CrWZVyN5wvdZDoGyLnWdOR9R8h5ia+fwgdg5hPMX+d+RYma0uyKjlab8cEIHwsOqY0iDWT1apmdShVEmKji5fJypHFHG/mdwuRGqbl5SbQ6saayZrSZzH9EUD38bTss87OZ0nFC1SxSp/VlzWT1dNnVSLW3Gcx+2OfNZ/P2q7lNfdZK7NNWDNZE/gsMJKVPst51mXnWasYIo6p3+HnWIvI22ftPM8CPltCjDklYPbn3yL7rD34LKnl5SbQYk4SnWddUp7V02cBlxf3ORYv+6w9+KwcR4zP8nVD+6ymiEm9Type9lmDuuEQ1hjomEbJ5Fl3enqTtTFZp5fznz3LZLUny7NnmaymZHn2LJPVlCzPnuWa1d1nXfTsWSarfTf07Fkma+OaddGzZ5msJFmePcs+a2951pnMnmWyuuZZFzR7lslqRpZnzzJZM+VZZzt7lsnqcW5Y2Sh3OXuWyeqRZ13i7Fkmq0cGf4mzZ5mswRHN2c6eZbJGHaztHtjaassmaz6ypAEETzg9Ek9TlX6805U+k9WMLHC8pQc2H08/epfBBzziPD7rvJIjhJjJqiULPBwecASokZ4JXVmzAH0Sa7cgZrI2tA5gBKT+GKsYU7MqK9T6capCuWZtSFYkArzFcMRUMaZmxQolsQYQczccXbNy/REQIfksYNyl3hcRc83agCypnYF1JDRyNUtaR9p55L9M1uA8q3IkIyNN0HCeNXeeles1gBppMhqmLea6s/OsafIsCTHQmI7KTCGAoxxi4HuZrL55FhglQI10JsjULNAxJcScZ+0qz2IiSgAdqFkgg821PJ8bju6GuYAUZAwx85RqFrg4JPk+51kT51mtbmiQfFZEDFwGb3YbhMkSli9l5MGTJ+WhBgAAAABJRU5ErkJggg==";
  1264. addEventListener("mousemove", function(ev){
  1265. var c = getColor(ev);
  1266. pre.style.background = c;
  1267. }, false);
  1268. addEventListener("click", function(ev){
  1269. var c = getColor(ev);
  1270. input.value = c;
  1271. input.focus();
  1272. input.blur();
  1273. cp.parentNode.removeChild(cp);
  1274. cssOnChange(input);
  1275. }, false);
  1276. addEventListener("mouseout", function(ev){
  1277. cp.parentNode.removeChild(cp);
  1278. }, false);
  1279. }
  1280. cp.appendChild(img);
  1281. cp.appendChild(pre);
  1282. target.appendChild(cp);
  1283. return false;
  1284. };
  1285.  
  1286. // 生成 CSS 选项的 table
  1287. function addCssTable(type, tableStyle, css){
  1288. css = (css + '').replace(/null/ig,'');
  1289. return ' <table id="bm_pref_css_' + type + '" class="bm_pref_css" style="' + tableStyle +'">\
  1290. <tbody>\
  1291. <tr>\
  1292. <td>\
  1293. <label>\
  1294. Font-Size:\
  1295. </label>\
  1296. </td>\
  1297. <td>\
  1298. <input class="css_' + type + '" name="font-size" size="8" type="text" value="' + ((css.match(/\sfont-size:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1299. </td>\
  1300. <td>\
  1301. <label>\
  1302. Font-Color:\
  1303. </label>\
  1304. </td>\
  1305. <td>\
  1306. <input class="css_' + type + '" name="color" size="8" type="text" value="' + ((css.match(/\scolor:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1307. </td>\
  1308. </tr>\
  1309. <tr>\
  1310. <td>\
  1311. <label>\
  1312. Font-Weight:\
  1313. </label>\
  1314. </td>\
  1315. <td>\
  1316. <input class="css_' + type + '" name="font-weight" size="8" type="text" value="' + ((css.match(/\sfont-weight:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1317. </td>\
  1318. <td>\
  1319. <label>\
  1320. Text-Decoration:\
  1321. </label>\
  1322. </td>\
  1323. <td>\
  1324. <input class="css_' + type + '" name="text-decoration" size="8" type="text" value="' + ((css.match(/\stext-decoration:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1325. </td>\
  1326. </tr>\
  1327. <tr>\
  1328. <td>\
  1329. <label>\
  1330. Text-Align:\
  1331. </label>\
  1332. </td>\
  1333. <td>\
  1334. <input class="css_' + type + '" name="text-align" size="8" type="text" value="' + ((css.match(/\stext-align:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1335. </td>\
  1336. <td>\
  1337. <label>\
  1338. White-Space:\
  1339. </label>\
  1340. </td>\
  1341. <td>\
  1342. <input class="css_' + type + '" name="white-space" size="8" type="text" value="' + ((css.match(/\swhite-space:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1343. </td>\
  1344. </tr>\
  1345. <tr>\
  1346. <td>\
  1347. <label>\
  1348. Background-Color:\
  1349. </label>\
  1350. </td>\
  1351. <td>\
  1352. <input class="css_' + type + '" name="background-color" size="8" type="text" value="' + ((css.match(/\sbackground-color:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1353. </td>\
  1354. <td>\
  1355. <label>\
  1356. Border-Color:\
  1357. </label>\
  1358. </td>\
  1359. <td>\
  1360. <input class="css_' + type + '" name="border-color" size="8" type="text" value="' + ((css.match(/\sborder-color:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1361. </td>\
  1362. </tr>\
  1363. <tr>\
  1364. <td>\
  1365. <label>\
  1366. Border-Style:\
  1367. </label>\
  1368. </td>\
  1369. <td>\
  1370. <input class="css_' + type + '" name="border-style" size="8" type="text" value="' + ((css.match(/\sborder-style:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1371. </td>\
  1372. <td>\
  1373. <label>\
  1374. Border-Width:\
  1375. </label>\
  1376. </td>\
  1377. <td>\
  1378. <input class="css_' + type + '" name="border-width" size="8" type="text" value="' + ((css.match(/\sborder-width:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1379. </td>\
  1380. </tr>\
  1381. <tr>\
  1382. <td>\
  1383. <label>\
  1384. Margin-Left:\
  1385. </label>\
  1386. </td>\
  1387. <td>\
  1388. <input class="css_' + type + '" name="margin-left" size="8" type="text" value="' + ((css.match(/\smargin-left:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1389. </td>\
  1390. <td>\
  1391. <label>\
  1392. Padding-Left:\
  1393. </label>\
  1394. </td>\
  1395. <td>\
  1396. <input class="css_' + type + '" name="padding-left" size="8" type="text" value="' + ((css.match(/\spadding-left:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1397. </td>\
  1398. </tr>\
  1399. <tr>\
  1400. <td>\
  1401. <label>\
  1402. Margin-Right:\
  1403. </label>\
  1404. </td>\
  1405. <td>\
  1406. <input class="css_' + type + '" name="margin-right" size="8" type="text" value="' + ((css.match(/\smargin-right:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1407. </td>\
  1408. <td>\
  1409. <label>\
  1410. Padding-Right:\
  1411. </label>\
  1412. </td>\
  1413. <td>\
  1414. <input class="css_' + type + '" name="padding-right" size="8" type="text" value="' + ((css.match(/\spadding-right:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1415. </td>\
  1416. </tr>\
  1417. <tr>\
  1418. <td>\
  1419. <label>\
  1420. Margin-Top:\
  1421. </label>\
  1422. </td>\
  1423. <td>\
  1424. <input class="css_' + type + '" name="margin-top" size="8" type="text" value="' + ((css.match(/\smargin-top:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1425. </td>\
  1426. <td>\
  1427. <label>\
  1428. Padding-Top:\
  1429. </label>\
  1430. </td>\
  1431. <td>\
  1432. <input class="css_' + type + '" name="padding-top" size="8" type="text" value="' + ((css.match(/\spadding-top:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1433. </td>\
  1434. </tr>\
  1435. <tr>\
  1436. <td>\
  1437. <label>\
  1438. Margin-Bottom:\
  1439. </label>\
  1440. </td>\
  1441. <td>\
  1442. <input class="css_' + type + '" name="margin-bottom" size="8" type="text" value="' + ((css.match(/\smargin-bottom:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1443. </td>\
  1444. <td>\
  1445. <label>\
  1446. Padding-Bottom:\
  1447. </label>\
  1448. </td>\
  1449. <td>\
  1450. <input class="css_' + type + '" name="padding-bottom" size="8" type="text" value="' + ((css.match(/\spadding-bottom:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1451. </td>\
  1452. </tr>\
  1453. <tr>\
  1454. <td>\
  1455. <label>\
  1456. Float:\
  1457. </label>\
  1458. </td>\
  1459. <td>\
  1460. <input class="css_' + type + '" name="float" size="8" type="text" value="' + ((css.match(/\sfloat:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1461. </td>\
  1462. <td>\
  1463. <label>\
  1464. Clear:\
  1465. </label>\
  1466. </td>\
  1467. <td>\
  1468. <input class="css_' + type + '" name="clear" size="8" type="text" value="' + ((css.match(/\sclear:[^!]*!/i) + '').replace(/.*:\s*|\s*!|null/ig,'') + '') + '"><span class="bm_pref_css_span">▼</span>\
  1469. </td>\
  1470. </tr>\
  1471. <tr>\
  1472. <td colspan="4">\
  1473. <label>\
  1474. 生成的 CSS \
  1475. </label><br>\
  1476. <label>\
  1477. <textarea id="css_' + type + '_gen" rows="3" cols="60" wrap="off" style="font-size: small;" readonly>' + css + '</textarea>\
  1478. </label>\
  1479. </td>\
  1480. </tr>\
  1481. </tbody>\
  1482. </table>\
  1483. ';
  1484. }
  1485.  
  1486. // 闪动具有指定 class 的元素
  1487. function blink(cls, count){
  1488. if(count>5){
  1489. return;
  1490. }
  1491. var i, len;
  1492. var eles = matchNode('//*[@class="' + cls + '" and ancestor::div[@id="bm_pref_gui"]]');
  1493. len = eles.snapshotLength;
  1494. for(i=0;i<len;i++){
  1495. eles.snapshotItem(i).style.border='1px solid red';
  1496. }
  1497. setTimeout(function(){
  1498. for (i = 0; i < len; i++) {
  1499. eles.snapshotItem(i).style.border = '';
  1500. }
  1501. setTimeout(function(){
  1502. blink(cls, ++count);
  1503. }, 150);
  1504. }, 150);
  1505. }
  1506.  
  1507. // 设置参数
  1508. function SetPreferences(){
  1509. var i, len;
  1510.  
  1511. var bodyElements = [], bodyElementsDisplay = [];
  1512. var allElements = document.body.childNodes;
  1513. len = allElements.length;
  1514. for(i=0;i<len;i++){
  1515. if (allElements[i].nodeType==1 && getComputedStyle(allElements[i],'').display != 'none'){
  1516. bodyElements.push(allElements[i]);
  1517. bodyElementsDisplay.push(getComputedStyle(allElements[i],'').display);
  1518. allElements[i].style.display='none';
  1519. };
  1520. }
  1521.  
  1522. var code2keyTable={'65':'A','66':'B','67':'C','68':'D','69':'E','70':'F','71':'G','72':'H','73':'I','74':'J','75':'K','76':'L','77':'M','78':'N','79':'O','80':'P','81':'Q','82':'R','83':'S','84':'T','85':'U','86':'V','87':'W','88':'X','89':'Y','90':'Z','48':'0','49':'1','50':'2','51':'3','52':'4','53':'5','54':'6','55':'7','56':'8','57':'9','96':'Numpad 0','97':'Numpad 1','98':'Numpad 2','99':'Numpad 3','100':'Numpad 4','101':'Numpad 5','102':'Numpad 6','103':'Numpad 7','104':'Numpad 8','105':'Numpad 9','106':'Numpad *','107':'Numpad +','108':'Numpad Enter','109':'Numpad -','110':'Numpad .','111':'Numpad /','112':'F1','113':'F2','114':'F3','115':'F4','116':'F5','117':'F6','118':'F7','119':'F8','120':'F9','121':'F10','122':'F11','123':'F12','8':'BackSpace','9':'Tab','12':'Clear','13':'Enter','16':'Shift','17':'Control','18':'Alt','20':'Cape Lock','27':'Esc','32':'Spacebar','33':'Page Up','34':'Page Down','35':'End','36':'Home','37':'←/Left Arrow','38':'↑/Up Arrow','39':'→/Right Arrow','40':'↓/Down Arrow','45':'Insert','46':'Delete','144':'Num Lock','186':';:','187':'=+','188':',<','189':'-_','190':'.>','191':'/?','192':'`~','219':'[{','220':'\|','221':']}','222':'"'};
  1523.  
  1524. // 将 keycode 转换成按键名称
  1525. function parse2keys(keycodes){
  1526. var array = keycodes.split('+');
  1527. array[array.length-1]=code2keyTable[array[array.length-1]] || '';
  1528. return array.join('+');
  1529. }
  1530.  
  1531. // 将设置界面的 css 添加到 head 中
  1532. addCSS('\
  1533. #bm_pref_gui {\
  1534. background-color: white;\
  1535. border: 2px solid black;\
  1536. margin: 0 auto;\
  1537. text-align: left;\
  1538. -moz-border-radius: 0.5em;\
  1539. -webkit-border-radius: 0.5em;\
  1540. }\
  1541. \
  1542. #bm_pref_gui_title {\
  1543. font-weight: bold;\
  1544. background: #CCCCCC;\
  1545. color: #666666;\
  1546. }\
  1547. \
  1548. #bm_pref_gui fieldset {\
  1549. margin-left: 1em;\
  1550. margin-right: 1em;\
  1551. margin-top: 0.5em;\
  1552. margin-bottom: 0.5em;\
  1553. }\
  1554. \
  1555. #bm_pref_gui legend {\
  1556. font-size : 12pt;\
  1557. font-weight : bold;\
  1558. }\
  1559. \
  1560. #bm_pref_gui .f {\
  1561. line-height: 1.5em;\
  1562. }\
  1563. \
  1564. #bm_pref_gui label {\
  1565. font-size: 13px;\
  1566. margin-left: 0.5em;\
  1567. }\
  1568. \
  1569. #bm_pref_options div {\
  1570. margin-bottom: 0.3em;\
  1571. padding-left: 1em;\
  1572. }\
  1573. \
  1574. .bm_pref_css {\
  1575. font-size: small;\
  1576. padding: 0.5em 0;\
  1577. white-space: nowrap;\
  1578. }\
  1579. \
  1580. .bm_pref_css_span {\
  1581. display : inline-block;\
  1582. font-size : 12px;\
  1583. border : 1px solid #999;\
  1584. color : #000;\
  1585. background-color : #fff;\
  1586. padding : 1px;\
  1587. margin-right: 0.5em;\
  1588. -moz-border-radius-topright :5px;\
  1589. -moz-border-radius-topleft :0px;\
  1590. -moz-border-radius-bottomright :5px;\
  1591. -moz-border-radius-bottomleft :0px;\
  1592. -webit-border-radius-topright :5px;\
  1593. -webit-border-radius-topleft :0px;\
  1594. -webit-border-radius-bottomright :5px;\
  1595. -webit-border-radius-bottomleft :0px;\
  1596. }\
  1597. .bm_pref_css_span:hover {\
  1598. color : #fff;\
  1599. background-color : #000;\
  1600. cursor : default;\
  1601. }\
  1602. .virtual-list {\
  1603. position : absolute;\
  1604. display : block !important;\
  1605. overflow-y : auto;\
  1606. overflow-x : hidden;\
  1607. margin : 0;\
  1608. margin-top : 2px;\
  1609. padding : 0 !important;\
  1610. max-height : 200px;\
  1611. border : 1px solid #333;\
  1612. background-color : white;\
  1613. }\
  1614. \
  1615. .virtual-list span {\
  1616. display : block !important;\
  1617. margin : 0;\
  1618. padding : 2px 0.5em;\
  1619. font-family : Arial, Hevetica, sans-serif;\
  1620. font-size : 9pt;\
  1621. color : #000;\
  1622. text-align : left;\
  1623. }\
  1624. \
  1625. .virtual-list span:hover {\
  1626. background-color : #33f;\
  1627. color : white;\
  1628. }\
  1629. \
  1630. .virtual-list span.selected {\
  1631. background-color : #88f;\
  1632. color : white;\
  1633. }\
  1634. \
  1635. #colorpicker {\
  1636. position : absolute;\
  1637. display : block;\
  1638. margin-top : 2px;\
  1639. margin-left : -30px;\
  1640. z-index : 9999999;\
  1641. }\
  1642. #colorpicker span {\
  1643. display : inline-block;\
  1644. width : 24px;\
  1645. height : 24px;\
  1646. border : 2px solid #000;\
  1647. margin-left : 2px;\
  1648. vertical-align: top;\
  1649. }\
  1650. #colorpicker img {\
  1651. width : 100px;\
  1652. height : 192px;\
  1653. padding : 7px;\
  1654. background-color : #888;\
  1655. border : 3px solid #333;\
  1656. cursor : crosshair;\
  1657. }\
  1658. #default_button {\
  1659. width: 12em;\
  1660. }\
  1661. ');
  1662. var bgDiv = document.createElement('div');
  1663. with(bgDiv){
  1664. setAttribute('id','preferences');
  1665. setAttribute('style','display: table; width:800px; height: 100%;');
  1666. innerHTML = '<div style="display: table-cell; text-align: center; vertical-align: middle; padding: 1em;">\
  1667. <div id="bm_pref_gui">\
  1668. <center>\
  1669. <table width="100%">\
  1670. <tr id="bm_pref_gui_title">\
  1671. <td colspan="2">\
  1672. <div style="float: left; padding-left: 0.8em; font-size: small;">BaiduMonkeyY 参数设置&nbsp;&nbsp;&nbsp;&nbsp;v' + scriptVersion + '</div>\
  1673. <div id="check_update" style="float: right; padding-right: 0.8em; font-size: small;"><a href="' + scriptUrl + '" target="_blank">访问页面</a></div>\
  1674. <div style="float: right; padding-right: 0.8em; font-size: small;">欢迎来<a href="mailto:in2@foxmail.com" target="_blank">这里</a>发表任何意见或建议。</div>\
  1675. </td>\
  1676. </tr>\
  1677. <tr>\
  1678. <td colspan="2">\
  1679. <fieldset id="bm_pref_preview">\
  1680. <legend>效果预览</legend>\
  1681. <div id="bm_pref_res" class="bm_pref_preview_id-res" style="display: none;">\
  1682. <table border="0" cellpadding="0" cellspacing="0">\
  1683. <tbody>\
  1684. <tr>\
  1685. <td class="c-default">\
  1686. <a href="javascript: void(0);"><font size="3">标题一<em class="bm_kw">关键字</em>标题一</font></a>\
  1687. <br>\
  1688. <font size="-1">\
  1689. 描述一<em class="bm_kw">关键字</em>描述一... 描述一描述一描述一 描述一描述一描述一 描述一描述一描述一 描述一描述一描述一 描述一描述一描述一 <b>...</b>描述一<em class="bm_kw">关键字</em>描述一. <b>...</b> 描述一描述一描述一 描述一描述一描述一 描述一描述一描述一 描述一描述一描述一 描述一描述一描述一...\
  1690. <br>\
  1691. <font color="#008000">\
  1692. www.urlstring1.com/path/ 00K 2000-1-1 \
  1693. </font>\
  1694. - <a href="javascript: void(0);" class="m">百度快照</a>\
  1695. <br>\
  1696. </font>\
  1697. </td>\
  1698. </tr>\
  1699. </tbody>\
  1700. </table>\
  1701. <table border="0" cellpadding="0" cellspacing="0">\
  1702. <tbody>\
  1703. <tr>\
  1704. <td class="c-default">\
  1705. <a href="javascript: void(0);"><font size="3">标题二<em class="bm_kw">关键字</em>标题二</font></a>\
  1706. <br>\
  1707. <font size="-1">\
  1708. 描述二<em class="bm_kw">关键字</em>描述二... 描述二描述二描述二 描述二描述二描述二 描述二描述二描述二 描述二描述二描述二 描述二描述二描述二 <b>...</b>\
  1709. <br>\
  1710. <font color="#008000">\
  1711. www.urlstring2.com/path/ 00K 2000-1-1 \
  1712. </font>\
  1713. - <a href="javascript: void(0);" class="m">百度快照</a>\
  1714. <br>\
  1715. </font>\
  1716. </td>\
  1717. </tr>\
  1718. </tbody>\
  1719. </table>\
  1720. <table border="0" cellpadding="0" cellspacing="0">\
  1721. <tbody>\
  1722. <tr>\
  1723. <td class="c-default">\
  1724. <a href="javascript: void(0);"><font size="3">标题三<em class="bm_kw">关键字</em>标题三</font></a>\
  1725. <br>\
  1726. <font size="-1">\
  1727. 描述三<em class="bm_kw">关键字</em>描述三... 描述三描述三描述三 描述三描述三描述三 描述三描述三描述三 描述三描述三描述三 描述三描述三描述三 <b>...</b>\
  1728. <br>\
  1729. <font color="#008000">\
  1730. www.urlstring3.com/path/ 00K 2000-1-1 \
  1731. </font>\
  1732. <br>\
  1733. </font>\
  1734. </td>\
  1735. </tr>\
  1736. </tbody>\
  1737. </table>\
  1738. <table border="0" cellpadding="0" cellspacing="0">\
  1739. <tbody>\
  1740. <tr>\
  1741. <td class="c-default">\
  1742. <a href="javascript: void(0);"><font size="3">标题四<em class="bm_kw">关键字</em>标题四</font></a>\
  1743. <br>\
  1744. <font size="-1">\
  1745. 描述四<em class="bm_kw">关键字</em>描述四... 描述四描述四描述四 描述四描述四描述四 描述四描述四描述四 描述四描述四描述四 描述四描述四描述四 <b>...</b>描述四<em class="bm_kw">关键字</em>描述四. <b>...</b> 描述四描述四描述四 描述四描述四描述四 描述四描述四描述四 描述四描述四描述四 描述四描述四描述四...\
  1746. <br>\
  1747. <font color="#008000">\
  1748. www.urlstring1.com/path/ 00K 2000-1-1 \
  1749. </font>\
  1750. - <a href="javascript: void(0);" class="m">百度快照</a>\
  1751. <br>\
  1752. </font>\
  1753. </td>\
  1754. </tr>\
  1755. </tbody>\
  1756. </table>\
  1757. </div>\
  1758. </fieldset>\
  1759. </td>\
  1760. </tr>\
  1761. <tr id="bm_pref_options">\
  1762. <td width="50%" valign="top">\
  1763. <fieldset>\
  1764. <legend>常规</legend>\
  1765. <div>\
  1766. <label>&nbsp;分栏数量:\
  1767. <select name="numcol" id="numcol" class="bm_pref_onchange">\
  1768. <option value="1" ' + ((OldPrefColumns==1) ? 'selected="selected"':'') + '>1</option>\
  1769. <option value="2" ' + ((OldPrefColumns==2) ? 'selected="selected"':'') + '>2</option>\
  1770. <option value="3" ' + ((OldPrefColumns==3) ? 'selected="selected"':'') + '>3</option>\
  1771. <option value="4" ' + ((OldPrefColumns==4) ? 'selected="selected"':'') + '>4</option>\
  1772. </select>\
  1773. </label>&nbsp;&nbsp;\
  1774. <label>&nbsp;&nbsp;阅读方向:\
  1775. <select name="direction" id="direction" class="bm_pref_onchange">\
  1776. <option value="1" ' + ((Pref.direction==1) ? 'selected="selected"':'') + '>横向</option>\
  1777. <option value="2" ' + ((Pref.direction==2) ? 'selected="selected"':'') + '>纵向</option>\
  1778. </select>\
  1779. </label>&nbsp;&nbsp;\
  1780. <label>&nbsp;&nbsp;排版模式:\
  1781. <select name="mode" id="mode" class="bm_pref_onchange">\
  1782. <option value="1" ' + ((Pref.displayMode==1) ? 'selected="selected"':'') + '>紧凑</option>\
  1783. <option value="2" ' + ((Pref.displayMode==2) ? 'selected="selected"':'') + '>对齐1</option>\
  1784. <option value="3" ' + ((Pref.displayMode==3) ? 'selected="selected"':'') + '>对齐2</option>\
  1785. <option value="4" ' + ((Pref.displayMode==4) ? 'selected="selected"':'') + '>对齐3</option>\
  1786. </select>\
  1787. </label>&nbsp;&nbsp;\
  1788. <label>\
  1789. <input name="fitwidth" id="fitwidth" class="bm_pref_onchange" type="checkbox" ' + (OldPrefFitwidth ? 'checked="true"':'') + '>&nbsp;适合宽度\
  1790. </label><br>\
  1791. <label>\
  1792. (注:阅读方向为“横向”时,排版模式将固定为“紧凑”或“对齐1”)\
  1793. </label>\
  1794. </div>\
  1795. <div>\
  1796. <label>\
  1797. <input name="floatInput" id="floatInput">&nbsp;\
  1798. </label>\
  1799. </div>\
  1800. <div>\
  1801. <label>\
  1802. <input name="removeAd" id="removeAd" type="checkbox" ' + (Pref.removeAd ? 'checked="true"':'') + '>&nbsp;移除右侧的广告\
  1803. </label>\
  1804. </div>\
  1805. <div>\
  1806. <label>\
  1807. <input name="SearchInOtherEngines" id="SearchInOtherEngines" type="checkbox" ' + (Pref.EnableSearchInOtherEngines ? 'checked="true"':'') + '>&nbsp;添加其他搜索引擎\
  1808. </label>\
  1809. <label>&nbsp;\
  1810. <select name="OtherEnginesTarget" id="OtherEnginesTarget">\
  1811. <option value="_blank" ' + ((Pref.OtherEnginesTarget=='_blank') ? 'selected="selected"':'') + '>在新页面打开</option>\
  1812. <option value="_self" ' + ((Pref.OtherEnginesTarget=='_self') ? 'selected="selected"':'') + '>在当前页面打开</option>\
  1813. </select>\
  1814. </label>&nbsp;&nbsp;\
  1815. <label style="display:none;">\
  1816. <input name="OtherEnginsFloat" id="OtherEnginsFloat" type="checkbox" ' + (Pref.OtherEnginsFloat ? 'checked="true"':'') + '>&nbsp;跟随搜索框浮动\
  1817. </label><br>\
  1818. <label>\
  1819. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (以下内容若不知何意,请勿修改)\
  1820. </label><br>\
  1821. <label>\
  1822. <textarea rows="5" cols="49" id="OtherEngines" style="margin: 0 1.5em;" wrap="off">' + Pref.OtherEngines + '</textarea>\
  1823. </label>\
  1824. </div>\
  1825. <div>\
  1826. <label>\
  1827. \
  1828. </label>\
  1829. <label>\
  1830. <input name="AutoNextPage" id="AutoNextPage">&nbsp;\
  1831. </label>&nbsp;&nbsp;\
  1832. <label>\
  1833. <input name="HideAutoNextPage" id="HideAutoNextPage">&nbsp;\
  1834. </label>\&nbsp;&nbsp;\
  1835. <label>\
  1836. <input name="NextPageWithRS" id="NextPageWithRS">&nbsp;\
  1837. </label>\
  1838. </div>\
  1839. <div>\
  1840. <label>\
  1841. <div>\
  1842. <input name="Focus2NextPageKeys" id="Focus2NextPageKeys"\
  1843. </div>\
  1844. </label>\
  1845. <label>\
  1846. <div>\
  1847. <input name="Focus2PrevPageKeys" id="Focus2PrevPageKeys"\
  1848. </div>\
  1849. </label>\
  1850. </div>\
  1851. <div>\
  1852. <label>\
  1853. <input name="DisableTracking" id="DisableTracking">&nbsp;\
  1854. </label>\
  1855. </div>\
  1856. <div>\
  1857. <label>\
  1858. <input name="Focus2Keyword" id="Focus2Keyword" type="checkbox" ' + (Pref.Focus2Keyword ? 'checked="true"':'') + '>&nbsp;快捷键定位到搜索框并\
  1859. </label>\
  1860. <label>\
  1861. <select name="Focus2KeywordAction" id="Focus2KeywordAction">\
  1862. <option value="1" ' + ((Pref.Focus2KeywordAction==1) ? 'selected="selected"':'') + '>清除全部文字</option>\
  1863. <option value="2" ' + ((Pref.Focus2KeywordAction==2) ? 'selected="selected"':'') + '>紧跟文字之后</option>\
  1864. <option value="3" ' + ((Pref.Focus2KeywordAction==3) ? 'selected="selected"':'') + '>选中全部文字</option>\ </select>\
  1865. </label>\
  1866. <label>&nbsp;&nbsp;&nbsp;快捷键:\
  1867. <input name="Focus2KeywordKeys" id="Focus2KeywordKeys" size="18" value="' + parse2keys(Pref.Focus2KeywordKeys) + '" >\
  1868. </label>\
  1869. </div>\
  1870. </fieldset>\
  1871. <fieldset>\
  1872. <legend>搜索条目</legend>\
  1873. <div>\
  1874. <label>\
  1875. <input name="addPreviews" id="addPreviews">&nbsp;\
  1876. </label>\
  1877. <label>&nbsp;&nbsp;\
  1878. <input id="PreviewSize">\
  1879. </label>\
  1880. </div>\
  1881. <div>\
  1882. <label>\
  1883. <input name="addResultNums" id="addResultNums" class="bm_pref_onchange" type="checkbox" ' + (Pref.addResultNum ? 'checked="true"':'') + '>&nbsp;给搜索结果标序号 ( 1, 2, 3... )\
  1884. </label>\
  1885. <label>\
  1886. <input name="addResultNums_h" id="addResultNums_h" class="bm_pref_onchange" type="checkbox" ' + (Pref.addResultNum_h ? 'checked="true"':'') + '>&nbsp;与标题同行\
  1887. </label>\
  1888. </div>\
  1889. <div>\
  1890. <label>\
  1891. <input name="addFavicons" id="addFavicons" class="bm_pref_onchange">&nbsp;\
  1892. </label>&nbsp;&nbsp;\
  1893. <label>\
  1894. <input name="addFavicons_h" id="addFavicons_h" class="bm_pref_onchange">&nbsp;\
  1895. </label>\
  1896. </div>\
  1897. <div>\
  1898. <label>\
  1899. <input name="searchSite" id="searchSite" class="bm_pref_onchange">&nbsp;\
  1900. </label>\
  1901. </div>\
  1902. <div>\
  1903. <label>\
  1904. &nbsp;\
  1905. </label>\
  1906. </div>\
  1907. </fieldset>\
  1908. <div id="bm_pref_buttons" style="float: right;padding: 1.5em 1em 0 0;">\
  1909. <input value="保存" name="save_button" id="save_button" class="btn" type="button">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
  1910. <input value="取消" name="cancel_button" id="cancel_button" class="btn" type="button">\
  1911. </div>\
  1912. </td>\
  1913. <td width="50%" valign="top">\
  1914. <fieldset>\
  1915. <legend>CSS 样式</legend>\
  1916. <div>\
  1917. <label>\
  1918. <select name="bm_pref_css_list" id="bm_pref_css_list">\
  1919. <option value="holder" selected="selected">条目</option>\
  1920. <option value="counter">序号</option>\
  1921. <option value="keyword">关键字</option>\
  1922. </select>\
  1923. </label>&nbsp;&nbsp;\
  1924. <label>\
  1925. <input value="全部恢复至默认 CSS" name="default_button" id="default_button" class="btn" type="button">\
  1926. </label>\
  1927. </div>\
  1928. <div>\
  1929. ' + addCssTable('holder','border: 1px solid rgb(170, 170, 170);', Pref.CSS.match(/\.rest\s\{[^\}]*\}/i))
  1930. + addCssTable('counter','border: 1px solid rgb(170, 170, 170); display: none;', Pref.CSS.match(/\.bm_num\s\{[^\}]*\}/i))
  1931. + addCssTable('keyword','border: 1px solid rgb(170, 170, 170); display: none;', Pref.CSS.match(/\.bm_kw\s\{[^\}]*\}/i))
  1932. + ' </div>\
  1933. <div>\
  1934. <table style="padding: 0.5em 0.5em 0 0.5em;">\
  1935. <tr>\
  1936. <td>\
  1937. <label>\
  1938. 自定义 CSS :【为推广链接分栏】 需在下框内输入 div.result-op.c-container.restTuiGuang {float: right;}\
  1939. </label><br>\
  1940. <label>\
  1941. <textarea rows="2" cols="60" id="customizeCSS" wrap="off" style="font-size: small;">' + Pref.customizeCSS + '</textarea>\
  1942. </label>\
  1943. </td>\
  1944. </tr>\
  1945. </table>\
  1946. </div>\
  1947. </fieldset>\
  1948. </td>\
  1949. </tr>\
  1950. </table>\
  1951. </center>\
  1952. </div>\
  1953. </div>\
  1954. ';
  1955. }
  1956. document.body.insertBefore(bgDiv,document.body.firstChild);
  1957.  
  1958. // 设置好预览效果
  1959. prefOnChange();
  1960. // 添加 CSS 列表事件,切换不同的设置
  1961. document.getElementById('bm_pref_css_list').addEventListener('change', function(event){
  1962. var list = event.target;
  1963. var curCssTable = matchNode('//table[@class="bm_pref_css" and not(contains(@style,"none"))]').snapshotItem(0);
  1964. curCssTable.setAttribute('style','border: 1px solid rgb(170, 170, 170); display: none;');
  1965. var newCssTable = document.getElementById('bm_pref_css_' + list.options[list.selectedIndex].value);
  1966. newCssTable.setAttribute('style','border: 1px solid rgb(170, 170, 170);');
  1967. switch(list.options[list.selectedIndex].value){
  1968. case 'holder':
  1969. blink('rest',1);
  1970. break;
  1971. case 'counter':
  1972. blink('bm_num',1);
  1973. break;
  1974. case 'keyword':
  1975. blink('bm_kw',1);
  1976. break;
  1977. }
  1978. }, false);
  1979. // 添加相关选项 onchange 时的事件
  1980. var onChanges = matchNode('//*[@class="bm_pref_onchange"]');
  1981. len = onChanges.snapshotLength;
  1982. for (i = 0; i < len; i++) {
  1983. onChanges.snapshotItem(i).addEventListener('change', function(){
  1984. prefOnChange();
  1985. }, false);
  1986. }
  1987. // 添加 CSS 参数变化时,更新预览效果
  1988. var cssInputs = matchNode('//input[ancestor::table[@class="bm_pref_css"]]');
  1989. len = cssInputs.snapshotLength;
  1990. for (i=0;i<len;i++){
  1991. cssInputs.snapshotItem(i).addEventListener('change', function(event){
  1992. cssOnChange(event.target);
  1993. }, false);
  1994. }
  1995. // 自定义 CSS 文本框失去焦点时,更新预览效果
  1996. document.getElementById('customizeCSS').addEventListener('blur', function(event){
  1997. prefOnChange();
  1998. }, false);
  1999. // 添加 CSS选项中的候选项
  2000. var optionSpans = matchNode('//span[@class="bm_pref_css_span"]');
  2001. len = optionSpans.snapshotLength;
  2002. for (i = 0; i < len; i++) {
  2003. optionSpans.snapshotItem(i).addEventListener('click', function(event){
  2004. var input = event.target.previousSibling;
  2005. switch(input.name){
  2006. case 'font-size':
  2007. addList(this,'6pt,7pt,8pt,9pt,10pt,11pt,12pt,13pt,14pt,15pt,16pt,17pt,18pt,19pt,20pt,21pt,22pt,23pt,24pt,25pt,26pt,27pt,28pt');
  2008. break;
  2009. case 'color':
  2010. addColorPicker(this);
  2011. break;
  2012. case 'font-weight':
  2013. addList(this,'bold,normal,100,200,300,400,500,600,700,800,900');
  2014. break;
  2015. case 'text-decoration':
  2016. addList(this,'none,underline,overline,line-through,blink');
  2017. break;
  2018. case 'text-align':
  2019. addList(this,'left,center,right,justify');
  2020. break;
  2021. case 'white-space':
  2022. addList(this,'normal,pre,nowrap');
  2023. break;
  2024. case 'background-color':
  2025. addColorPicker(this);
  2026. break;
  2027. case 'border-color':
  2028. addColorPicker(this);
  2029. break;
  2030. case 'border-style':
  2031. addList(this,'none,hidden,dotted,dashed,solid,double,groove,ridge,inset,outset');
  2032. break;
  2033. case 'border-width':
  2034. addList(this,'thin,medium,thick,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px')
  2035. break;
  2036. case 'margin-left':
  2037. addList(this,'0px,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,31px,32px,33px,34px,35px,36px,37px,38px,39px,40px,41px,42px,43px,44px,45px,46px,47px,48px,49px,50px');
  2038. break;
  2039. case 'padding-left':
  2040. addList(this,'0px,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,31px,32px,33px,34px,35px,36px,37px,38px,39px,40px,41px,42px,43px,44px,45px,46px,47px,48px,49px,50px');
  2041. break;
  2042. case 'margin-right':
  2043. addList(this,'0px,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,31px,32px,33px,34px,35px,36px,37px,38px,39px,40px,41px,42px,43px,44px,45px,46px,47px,48px,49px,50px');
  2044. break;
  2045. case 'padding-right':
  2046. addList(this,'0px,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,31px,32px,33px,34px,35px,36px,37px,38px,39px,40px,41px,42px,43px,44px,45px,46px,47px,48px,49px,50px');
  2047. break;
  2048. case 'margin-top':
  2049. addList(this,'0px,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,31px,32px,33px,34px,35px,36px,37px,38px,39px,40px,41px,42px,43px,44px,45px,46px,47px,48px,49px,50px');
  2050. break;
  2051. case 'padding-top':
  2052. addList(this,'0px,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,31px,32px,33px,34px,35px,36px,37px,38px,39px,40px,41px,42px,43px,44px,45px,46px,47px,48px,49px,50px');
  2053. break;
  2054. case 'margin-bottom':
  2055. addList(this,'0px,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,31px,32px,33px,34px,35px,36px,37px,38px,39px,40px,41px,42px,43px,44px,45px,46px,47px,48px,49px,50px');
  2056. break;
  2057. case 'padding-bottom':
  2058. addList(this,'0px,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,31px,32px,33px,34px,35px,36px,37px,38px,39px,40px,41px,42px,43px,44px,45px,46px,47px,48px,49px,50px');
  2059. break;
  2060. case 'float':
  2061. addList(this,'none,left,right');
  2062. break;
  2063. case 'clear':
  2064. addList(this,'none,left,right,both');
  2065. break;
  2066. }
  2067. }, false);
  2068. }
  2069.  
  2070. // 2012-4-26 去掉 脚本自身自动更新,因为greasemonkey已经支持更新
  2071. // 检查是否有新版本
  2072. //getNewVersion(function(version){
  2073. // if (Number(scriptVersion) < Number(version)) {
  2074. // document.getElementById('check_update').innerHTML = '<font color="red">&nbsp;&nbsp;&nbsp;检测到新版本,请点击'+
  2075. // '&nbsp;<a href="' + scriptUrl + '" target="_blank">查看</a>&nbsp;或'+
  2076. // '&nbsp;<a href="' + installUrl + '">升级</a>&nbsp;</font>';
  2077. // }
  2078. //})
  2079. // 将 CSS 全部恢复至默认
  2080. document.getElementById('default_button').addEventListener('click',function(){
  2081. if(confirm("除自定义 CSS 外的其他所有 CSS 设置将恢复到默认状态。\n继续吗?"))
  2082. {
  2083. setValue('CSS', defaultCSS);
  2084. alert('除自定义 CSS 外的其他所有 CSS 设置已恢复到默认状态,刷新页面后生效。');
  2085. }
  2086. }, false);
  2087. // 保存设置
  2088. document.getElementById('save_button').addEventListener('click',function(){
  2089. var len, tmp;
  2090. // 保存分栏数量
  2091. tmp = document.getElementById('numcol');
  2092. setValue('numcol', Number(tmp.options[tmp.selectedIndex].value));
  2093.  
  2094. // 保存搜索结果的排列方向
  2095. tmp = document.getElementById('direction');
  2096. setValue('direction', Number(tmp.options[tmp.selectedIndex].value));
  2097. // 保存排版模式
  2098. tmp = document.getElementById('mode');
  2099. setValue('mode', Number(tmp.options[tmp.selectedIndex].value));
  2100.  
  2101. // 让搜索结果适合屏幕宽度
  2102. setValue('fitwidth', document.getElementById('fitwidth').checked);
  2103. // 移除右侧的广告
  2104. setValue('removeAd', document.getElementById('removeAd').checked);
  2105. // 给搜索结果标序号
  2106. setValue('addResultNums', document.getElementById('addResultNums').checked);
  2107. // 搜索结果标序号,要在标题同行
  2108. setValue('addResultNums_h', document.getElementById('addResultNums_h').checked);
  2109. // 添加缩略图预览
  2110. setValue('addPreviews', document.getElementById('addPreviews').checked);
  2111. // 缩略图大小。如果包含非数字,则替换成默认值 100
  2112. setValue('PreviewSize', isNaN(document.getElementById('PreviewSize').value)?'100':document.getElementById('PreviewSize').value);
  2113. // 添加站点的 Favicon
  2114. setValue('addFavicons', document.getElementById('addFavicons').checked);
  2115. // 若没有 Favicon 则显示空白
  2116. setValue('addFavicons_h', document.getElementById('addFavicons_h').checked);
  2117. // 在页面上部添加其他搜索引擎,默认【在Google中搜索xx】
  2118. setValue('SearchInOtherEngines', document.getElementById('SearchInOtherEngines').checked);
  2119. setValue('OtherEngines', document.getElementById('OtherEngines').value.replace(/\'/ig,'"').replace(/^\s*|\s*$/ig,'').replace(/\s*[\n\r]+\s*/ig,'\n').replace(/\s*\|\s*http/ig,'|http'));
  2120. setValue('OtherEnginsFloat', document.getElementById('OtherEnginsFloat').checked);
  2121. tmp = document.getElementById('OtherEnginesTarget');
  2122. setValue('OtherEnginesTarget', tmp.options[tmp.selectedIndex].value);
  2123. // 自动加载下一页
  2124. setValue('AutoNextPage', document.getElementById('AutoNextPage').checked);
  2125. setValue('HideAutoNextPage', document.getElementById('HideAutoNextPage').checked);
  2126. setValue('NextPageWithRS', document.getElementById('NextPageWithRS').checked);
  2127. // 快捷键定位到搜索框
  2128. setValue('Focus2Keyword', document.getElementById('Focus2Keyword').checked);
  2129. tmp = document.getElementById('Focus2KeywordAction');
  2130. setValue('Focus2KeywordAction', Number(tmp.options[tmp.selectedIndex].value));
  2131. // 禁止Baidu记录我的点击情况
  2132. setValue('DisableTracking', document.getElementById('DisableTracking').checked);
  2133.  
  2134. // 添加“在此站点中搜索”
  2135. setValue('searchSite', document.getElementById('searchSite').checked);
  2136. var css = '';
  2137. // 保存 CSS 设置
  2138. var cssTextareas = matchNode('//textarea[string-length(text())>0 and ancestor::table[@class="bm_pref_css"]]');
  2139. len = cssTextareas.snapshotLength;
  2140. for(var i=0;i<len;i++){
  2141. css +='.bm_MultiColDiv ' + cssTextareas.snapshotItem(i).value + '\n';
  2142. }
  2143. setValue('CSS', css);
  2144.  
  2145. // 保存自定义的 CSS
  2146. setValue('customizeCSS', document.getElementById('customizeCSS').value);
  2147. // 滚动到页面顶部,刷新一下页面
  2148. window.scrollTo(0, 0);
  2149. location.href = location.href;
  2150. },false);
  2151. // 取消
  2152. document.getElementById('cancel_button').addEventListener('click',function(){
  2153.  
  2154. var bgDiv = document.getElementById('preferences');
  2155. bgDiv.parentNode.removeChild(bgDiv);
  2156.  
  2157. len = bodyElements.length;
  2158. for(i=0;i<len;i++){
  2159. bodyElements[i].style.display = bodyElementsDisplay[i];
  2160. }
  2161.  
  2162. window.scrollTo(0, 0);
  2163. if(Pref.AutoNextPage) loadNextPage();
  2164. },false);
  2165.  
  2166. // “快捷键定位到搜索框” 的快捷键设定
  2167. document.getElementById('Focus2KeywordKeys').addEventListener('keydown',function(event){
  2168. var keycode = event.keyCode;
  2169. var shift = event.shiftKey;
  2170. var ctrl = event.ctrlKey;
  2171. var alt = event.altKey;
  2172.  
  2173. var Keys = '';
  2174. if (shift) {
  2175. Keys += 'shift+';
  2176. }
  2177. if (ctrl) {
  2178. Keys += 'ctrl+';
  2179. }
  2180. if (alt) {
  2181. Keys += 'alt+';
  2182. }
  2183.  
  2184. this.value = Keys + (code2keyTable[keycode] || '');
  2185. Keys += String(event.keyCode);
  2186. setValue('Focus2KeywordKeys', Keys); // 立即保存快捷键
  2187. event.preventDefault();
  2188. event.stopPropagation();
  2189. },false);
  2190.  
  2191. // “快捷键定位到下一页”的快捷键设定
  2192. document.getElementById('Focus2NextPageKeys').addEventListener('keydown',function(event){
  2193. var keycode = event.keyCode;
  2194. var shift = event.shiftKey;
  2195. var ctrl = event.ctrlKey;
  2196. var alt = event.altKey;
  2197.  
  2198. var Keys = '';
  2199. if (shift) {
  2200. Keys += 'shift+';
  2201. }
  2202. if (ctrl) {
  2203. Keys += 'ctrl+';
  2204. }
  2205. if (alt) {
  2206. Keys += 'alt+';
  2207. }
  2208.  
  2209. this.value = Keys + (code2keyTable[keycode] || '');
  2210. Keys += String(event.keyCode);
  2211. setValue('Focus2NextPageKeys', Keys); // 立即保存快捷键
  2212. event.preventDefault();
  2213. event.stopPropagation();
  2214. },false);
  2215.  
  2216. // “快捷键定位到上一页”的快捷键设定
  2217. document.getElementById('Focus2PrevPageKeys').addEventListener('keydown',function(event){
  2218. var keycode = event.keyCode;
  2219. var shift = event.shiftKey;
  2220. var ctrl = event.ctrlKey;
  2221. var alt = event.altKey;
  2222.  
  2223. var Keys = '';
  2224. if (shift) {
  2225. Keys += 'shift+';
  2226. }
  2227. if (ctrl) {
  2228. Keys += 'ctrl+';
  2229. }
  2230. if (alt) {
  2231. Keys += 'alt+';
  2232. }
  2233.  
  2234. this.value = Keys + (code2keyTable[keycode] || '');
  2235. Keys += String(event.keyCode);
  2236. setValue('Focus2PrevPageKeys', Keys); // 立即保存快捷键
  2237. event.preventDefault();
  2238. event.stopPropagation();
  2239. },false);
  2240. }
  2241.  
  2242. // 加载下一页
  2243. function loadNextPage(){
  2244.  
  2245. // 如果剩余页面高度小于两倍窗口高度,而且存在下一页、没有在加载下一页、没有打开设置界面
  2246. if (!IsLoadingNext && NextPageLink && document.body.scrollHeight - window.scrollY < window.innerHeight * 3 && !document.getElementById('preferences')) {
  2247. IsLoadingNext = true;
  2248. var splitDiv = document.createElement('div');
  2249. splitDiv.setAttribute('style', 'font-size: small; background: rgb(230, 230, 230) none repeat scroll 0% 0%; clear: both; line-height: 20px; text-align: center; margin-top: 0.7em;');
  2250. splitDiv.setAttribute('id','isLoading');
  2251. splitDiv.setAttribute('class','bm_nav');
  2252. splitDiv.innerHTML = '<img style="vertical-align: middle;" src="data:image/gif;base64,R0lGODlhEAAQAPMAAP///wAA/wAA/4KC/nJy/qio/ry8/s7O/t7e/pSU/ujo/mho/gAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAAEKxDISau9OE/Bu//cQBTGgWDhWJ5XSpqoIL6s5a7xjLeyCvOgIEdDLBqPlAgAIfkECQoAAAAsAAAAABAAEAAABCsQyEmrvThPwbv/XJEMxIFg4VieV0qaqCC+rOWu8Yy3sgrzoCBHQywaj5QIACH5BAkKAAAALAAAAAAQABAAAAQrEMhJq704T8G7/9xhFMlAYOFYnldKmqggvqzlrvGMt7IK86AgR0MsGo+UCAAh+QQJCgAAACwAAAAAEAAQAAAEMRDISau9OE/Bu/+cghxGkQyEFY7lmVYraaKqIMpufbc0bLOzFyXGE25AyI5myWw6KREAIfkECQoAAAAsAAAAABAAEAAABDYQyEmrvThPwbv/nKQgh1EkA0GFwFie6SqIpImq29zWMC6xLlssR3vdZEWhDwBqejTQqHRKiQAAIfkECQoAAAAsAAAAABAAEAAABDYQyEmrvThPwbv/HKUgh1EkAyGF01ie6SqIpImqACu5dpzPrRoMpwPwhjLa6yYDOYuaqHRKjQAAIfkECQoAAAAsAAAAABAAEAAABDEQyEmrvThPwbv/nKUgh1EkAxFWY3mmK9WaqCqIJA3fbP7aOFctNpn9QEiPZslsOikRACH5BAkKAAAALAAAAAAQABAAAAQrEMhJq704T8G7/xymIIexEOE1lmdqrSYqiGTsVnA7q7VOszKQ8KYpGo/ICAAh+QQJCgAAACwAAAAAEAAQAAAEJhDISau9OE/Bu/+cthBDEmZjeWKpKYikC6svGq9XC+6e5v/AICUCACH5BAkKAAAALAAAAAAQABAAAAQrEMhJq704T8G7/xy2EENSGOE1lmdqrSYqiGTsVnA7q7VOszKQ8KYpGo/ICAAh+QQJCgAAACwAAAAAEAAQAAAEMRDISau9OE/Bu/+ctRBDUhgHElZjeaYr1ZqoKogkDd9s/to4Vy02mf1ASI9myWw6KREAIfkECQoAAAAsAAAAABAAEAAABDYQyEmrvThPwbv/HLUQQ1IYByKF01ie6SqIpImqACu5dpzPrRoMpwPwhjLa6yYDOYuaqHRKjQAAIfkECQoAAAAsAAAAABAAEAAABDYQyEmrvThPwbv/nLQQQ1IYB0KFwFie6SqIpImq29zWMC6xLlssR3vdZEWhDwBqejTQqHRKiQAAIfkECQoAAAAsAAAAABAAEAAABDEQyEmrvThPwbv/3EIMSWEciBWO5ZlWK2miqiDKbn23NGyzsxclxhNuQMiOZslsOikRADsAAAAAAAAAAAA=">\
  2253. BaiduMonkeyW 正在加载下一页 ...';
  2254. var clr = matchNode('//div[@id="search" and descendant::form[@name="f2"]]').snapshotItem(0);
  2255. clr.parentNode.insertBefore(splitDiv, clr);
  2256. GM_xmlhttpRequest({
  2257. method: 'GET',
  2258. url: String(NextPageLink.href),
  2259. overrideMimeType: 'text/html; charset=' + document.characterSet,
  2260. onload: function(d){
  2261.  
  2262. // 如果已打开设置界面,那么不加载下一页
  2263. if(document.getElementById('preferences')){
  2264. IsLoadingNext = false;
  2265. document.body.removeChild(document.getElementById('isLoading'));
  2266. return;
  2267. }
  2268. var i, len;
  2269. pageCount ++;
  2270. var lastNextPageLink = NextPageLink;
  2271. var ContainerDiv = document.createElement('div');
  2272. ContainerDiv.innerHTML = d.responseText;
  2273. var tempDivs = matchNode(sRestElementReal, ContainerDiv);
  2274. len = tempDivs.snapshotLength;
  2275. var ResultCellsDiv = document.createElement('div');
  2276. for (i = 0; i < len; i++) {
  2277. ResultCellsDiv.appendChild(tempDivs.snapshotItem(i));
  2278. }
  2279. ResultCellsDiv.setAttribute('class','bm_nextpage');
  2280.  
  2281. // 给搜索结果条目添加序号
  2282. if (Pref.addResultNum) {
  2283. addResultNums(ResultCellsDiv, Pref);
  2284. }
  2285. // 设置分栏格式
  2286. movePops_and_MultiCol(ResultCellsDiv, pageCount, Pref);
  2287.  
  2288. // 添加缩略图预览
  2289. if(Pref.addPreview){
  2290. addPreviews(ResultCellsDiv);
  2291. }
  2292. // 添加站点 Favicon
  2293. if (Pref.addFavicon) {
  2294. addFavicons(ResultCellsDiv);
  2295. }
  2296. // 禁止百度记录我的点击情况
  2297. if (Pref.DisableTracking) {
  2298. removeTracking(ResultCellsDiv);
  2299. }
  2300. // 添加“在此站点中搜索”
  2301. if(Pref.searchSite){
  2302. addseatchSite(ResultCellsDiv);
  2303. }
  2304. NextPageLink = matchNode('//p[@id="page"]/a[text() = "下一页>"]', ContainerDiv).snapshotItem(0);
  2305. if(!NextPageLink){
  2306. // 如果没有下一页了则移除滚动监视
  2307. window.removeEventListener('scroll', watch_scroll, true);
  2308. }
  2309.  
  2310. // 取得页面导航条
  2311. var splitDiv = matchNode('//p[@id="page"]', ContainerDiv).snapshotItem(0);
  2312. splitDiv.innerHTML = '<a style="width:auto;" href="' + lastNextPageLink.href + '">第' + (pageCount) + '页</a>' + splitDiv.innerHTML.replace('找到相关结果', '') + '';
  2313. splitDiv.setAttribute('style', 'margin: 8px 0 0 0;');
  2314. splitDiv.setAttribute('class',splitDiv.getAttribute('class')+' bm_nav');
  2315. // 在当前页插入自动翻页分隔符
  2316. document.getElementById('isLoading').parentNode.replaceChild(splitDiv, document.getElementById('isLoading'));
  2317. // 插入下一页
  2318. clr.parentNode.insertBefore(ResultCellsDiv, clr);
  2319. // 插入相关搜索
  2320. if (relatedSearch && Pref.NextPageWithRS) {
  2321. clr.parentNode.insertBefore(relatedSearch.cloneNode(true), clr);
  2322. }
  2323. // 统一格式,美化版面
  2324. // 只有一列或者“紧凑”模式时不需要统一格式
  2325. if (Pref.columns > 1 && Pref.displayMode > 1) {
  2326. // 加载第二页后,可能出现纵向滚动条,导致第一页宽度发生变化,所以要重新排版第一页的对齐格式
  2327. if (pageCount == 2) {
  2328. format('bm_page_1', Pref);
  2329. }
  2330. format('bm_page_' + pageCount, Pref);
  2331. }
  2332. delete ContainerDiv;
  2333. var ev = document.createEvent('Event');
  2334. ev.initEvent('bm_NextPageLoaded', true, false);
  2335. document.dispatchEvent(ev);
  2336. IsLoadingNext = false;
  2337. }
  2338. });
  2339. }
  2340. }
  2341.  
  2342. // 滚动停止 300ms 后,开始判断并加载下一页
  2343. var t = setTimeout(function(){},10);
  2344. function watch_scroll(){
  2345. clearTimeout(t);
  2346. var last = window.scrollY;
  2347. t = setTimeout(function(){
  2348. if (last == window.scrollY){
  2349. loadNextPage();
  2350. }
  2351. }, 300);
  2352. }
  2353.  
  2354. // 检查新版本
  2355. //function checkUpdate() {
  2356. // var now = Math.round(new Date().getTime() / 1000);
  2357. //
  2358. // if (Number(Pref.newVersion)) { // 如果已经检查到新版本
  2359. // showUpdateMessage(Pref.newVersion);
  2360. // }
  2361. // else if (now - Pref.lastCheck > 86400) { // 如果上一次没有检查到新版本,并且上一次检查距今超过24小时,那么现在检查新版本
  2362. // setValue('lastCheck',now);
  2363. // getNewVersion(function(version){
  2364. // if(Number(version)>Number(scriptVersion) && version != Pref.skipVersion){ // 如果最新版大于现有版本,并且不等于跳过的版本
  2365. // setValue('newVersion',version);
  2366. // showUpdateMessage(version);
  2367. // }
  2368. // else {
  2369. // setValue('newVersion',0);
  2370. // }
  2371. // })
  2372. // }
  2373. //}
  2374.  
  2375. // 显示新版本提示
  2376. function showUpdateMessage(newVersion){
  2377. var seperate = document.createElement('span');
  2378. seperate.innerHTML = '&nbsp;&nbsp;-&nbsp;&nbsp;';
  2379.  
  2380. var ignore = document.createElement('a');
  2381. ignore.innerHTML = '暂时忽略';
  2382. ignore.href='javascript:void(0)';
  2383. ignore.addEventListener("click", ignoreUpdate, false);
  2384.  
  2385. var skip = document.createElement('a');
  2386. skip.innerHTML = '跳过此版';
  2387. skip.href='javascript:void(0)';
  2388. skip.addEventListener("click", function(){
  2389. skipUpdate(newVersion)
  2390. }, false);
  2391.  
  2392. var view = document.createElement('a');
  2393. view.innerHTML = '查看更新';
  2394. view.href = scriptUrl;
  2395. view.target = '_blank';
  2396. var update = document.createElement('a');
  2397. update.innerHTML = '立即升级';
  2398. update.href='javascript:void(0)';
  2399. update.addEventListener("click", updateScript, false);
  2400.  
  2401. var msg = document.createElement('div');
  2402. with (msg) {
  2403. setAttribute('id', 'bm_UpdateMsg');
  2404. innerHTML = '<strong>BaiduMonkeyW</strong>&nbsp;发现新版本 v' + newVersion + '&nbsp;(当前版本 v' + scriptVersion + ')&nbsp;&nbsp;&nbsp;&nbsp;';
  2405. appendChild(ignore);
  2406. appendChild(seperate.cloneNode(true));
  2407. appendChild(skip);
  2408. appendChild(seperate.cloneNode(true));
  2409. appendChild(view);
  2410. appendChild(seperate.cloneNode(true));
  2411. appendChild(update);
  2412. }
  2413. document.body.insertBefore(msg,document.body.firstChild);
  2414. var css;
  2415. if(Pref.floatInput && Pref.floatInputPos == 1){
  2416. css = '.gbh {display: none;} \
  2417. #bm_UpdateMsg {background-color: rgb(240, 247, 249); margin: 1em; padding: 3px; text-align: center; -moz-border-radius: 5px; -webkit-border-radius: 5px;} \
  2418. #bm_header {top: 48px;}\
  2419. ';
  2420. }
  2421. else {
  2422. css = '.gbh {display: none;} \
  2423. #bm_UpdateMsg {background-color: rgb(240, 247, 249); margin: 1em; padding: 3px; text-align: center; -moz-border-radius: 5px; -webkit-border-radius: 5px;} \
  2424. ';
  2425. }
  2426. GM_addStyle(css);
  2427. }
  2428.  
  2429. function hideUpdateMessage(){
  2430. document.body.removeChild(document.getElementById('bm_UpdateMsg'));
  2431. }
  2432.  
  2433. // 暂时忽略
  2434. function ignoreUpdate(){
  2435. hideUpdateMessage();
  2436. setValue('lastCheck',Math.round(new Date().getTime() / 1000));
  2437. setValue('newVersion',0);
  2438. }
  2439.  
  2440. // 跳过此版
  2441. function skipUpdate(newVersion){
  2442. hideUpdateMessage();
  2443. setValue('skipVersion',newVersion);
  2444. setValue('newVersion',0);
  2445. }
  2446.  
  2447. // 立即升级
  2448. function updateScript(){
  2449. if(isChrome){
  2450. alert('Chrome用户请先卸载旧版本,再去脚本页面(点击查看更新即可)安装新版。\n卸载前请务必记好自定义的各项设置。');
  2451. setValue('newVersion',0);
  2452. }else{
  2453. hideUpdateMessage();
  2454. setValue('newVersion',0);
  2455. window.location.replace(installUrl);
  2456. }
  2457. }
  2458.  
  2459. //// 查询最新版本号
  2460. //function getNewVersion(funcbind){
  2461. // if(isChrome){
  2462. // GM_xmlhttpRequest({
  2463. // method: 'GET',
  2464. // url: 'http://' + location.host+ '/s?wd=site:(userscripts.org)+BaiduMonkey+version',
  2465. // overrideMimeType: 'text/html; charset=' + document.characterSet,
  2466. // onload: function(d){
  2467. // var versionCode = d.responseText.match(/Version.*Recently/i);
  2468. // if (versionCode) { // 如果找到 Version
  2469. // funcbind(String(versionCode).replace(/[^\d\.]/ig, ''));
  2470. // }
  2471. // }
  2472. // });
  2473. // }
  2474. // else{
  2475. // GM_xmlhttpRequest({
  2476. // method: 'GET',
  2477. // url: scriptUrl,
  2478. // overrideMimeType: 'text/html; charset=utf-8',
  2479. // onload: function(d){
  2480. // var divContainer = document.createElement('div');
  2481. // divContainer.innerHTML = d.responseText;
  2482. // var versionCode = matchNode('//h3[contains(text(),"当前版本")]', divContainer).snapshotItem(0).nextSibling;
  2483. // delete divContainer;
  2484. // if (versionCode) { // 如果找到 Version 标签
  2485. // funcbind(versionCode.textContent.replace(/^\s*|\s*$|v/ig, ''));
  2486. // }
  2487. // }
  2488. // });
  2489. // }
  2490. //}
  2491.  
  2492. // 转换为 Boolean 类型
  2493. function toBoolean(s){
  2494. return typeof(s)=='boolean'?s:(s=='true'?true:false);
  2495. }
  2496.  
  2497.  
  2498. //////////////////删除 推广链接
  2499. function RemoveTuiGuang(){
  2500. //f16 EC_PP
  2501. // 删除“推广”条目
  2502. var popTables = matchNode('//table[tbody/tr/td[contains(@class,"f16 EC_PP") ]]');
  2503. len = popTables.snapshotLength;
  2504. if (len > 0) {
  2505. for (i = 0; i < len; i++) {
  2506. var popTable = popTables.snapshotItem(i);
  2507. popTable.parentNode.removeChild(popTable);
  2508. }
  2509. }
  2510. }
  2511.  
  2512. /*********************************************************************************************
  2513. * 各功能函数 结束
  2514. *********************************************************************************************/
  2515.  
  2516. RemoveTuiGuang();
  2517.  
  2518. }
  2519.  
  2520. //baiduMeiHua();
  2521.  
  2522.  
  2523.  
  2524.  
  2525. function ajaxSend(objectOfXMLHttpRequest, callback) {
  2526. console.log(objectOfXMLHttpRequest);
  2527. console.log(callback);
  2528. // http://stackoverflow.com/questions/3596583/javascript-detect-an-ajax-event
  2529. if(!callback){
  2530. return;
  2531. }
  2532. var s_ajaxListener = new Object();
  2533. s_ajaxListener.tempOpen = objectOfXMLHttpRequest.prototype.open;
  2534. s_ajaxListener.tempSend = objectOfXMLHttpRequest.prototype.send;
  2535. s_ajaxListener.callback = function () {
  2536. // this.method :the ajax method used
  2537. // this.url :the url of the requested script (including query string, if any) (urlencoded)
  2538. // this.data :the data sent, if any ex: foo=bar&a=b (urlencoded)
  2539. callback(this.method, this.url, this.data);
  2540. }
  2541. objectOfXMLHttpRequest.prototype.open = function(a,b) {
  2542. if (!a) var a='';
  2543. if (!b) var b='';
  2544. s_ajaxListener.method = a;
  2545. s_ajaxListener.url = b;
  2546. if (a.toLowerCase() == 'get') {
  2547. s_ajaxListener.data = b.split('?');
  2548. s_ajaxListener.data = s_ajaxListener.data[1];
  2549. }
  2550. var realLink=findRealLink(s_ajaxListener.method, s_ajaxListener.url, s_ajaxListener.data);
  2551. if (realLink!="" ) {
  2552. var bCanTo=false;
  2553. var eles;
  2554. console.log(typeof($)=="undefined");
  2555. eles=document.getElementsByClassName("bdsug");
  2556. console.log(eles.length);
  2557. if (eles.length==0) {
  2558. bCanTo=true;
  2559. }
  2560. else {
  2561. console.log(eles[0].style.display);
  2562. if (eles[0].style.display=="none") {
  2563. console.log(4);
  2564. bCanTo=true;
  2565. }
  2566. }
  2567. //bRedirect=$(".bdsug").length==0 || $(".bdsug").is(":hidden");
  2568. console.log(bCanTo);
  2569. if (bCanTo) {
  2570. console.log("redirest to :"+realLink);
  2571. window.location.href=realLink;
  2572. }
  2573. else {
  2574. console.log("not redirest ");
  2575. objectOfXMLHttpRequest.abort();
  2576. }
  2577. return false;
  2578. }
  2579. s_ajaxListener.tempOpen.apply(this, arguments);
  2580. }
  2581. objectOfXMLHttpRequest.prototype.send = function(a,b) {
  2582. if (!a) var a='';
  2583. if (!b) var b='';
  2584. s_ajaxListener.tempSend.apply(this, arguments);
  2585. if(s_ajaxListener.method.toLowerCase() == 'post') {
  2586. s_ajaxListener.data = a;
  2587. }
  2588. s_ajaxListener.callback();
  2589. }
  2590. }
  2591.  
  2592. function callback(method,url,data) {
  2593. console.log("ajax:"+method+" "+url+ " Data:" + data);
  2594. }
  2595.  
  2596. function findRealLink(method,url,data) {
  2597. console.log("RealTest ajax:"+method+" "+url+ " Data:" + data);
  2598. if (method=="GET" && url.indexOf("/s?")>=0) {
  2599. var kw;
  2600. var wd;
  2601. kw=document.getElementById("kw");
  2602. if (kw) {
  2603. wd=kw.value;
  2604. }
  2605. else {
  2606. kw=document.getElementById("kw1");
  2607. if (kw) {
  2608. wd=kw.value;
  2609. }
  2610. }
  2611. //var wd=$("#kw").val();
  2612. //if (!wd) wd=$("#kw1").val();
  2613. //if (!wd) {
  2614. // console.log("未发现查询关键字控件");
  2615. // return "";
  2616. if (wd=="") {
  2617. console.log("查询关键字为空");
  2618. return "";
  2619. }
  2620. console.log("wd="+wd);
  2621. if (url.split("?")[1].indexOf("wd="+wd+"&")) {
  2622. console.log("have find wd :"+wd);
  2623. return "http://www.baidu.com/s?"+"wd="+wd;
  2624. }
  2625. }
  2626. return "";
  2627. }
  2628.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址