Tieba Preload

贴吧预加载,自动加载下一页内容,同时附带消灭贴吧自带 Lazy Load 功能

当前为 2014-10-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Tieba Preload
  3. // @version 1.3.7
  4. // @description 贴吧预加载,自动加载下一页内容,同时附带消灭贴吧自带 Lazy Load 功能
  5. // @match http://tieba.baidu.com/*
  6. // @include http://tieba.baidu.com/*
  7. // @exclude http://tieba.baidu.com/*tp=1*
  8. // @exclude http://tieba.baidu.com/*tab=*
  9. // @author 864907600cc
  10. // @icon http://1.gravatar.com/avatar/147834caf9ccb0a66b2505c753747867
  11. // @run-at document-end
  12. // @grant GM_registerMenuCommand
  13. // @namespace http://ext.ccloli.com
  14. // ==/UserScript==
  15.  
  16. // 贴子判断方式由 kookxiang 提供
  17. // 本脚本基于 GPLv3 协议开源 http://www.gnu.org/licenses/gpl.html‎
  18. // (c) 86497600cc. Some Rights Reserved.
  19.  
  20. // 修复使用 GM 函数后脚本失效的问题,thanks to shyangs
  21. var window=unsafeWindow,
  22. _=unsafeWindow._,
  23. PageData=unsafeWindow.PageData,
  24. Page=unsafeWindow.Page,
  25. $=unsafeWindow.$,
  26. //forumlist=unsafeWindow.forumlist,
  27. no_refresh_url_prefix=(typeof unsafeWindow.no_refresh_url_prefix!='undefined')?unsafeWindow.no_refresh_url_prefix:null,
  28. is_firefox=navigator.userAgent.indexOf('Firefox')>=0?true:false;
  29.  
  30. var notification=document.createElement('div'),
  31. setting=(window.localStorage.getItem('tb_preload_setting')&&window.localStorage.getItem('tb_preload_setting').indexOf('{')>=0)?JSON.parse(window.localStorage.getItem('tb_preload_setting')):{},
  32. stylesheet='@keyframes setting_panel_show{0%{top:100px;opacity:0}80%{top:-20px;opacity:1}100%{top:0px;opacity:1}}@-webkit-keyframes setting_panel_show{0%{top:100px;opacity:0}80%{top:-20px;opacity:1}100%{top:0px;opacity:1}}@keyframes setting_panel_hide{0%{top:0px;opacity:1}20%{top:-20px;opacity:1}100%{top:100px;opacity:0}}@-webkit-keyframes setting_panel_hide{0%{top:0px;opacity:1}20%{top:-20px;opacity:1}100%{top:100px;opacity:0}}.tb_preload_notification{position:fixed;right:10px;padding:5px;bottom:-50px;box-shadow:0 0 1px 5px rgba(0,0,0,0.5);background:rgba(0,0,0,0.5);font-size:12px;color:#fff;opacity:0;-webkit-transition:0.25s all linear;-o-transition:0.25s all linear;transition:0.25s all linear;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;cursor:pointer;z-index:999999;pointer-events:none}.tb_preload_notification[show]{bottom:10px;opacity:1}.tb_preload_page{width:100%;font-size:14px;text-align:center}.tb_preload_page a{text-decoration:none;color:#333;margin:20px 0;display:block;font-size:14px}.tb_preload_setting{color:#2d64b3;cursor:pointer}.list_loading,.right_section [data-type="tb-datalazyload"]{display:none}.vpic_wrap img{max-height:90px}.tb_preload_setting_panel{width:600px;height:200px;margin:auto;position:fixed;top:0;bottom:0;left:0;right:0;z-index:999998;box-shadow:rgba(0,0,0,.5) 0 0 0 2500px,rgba(255,255,255,.75) 0 0 200px;background:rgba(255,255,255,.75);font-size:14px;-webkit-user-select:none;-moz-user-select:none;-webkit-animation:setting_panel_show 0.75s ease-in;animation:setting_panel_show 0.75s ease-in;font-family:"Hiragino Sans GB","Microsoft Yahei","WenQuanYi Micro Hei",Arial,Tahoma,sans-serif}.tb_preload_setting_panel[close]{-webkit-animation:setting_panel_hide 0.75s ease-out;animation:setting_panel_hide 0.75s ease-out}.tb_preload_setting_panel_bg{width:100%;height:100%;position:fixed;left:0;top:0;z-index:999997}.tb_preload_setting_panel span,.tb_preload_setting_panel a{display:block;cursor:pointer;height:20px;line-height:20px;margin:10px;-webkit-transition:all 0.25s linear;-moz-transition:all 0.25s linear;transition:all 0.25s linear}.tb_preload_setting_panel span{color:#F00;padding-left:50px}.tb_preload_setting_panel span:hover{text-shadow:#F00 0 0 1px}.tb_preload_setting_panel span[active]:hover,.tb_preload_setting_panel a:hover{text-shadow:#7fb900 0 0 1px}.tb_preload_setting_panel span::before{content:"×";display:inline-block;width:20px}.tb_preload_setting_panel span[active]{color:#7FB900}.tb_preload_setting_panel span[active]::before{content:"√"}.tb_preload_setting_panel p{margin:20px;font-size:20px;height:24px;line-height:24px;cursor:default;font-family:"Segoe Script"!important;text-shadow: #000 0 0 2px}.tb_preload_setting_panel a{color:#7FB900;font-family:"Segoe Script"!important;text-align:center}.tbui_follow_fixed{display:block!important}img[origin-src]{display:none!important}',
  33. setting_panel=false,
  34. ss=document.createElement('style'),
  35. notification_timer=null;
  36. ss.textContent=stylesheet;
  37. document.head.appendChild(ss);
  38. notification.className='tb_preload_notification';
  39. document.body.appendChild(notification);
  40. if(setting.thread_preload==null)setting.thread_preload=1;
  41. if(setting.thread_list_lazyload==null)setting.thread_list_lazyload=1;
  42. if(setting.notification_1_3_4=null){
  43. setting.notification_1_3_4=1;
  44. alert('Tieba Preload Notification\n\n1. 自该版本起添加 @namespace,若出现重复安装的情况请删除旧脚本;\n2. Firefox 下不翻页 bug 已临时使用定时器解决,为保证楼中楼完全加载,请注意在载入页面完成后不要在 1s 内滚动到页面底部 = = 关于该 bug 引起的具体原因仍旧不明,不知道是不是 Firefox 特有的 bug……\n3. 现可以通过在贴子页的“开启/关闭自动加载”处单击鼠标右键打开设置界面,原开启设置界面的方式保留;\n4. 1.3.5 版本起按住 Ctrl 键鼠标左键点击页面内的“开启/关闭自动加载”可设置仅当前页生效。');
  45. window.localStorage.setItem('tb_preload_setting',JSON.stringify(setting));
  46. }
  47.  
  48. function set_function(v,k){
  49. if(k==null)k=true;
  50. switch(v){
  51. case 1:
  52. if(setting.thread_preload==1){
  53. setting.thread_preload=0;
  54. if(setting_node){
  55. setting_node.textContent='开启自动加载';
  56. setting_node_2.textContent='开启自动加载';
  57. }
  58. if(PageData.product=='pb'&&typeof loader!='undefined'&&loader!=null){
  59. clearInterval(loader);
  60. loader=null;
  61. }
  62. show_notification(1,'已关闭自动加载......');
  63. notification.setAttribute('show','true');
  64. notification_timer=setTimeout(function(){notification.removeAttribute('show')},5000);
  65. }
  66. else{
  67. setting.thread_preload=1;
  68. if(setting_node){
  69. setting_node.textContent='关闭自动加载';
  70. setting_node_2.textContent='关闭自动加载';
  71. }
  72. if(PageData.product=='pb'&&typeof loader!='undefined'&&loader==null)preload_listener();
  73. show_notification(1,'已开启自动加载......');
  74. }
  75. break;
  76. case 2:
  77. if(setting.thread_list_preload==1){
  78. alert('当开启首页贴子列表预加载时,该项不能关闭。');
  79. }
  80. else if(setting.thread_list_lazyload==1){
  81. setting.thread_list_lazyload=0;
  82. if(PageData.product=='frs'&&typeof loader!='undefined'&&loader!=null){
  83. clearInterval(loader);
  84. loader=null;
  85. if(document.getElementById('frs_list_pager'))document.getElementById('frs_list_pager').onclick=null;
  86. }
  87. show_notification(1,'已禁用自动去除首页 lazyload......');
  88. }
  89. else{
  90. setting.thread_list_lazyload=1;
  91. //setting_node.textContent='禁用自动去除首页 lazyload';
  92. if(PageData.product=='frs'&&typeof loader!='undefined'&&loader==null){
  93. kill_tieba_lazyload_listener();
  94. }
  95. show_notification(1,'已开启自动去除首页 lazyload......');
  96. }
  97. break;
  98. case 3:
  99. if(setting.thread_list_preload==1){
  100. setting.thread_list_preload=0;
  101. if(PageData.product=='frs'&&typeof loader!='undefined'&&loader!=null){
  102. clearInterval(loader);
  103. loader=null;
  104. if(document.getElementById('frs_list_pager'))document.getElementById('frs_list_pager').onclick=null;
  105. }
  106. show_notification(1,'已关闭自动加载......');
  107. }
  108. else{
  109. setting.thread_list_preload=1;
  110. setting.thread_list_lazyload=1;
  111. if(PageData.product=='frs'&&typeof loader!='undefined'&&loader==null){
  112. preload_listener();
  113. }
  114. show_notification(1,'已开启自动加载......');
  115. }
  116. break;
  117. }
  118. if(k==true)window.localStorage.setItem('tb_preload_setting',JSON.stringify(setting));
  119. update_setting_panel();
  120. }
  121.  
  122. function call_setting(){
  123. if(setting_panel==false){
  124. setting_panel=true;
  125. var panel=document.createElement('div'),
  126. panel_bg=document.createElement('div');
  127. panel_bg.className='tb_preload_setting_panel_bg';
  128. panel.className='tb_preload_setting_panel';
  129. panel_bg.onclick=function(){
  130. panel.setAttribute('close',true);
  131. setTimeout(function(){panel.parentElement.removeChild(panel);},700);
  132. panel_bg.parentElement.removeChild(panel_bg);
  133. setting_panel=false;
  134. }
  135. panel_bg.setAttribute('title','点击以关闭设置界面');
  136. panel.innerHTML='<p align="center">Tieba Preload Setting</p><span class="tbpreload_setting_panel_thread_preload">自动加载贴子下一页</span><span class="tbpreload_setting_panel_thread_list_lazyload">去除贴吧首页 lazyload</span><span class="tbpreload_setting_panel_thread_list_preload">自动加载贴子列表下一页</span><a href="http://tieba.baidu.com/p/2939166340">Feedback</a>';
  137. document.body.appendChild(panel);
  138. document.body.appendChild(panel_bg);
  139. var panel_thread_preload=document.getElementsByClassName('tbpreload_setting_panel_thread_preload')[0],
  140. panel_thread_list_lazyload=document.getElementsByClassName('tbpreload_setting_panel_thread_list_lazyload')[0],
  141. panel_thread_list_preload=document.getElementsByClassName('tbpreload_setting_panel_thread_list_preload')[0];
  142. panel_thread_preload.onclick=function(){
  143. set_function(1);
  144. }
  145. panel_thread_list_lazyload.onclick=function(){
  146. set_function(2);
  147. }
  148. panel_thread_list_preload.onclick=function(){
  149. set_function(3);
  150. }
  151. update_setting_panel();
  152. }
  153. }
  154.  
  155. function update_setting_panel(){
  156. var panel_thread_preload=document.getElementsByClassName('tbpreload_setting_panel_thread_preload')[0],
  157. panel_thread_list_lazyload=document.getElementsByClassName('tbpreload_setting_panel_thread_list_lazyload')[0],
  158. panel_thread_list_preload=document.getElementsByClassName('tbpreload_setting_panel_thread_list_preload')[0];
  159. if(setting.thread_preload==1)panel_thread_preload.setAttribute('active','true');
  160. else if(panel_thread_preload.hasAttribute('active'))panel_thread_preload.removeAttribute('active');
  161. if(setting.thread_list_lazyload==1)panel_thread_list_lazyload.setAttribute('active','true');
  162. else if(panel_thread_list_lazyload.hasAttribute('active'))panel_thread_list_lazyload.removeAttribute('active');
  163. if(setting.thread_list_preload==1)panel_thread_list_preload.setAttribute('active','true');
  164. else if(panel_thread_list_preload.hasAttribute('active'))panel_thread_list_preload.removeAttribute('active');
  165. }
  166.  
  167. function show_notification(n,c){
  168. notification.textContent=c;
  169. notification.setAttribute('show','true');
  170. if(notification_timer!=null){
  171. clearTimeout(notification_timer);
  172. notification_timer=null;
  173. }
  174. if(n==1){
  175. notification_timer=setTimeout(function(){
  176. notification.removeAttribute('show');
  177. notification_timer=null;
  178. },5000);
  179. }
  180. }
  181.  
  182. GM_registerMenuCommand('Tieba Preload Setting',call_setting);
  183.  
  184. if(typeof PageData!='undefined'&&PageData&&(PageData.product=='pb'||PageData.product=='frs')){ // 判断是否载入
  185. var loading=false,
  186. loader=null,
  187. pager_timer=null;
  188.  
  189. // 以下语句中代码来自 Kill Tieba Lazy Load (by 864907600cc, Licence: WTFPL)
  190.  
  191. function kill_tieba_lazyload(){
  192. var codearea=document.getElementById('pblistCodeArea')||document.getElementById('frslistCodeArea')||null;
  193. if(codearea!=null){
  194. //document.getElementById('list_loading').outerHTML=document.getElementById('pblistCodeArea').value;
  195. //document.getElementById('pblistCodeArea').parentElement.removeChild(document.getElementById('pblistCodeArea'));
  196. var lazyload_t_nodes=codearea.childNodes;
  197. for(var i=0;i<lazyload_t_nodes.length;i++){
  198. if(lazyload_t_nodes[i].nodeType==8){
  199. codearea.outerHTML=lazyload_t_nodes[i].data;
  200. //lazyload_nodes[i].parentElement.removeChild(lazyload_nodes[i])
  201. break;
  202. }
  203. }
  204. }
  205. if(document.querySelectorAll('img[data-tb-lazyload]')){
  206. var lazyload_i_nodes=document.querySelectorAll('img[data-tb-lazyload]');
  207. for(var i=0;i<lazyload_i_nodes.length;i++){
  208. lazyload_i_nodes[i].setAttribute('src',lazyload_i_nodes[i].getAttribute('data-tb-lazyload'));
  209. lazyload_i_nodes[i].removeAttribute('data-tb-lazyload');
  210. }
  211. }
  212. if(document.querySelectorAll('img[onloadfun="listimg"][original]')){
  213. var lazyload_i_nodes=document.querySelectorAll('img[onloadfun="listimg"][original]');
  214. for(var i=0;i<lazyload_i_nodes.length;i++){
  215. lazyload_i_nodes[i].setAttribute('src',lazyload_i_nodes[i].getAttribute('original'));
  216. }
  217. }
  218. if(PageData.product=='pb'){
  219. //_.Module.use("pb/widget/ForumListV3", {});
  220. _.Module.use('pb/component/NoAutoVideo',[{text_videofrom:'视频来自: '}]);
  221. //rebind_image();
  222. //Page.bindOpenImg();
  223. //console.log('触发强制显示楼中楼');
  224. if(typeof window.forumlist=='object'&&typeof window.forumlist._loadSubList=='object'){
  225. if(is_firefox)setTimeout(function(){kill_lzl();},500);
  226. else kill_lzl();
  227. }
  228. else var k=setInterval(function(){if(typeof window.forumlist=='object'&&typeof window.forumlist._loadSubList=='object')clearInterval(k);kill_lzl();},1000)
  229. //console.log('触发强制显示楼中楼完成');
  230. }
  231. if(PageData.product=='frs'&&document.cookie.match(/batch_delete_mode=(\w{4,5})/)&&document.cookie.match(/batch_delete_mode=(\w{4,5})/)[1]=='true'){
  232. var tls=document.getElementsByClassName('j_thread_list');
  233. for(var i=0;i<tls.length;i++){
  234. if(!tls[i].getElementsByClassName('batch_delete')[0]){
  235. var s='<div class="batch_delete j_batch_delete"><div class="batch_delete_text">勾选</div><input type="checkbox" class="batch_delete_select j_batch_delete_select"></div>';
  236. var t=document.createElement('div');
  237. tls[i].appendChild(t);
  238. t.outerHTML=s;
  239. }
  240. }
  241. }
  242. }
  243.  
  244. function show_lzl(c){
  245. var t=document.createElement('iframe');
  246. t.style.cssText='width:0;height:0;position:absolute'
  247. t.setAttribute('onload',c);
  248. document.body.appendChild(t);
  249. // kill_lzl();
  250. //document.body.removeChild(t); // 取消自动移除 iframe,因为该操作可能导致在 Firefox 下无法运行
  251. }
  252.  
  253. function kill_lzl(){
  254. // Fuck LZL Thanks To 8qwe24657913
  255. //console.log('执行强制显示楼中楼');
  256. /* var a = document.getElementsByClassName('hideLzl'),
  257. b = window.forumlist._loadSubList,
  258. c = a.length;
  259. /*while (--c > -1) {
  260. console.log(a)
  261. console.log('开始处理 - '+(c+1));
  262. b.showLzlPost(a[c]);
  263. console.log('showLzlPost - '+(c+1));
  264. a[c].setAttribute('class',a[c].getAttribute('class').replace(/ ?hideLzl/,''));
  265. console.log('处理完成 - '+(c+1));
  266. }*/
  267. //for(var i=0;i<c;i++){
  268. /* while(a[0]){
  269. console.log(a)
  270. //console.log('开始处理 - ');
  271. console.log(a[0])
  272. b.showLzlPost(a[0]);
  273. //console.log('showLzlPost - ');
  274. a[0].setAttribute('class',a[0].getAttribute('class').replace(/ ?hideLzl/,''));
  275. //console.log('处理完成 - ');
  276. }
  277. //console.log('楼中楼处理完成!');
  278. /*for(var i=0;i<c.length;i++){
  279. b.showLzlPost(a[i]);
  280. a[i].className=a[i].className.replace(/ ?hideLzl/,'');
  281. }*/
  282. // Fuck LZL Thanks To 网络孤独行客
  283. (function($){
  284. $(document).ajaxSuccess(function(e,xhr,s){
  285. (s.url.search("pn") !== -1) && lazyload();
  286. });
  287. function lazyload() {
  288. if("undefined" !== typeof unsafeWindow.datalazyload) {
  289. if(unsafeWindow.datalazyload.userConfig.diff === 500){
  290. unsafeWindow.datalazyload.userConfig.diff = 99999;
  291. return window.scrollTo(0,(document.body.scrollTop || document.documentElement.scrollTop) + 1);
  292. }
  293. else
  294. return setTimeout(lazyload,200);
  295. }
  296. setTimeout(lazyload,200);
  297. }
  298. lazyload();
  299. })(unsafeWindow.jQuery);
  300. }
  301.  
  302. // 以下语句中代码基于 Tieba Preload 修改 (by 864907600cc, Licence: GPLv3 | http://ccloli.com/201212/tieba-preload-source/)
  303.  
  304. function whether_fetching(){
  305. //console.log('whether_fetching');
  306. var getscroll=document.documentElement.scrollTop||document.body.scrollTop,
  307. scroll_psi=document.body.scrollHeight-getscroll,
  308. psi=PageData.product=='pb'?5000:PageData.forum.version==2?2500:1500;
  309. if(scroll_psi<=psi&&loading==false){
  310. if(cur_page<total_page){
  311. loading=true;
  312. fetch_next_page();
  313. }
  314. //else window.onscroll=null;
  315. else{
  316. clearInterval(loader);
  317. loader=null
  318. }
  319. }
  320. }
  321.  
  322. function fetch_next_page(){
  323. //console.log('fetch_next_page');
  324. switch(PageData.product){
  325. case 'pb':
  326. var url=page_url+'?see_lz='+see_lz+'&pn='+next_page;
  327. xhr.onreadystatechange=function(){
  328. if(xhr.readyState==4&&xhr.status==200){
  329. var str=xhr.responseText;
  330. if(PageData.page=='v1')var data=str.split('"p_postlist"')[1].split('<div class="p_thread')[0].match(/>([\s\S]+)/)[1]; // 旧版贴吧
  331. else var data=str.split('"p_postlist"')[1].split('"right_section')[0].match(/>([\s\S]+)<\/div>[\s\S]*<\/div>[\s\S]*<div/)[1]; // 先 split 再 match 减少资源消耗(>20s → <1s)
  332. var node=document.getElementsByClassName('p_postlist')[0],
  333. t_node=document.createElement('div'),
  334. p_node=document.createElement('div');
  335. p_node.className='tb_preload_page';
  336. p_node.innerHTML='<a href="'+url+'">第 '+next_page+' 页,共 '+total_page+' 页</a>';
  337. node.appendChild(p_node);
  338. node.appendChild(t_node);
  339. t_node.outerHTML=data;
  340. if(str.match(/<script>.*(_.Module.use\("pb\/widget\/postList",[\s\S]+?)<\/script>/)){
  341. var lzl=str.match(/<script>.*(_.Module.use\("pb\/widget\/postList",[\s\S]+?)<\/script>/)[1];
  342. show_lzl(lzl);
  343. }
  344. kill_tieba_lazyload();
  345. ++cur_page;
  346. ++next_page;
  347. PageData.pager.cur_page=cur_page;
  348. see_lz=window.location.href.match(/see_lz/)?window.location.href.match(/see_lz=(\d)/)[1]:PageData.special.lz_only;
  349. loading=false;
  350. if(cur_page==total_page){
  351. clearInterval(loader);
  352. loader=null;
  353. }
  354. notification.removeAttribute('show');
  355. }
  356. }
  357. xhr.open('GET',url);
  358. xhr.send();
  359. notification.setAttribute('show','true');
  360. show_notification(0,'正在加载第 '+next_page+' 页......');
  361. break;
  362. case 'frs':
  363. var url=page_url+'&pn='+next_page;
  364. if(PageData.forum.version==2){
  365. var xurl=page_url+'&apage=1&pn='+next_page;
  366. }
  367. else{
  368. if(location.hash.indexOf('#!')>=0){
  369. var hash_data=location.hash.match(/#\!\/(.)/)[1];
  370. if(hash_data!=last_hash_data){
  371. switch(hash_data){
  372. case 'm':
  373. page_url=page_url.replace(/f.+kw=/,'f?kw=');
  374. last_hash_data='m';
  375. cur_page=0;
  376. next_page=cur_page+50;
  377. total_page=document.querySelector('a.last').href.match(/pn=(\d+)/)[1];
  378. break;
  379. case 'n':
  380. page_url=page_url.replace(/f.+kw=/,'f/good?kw=');
  381. last_hash_data='n';
  382. cur_page=0;
  383. next_page=cur_page+50;
  384. total_page=document.querySelector('a.last').href.match(/pn=(\d+)/)[1];
  385. break;
  386. case 'v':
  387. page_url=page_url.replace(/f.+kw=/,'f/vote?kw=');
  388. last_hash_data='v';
  389. cur_page=0;
  390. next_page=cur_page+50;
  391. total_page=document.querySelector('a.last').href.match(/pn=(\d+)/)[1];
  392. break;
  393. }
  394. }
  395. }
  396. var xurl=page_url+'&ajax=1&pn='+next_page
  397. }
  398. xhr.onreadystatechange=function(){
  399. if(xhr.readyState==4&&xhr.status==200){
  400. var str=xhr.responseText;
  401. if(PageData.forum.version==2){
  402. var data=str.match(/<ul id="thread_list"[\s\S]*?>([\s\S]+)<\/ul>/)[1],
  403. node=document.getElementById('thread_list');
  404. p_node=document.createElement('div'),
  405. context='<a href="'+url+'">第 '+(parseInt(next_page/50)+1)+' 页,共 '+(parseInt(total_page/50)+1)+' 页</a>';
  406. }
  407. else{
  408. var data=JSON.parse(str).data.content.split('<tbody>')[1].split('</tbody>')[0],//str.split('<tbody>')[1].split('</tbody>')[0],
  409. node=document.querySelector('#thread_list tbody'),
  410. p_node=document.createElement('tr'),
  411. context='<td colspan="5"><a href="'+url+'">第 '+(parseInt(next_page/50)+1)+' 页,共 '+(parseInt(total_page/50)+1)+' 页</a></td>';
  412. }
  413. var //node=document.getElementById('thread_list'),
  414. t_node=document.createElement('div')/*,
  415. p_node=document.createElement('div')*/;
  416. p_node.className='tb_preload_page';
  417. p_node.innerHTML=context;
  418. node.appendChild(p_node);
  419. node.appendChild(t_node);
  420. t_node.outerHTML=data;
  421. kill_tieba_lazyload();
  422. cur_page+=50;
  423. next_page+=50;
  424. loading=false;
  425. if(cur_page==total_page){
  426. clearInterval(loader);
  427. loader=null;
  428. }
  429. notification.removeAttribute('show');
  430. }
  431. }
  432. xhr.open('GET',xurl);
  433. xhr.send();
  434. notification.setAttribute('show','true');
  435. show_notification(0,'正在加载第 '+(parseInt(next_page/50)+1)+' 页......');
  436. break;
  437. }
  438. }
  439.  
  440. function preload_listener(){
  441. if(cur_page!=total_page){
  442. //console.log('aaa');
  443. //window.onscroll=function(){ // 改用定时器以节省资源
  444. loader=setInterval(function(){whether_fetching()},1000);
  445. //}
  446. }
  447. }
  448.  
  449. function kill_tieba_lazyload_listener(){
  450. kill_tieba_lazyload();
  451. if(document.getElementById('frs_list_pager'))document.getElementById('frs_list_pager').onclick=function(){
  452. if(loader==null)loader=setInterval(function(){
  453. if(document.getElementById('frslistCodeArea')){
  454. //kill_tieba_lazyload();
  455. clearInterval(loader);
  456. loader=null;
  457. kill_tieba_lazyload_listener();
  458. }
  459. },1000);
  460. }
  461. }
  462.  
  463. function rebind_image(){
  464. var imglist=document.querySelectorAll('.d_post_content img[pic_type="0"]');//.BDE_Image
  465. $(imglist).unbind();
  466. Page._bindOpenImg();
  467.  
  468. }
  469.  
  470. function bind_pager(){
  471. var pager1=document.querySelectorAll('.pb_list_pager,.jump_btn_bright');
  472. var pager2=document.querySelectorAll('.jump_input_bright');
  473. for(var i=0;i<pager1.length;i++){
  474. pager1[i].addEventListener('click',rebind_pager);
  475. }
  476. for(var i=0;i<pager2.length;i++){
  477. pager2[i].addEventListener('keypress',function(e){
  478. if(e.keyCode==13)rebind_pager();
  479. });
  480. }
  481. }
  482.  
  483. function rebind_pager(){
  484. if(pager_timer==null){
  485. pager_timer=setInterval(function(){
  486. if(PageData.pager.cur_page!=cur_page){
  487. clearInterval(pager_timer);
  488. pager_timer=null;
  489. kill_tieba_lazyload();
  490. bind_pager();
  491. cur_page=PageData.pager.cur_page;
  492. next_page=cur_page+1;
  493. total_page=PageData.pager.total_page;
  494. if(loader==null && setting.thread_preload==1)preload_listener();
  495. inner_setting();
  496. }
  497. },1000)
  498. }
  499. }
  500.  
  501. function inner_setting(){
  502. setting_node=document.createElement('li');
  503. page_node=document.getElementsByClassName('l_posts_num');
  504. setting_node.textContent=setting.thread_preload==1?'关闭自动加载':'开启自动加载';
  505. setting_node.className='tb_preload_setting';
  506. setting_node_2=setting_node.cloneNode(true);
  507. setting_node.onclick=function(e){if(e.ctrlKey)set_function(1,false);else set_function(1);};
  508. setting_node_2.onclick=function(e){if(e.ctrlKey)set_function(1,false);else set_function(1);};
  509. setting_node.oncontextmenu=function(){call_setting();return false};
  510. setting_node_2.oncontextmenu=function(){call_setting();return false;};
  511. if(page_node[0])page_node[0].insertBefore(setting_node,page_node[0].getElementsByClassName('l_pager')[0].nextSibling);
  512. if(page_node[1])page_node[1].insertBefore(setting_node_2,page_node[1].getElementsByClassName('l_pager')[0].nextSibling);
  513. }
  514.  
  515. //notification.onclick=function(){set_function(1)};
  516.  
  517. if(PageData.product=='frs'){
  518. /*if(document.getElementsByClassName('th_footer_l')[0]){
  519. var setting_node=document.createElement('a'),
  520. page_node=document.getElementsByClassName('th_footer_l')[0];
  521. setting_node.textContent=setting.thread_list_lazyload==1?'禁用自动去除首页 lazyload':'开启自动去除首页 lazyload'; // 好长 _(:з」∠)_
  522. setting_node.className='tb_preload_setting';
  523. setting_node.onclick=function(){set_function(2)};
  524. page_node.appendChild(setting_node);
  525. }*/
  526. notification.style.pointerEvents='none';
  527. var xhr=new XMLHttpRequest(),
  528. page_url=no_refresh_url_prefix?('//tieba.baidu.com'+no_refresh_url_prefix):location.href.replace(/&?pn=\d+/,''),
  529. cur_page=location.href.match(/pn=(\d+)/)?parseInt(location.href.match(/pn=(\d+)/)[1]):0,
  530. next_page=cur_page+50,
  531. total_page=PageData.forum.thread_num-PageData.forum.thread_num%50||document.querySelector('a.last').href.match(/pn=(\d+)/)[1],
  532. last_hash_data='';
  533. if(setting.thread_list_preload==1){
  534. kill_tieba_lazyload();
  535. preload_listener();
  536. }
  537. else if(setting.thread_list_lazyload==1)kill_tieba_lazyload_listener();
  538. }
  539. else if(PageData.product=='pb'&&PageData.pager){
  540. //Page._bindOpenImg=Page.bindOpenImg;
  541. //Page.bindOpenImg=rebind_image;
  542. kill_tieba_lazyload();
  543. // 以下语句中部分判断代码来自 Chrome 扩展程序 KK 贴吧工具箱 (by kookxiang | https://chrome.google.com/webstore/detail/bcmemjlkdbeephmnklgimfnjlmfhfdgi)
  544. /*cur_page=0,
  545. total_page=0,
  546. page_url='',
  547. see_lz=0,*/
  548. var xhr=new XMLHttpRequest(),
  549. page_url=PageData.thread_url?'//tieba.baidu.com'+PageData.thread_url:location.href.match(/\/\/tieba\.baidu\.com\/p\/\d+/)[0],
  550. see_lz=window.location.href.match(/see_lz/)?window.location.href.match(/see_lz=(\d)/)[1]:PageData.special.lz_only,
  551. cur_page=PageData.pager.cur_page,
  552. total_page=PageData.pager.total_page,
  553. next_page=cur_page+1,
  554. setting_node,
  555. setting_node_2,
  556. page_node;
  557. if(setting.thread_preload==1)preload_listener();
  558. bind_pager();
  559. inner_setting();
  560. /*for(var i in document.scripts){
  561. if(document.scripts[i].textContent.indexOf('ForumListV3')>=0){
  562. var lzl=document.scripts[i].textContent;
  563. show_lzl(lzl);
  564. break;
  565. }
  566. }*/
  567. }
  568. }