Tieba Preload

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

À partir de 2014-06-20. Voir la dernière version.

  1. // ==UserScript==
  2. // @name Tieba Preload
  3. // @version 1.3.6
  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. }
  283.  
  284. // 以下语句中代码基于 Tieba Preload 修改 (by 864907600cc, Licence: GPLv3 | http://ccloli.com/201212/tieba-preload-source/)
  285.  
  286. function whether_fetching(){
  287. //console.log('whether_fetching');
  288. var getscroll=document.documentElement.scrollTop||document.body.scrollTop,
  289. scroll_psi=document.body.scrollHeight-getscroll,
  290. psi=PageData.product=='pb'?5000:PageData.forum.version==2?2500:1500;
  291. if(scroll_psi<=psi&&loading==false){
  292. if(cur_page<total_page){
  293. loading=true;
  294. fetch_next_page();
  295. }
  296. //else window.onscroll=null;
  297. else{
  298. clearInterval(loader);
  299. loader=null
  300. }
  301. }
  302. }
  303.  
  304. function fetch_next_page(){
  305. //console.log('fetch_next_page');
  306. switch(PageData.product){
  307. case 'pb':
  308. var url=page_url+'?see_lz='+see_lz+'&pn='+next_page;
  309. xhr.onreadystatechange=function(){
  310. if(xhr.readyState==4&&xhr.status==200){
  311. var str=xhr.responseText;
  312. if(PageData.page=='v1')var data=str.split('"p_postlist"')[1].split('<div class="p_thread')[0].match(/>([\s\S]+)/)[1]; // 旧版贴吧
  313. 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)
  314. var node=document.getElementsByClassName('p_postlist')[0],
  315. t_node=document.createElement('div'),
  316. p_node=document.createElement('div');
  317. p_node.className='tb_preload_page';
  318. p_node.innerHTML='<a href="'+url+'">第 '+next_page+' 页,共 '+total_page+' 页</a>';
  319. node.appendChild(p_node);
  320. node.appendChild(t_node);
  321. t_node.outerHTML=data;
  322. if(str.match(/<script>.*(_\.Module\.use\("pb\/widget\/ForumListV3"[\s\S]+?)<\/script>/)){
  323. var lzl=str.match(/<script>.*(_\.Module\.use\("pb\/widget\/ForumListV3"[\s\S]+?)<\/script>/)[1];
  324. show_lzl(lzl);
  325. }
  326. kill_tieba_lazyload();
  327. ++cur_page;
  328. ++next_page;
  329. PageData.pager.cur_page=cur_page;
  330. see_lz=window.location.href.match(/see_lz/)?window.location.href.match(/see_lz=(\d)/)[1]:PageData.special.lz_only;
  331. loading=false;
  332. if(cur_page==total_page){
  333. clearInterval(loader);
  334. loader=null;
  335. }
  336. notification.removeAttribute('show');
  337. }
  338. }
  339. xhr.open('GET',url);
  340. xhr.send();
  341. notification.setAttribute('show','true');
  342. show_notification(0,'正在加载第 '+next_page+' 页......');
  343. break;
  344. case 'frs':
  345. var url=page_url+'&pn='+next_page;
  346. if(PageData.forum.version==2){
  347. var xurl=page_url+'&apage=1&pn='+next_page;
  348. }
  349. else{
  350. if(location.hash.indexOf('#!')>=0){
  351. var hash_data=location.hash.match(/#\!\/(.)/)[1];
  352. if(hash_data!=last_hash_data){
  353. switch(hash_data){
  354. case 'm':
  355. page_url=page_url.replace(/f.+kw=/,'f?kw=');
  356. last_hash_data='m';
  357. cur_page=0;
  358. next_page=cur_page+50;
  359. total_page=document.querySelector('a.last').href.match(/pn=(\d+)/)[1];
  360. break;
  361. case 'n':
  362. page_url=page_url.replace(/f.+kw=/,'f/good?kw=');
  363. last_hash_data='n';
  364. cur_page=0;
  365. next_page=cur_page+50;
  366. total_page=document.querySelector('a.last').href.match(/pn=(\d+)/)[1];
  367. break;
  368. case 'v':
  369. page_url=page_url.replace(/f.+kw=/,'f/vote?kw=');
  370. last_hash_data='v';
  371. cur_page=0;
  372. next_page=cur_page+50;
  373. total_page=document.querySelector('a.last').href.match(/pn=(\d+)/)[1];
  374. break;
  375. }
  376. }
  377. }
  378. var xurl=page_url+'&ajax=1&pn='+next_page
  379. }
  380. xhr.onreadystatechange=function(){
  381. if(xhr.readyState==4&&xhr.status==200){
  382. var str=xhr.responseText;
  383. if(PageData.forum.version==2){
  384. var data=str.match(/<ul id="thread_list"[\s\S]*?>([\s\S]+)<\/ul>/)[1],
  385. node=document.getElementById('thread_list');
  386. p_node=document.createElement('div'),
  387. context='<a href="'+url+'">第 '+(parseInt(next_page/50)+1)+' 页,共 '+(parseInt(total_page/50)+1)+' 页</a>';
  388. }
  389. else{
  390. var data=JSON.parse(str).data.content.split('<tbody>')[1].split('</tbody>')[0],//str.split('<tbody>')[1].split('</tbody>')[0],
  391. node=document.querySelector('#thread_list tbody'),
  392. p_node=document.createElement('tr'),
  393. context='<td colspan="5"><a href="'+url+'">第 '+(parseInt(next_page/50)+1)+' 页,共 '+(parseInt(total_page/50)+1)+' 页</a></td>';
  394. }
  395. var //node=document.getElementById('thread_list'),
  396. t_node=document.createElement('div')/*,
  397. p_node=document.createElement('div')*/;
  398. p_node.className='tb_preload_page';
  399. p_node.innerHTML=context;
  400. node.appendChild(p_node);
  401. node.appendChild(t_node);
  402. t_node.outerHTML=data;
  403. kill_tieba_lazyload();
  404. cur_page+=50;
  405. next_page+=50;
  406. loading=false;
  407. if(cur_page==total_page){
  408. clearInterval(loader);
  409. loader=null;
  410. }
  411. notification.removeAttribute('show');
  412. }
  413. }
  414. xhr.open('GET',xurl);
  415. xhr.send();
  416. notification.setAttribute('show','true');
  417. show_notification(0,'正在加载第 '+(parseInt(next_page/50)+1)+' 页......');
  418. break;
  419. }
  420. }
  421.  
  422. function preload_listener(){
  423. if(cur_page!=total_page){
  424. //console.log('aaa');
  425. //window.onscroll=function(){ // 改用定时器以节省资源
  426. loader=setInterval(function(){whether_fetching()},1000);
  427. //}
  428. }
  429. }
  430.  
  431. function kill_tieba_lazyload_listener(){
  432. kill_tieba_lazyload();
  433. if(document.getElementById('frs_list_pager'))document.getElementById('frs_list_pager').onclick=function(){
  434. if(loader==null)loader=setInterval(function(){
  435. if(document.getElementById('frslistCodeArea')){
  436. //kill_tieba_lazyload();
  437. clearInterval(loader);
  438. loader=null;
  439. kill_tieba_lazyload_listener();
  440. }
  441. },1000);
  442. }
  443. }
  444.  
  445. function rebind_image(){
  446. var imglist=document.querySelectorAll('.d_post_content img[pic_type="0"]');//.BDE_Image
  447. $(imglist).unbind();
  448. Page._bindOpenImg();
  449.  
  450. }
  451.  
  452. function bind_pager(){
  453. var pager1=document.querySelectorAll('.pb_list_pager,.jump_btn_bright');
  454. var pager2=document.querySelectorAll('.jump_input_bright');
  455. for(var i=0;i<pager1.length;i++){
  456. pager1[i].addEventListener('click',rebind_pager);
  457. }
  458. for(var i=0;i<pager2.length;i++){
  459. pager2[i].addEventListener('keypress',function(e){
  460. if(e.keyCode==13)rebind_pager();
  461. });
  462. }
  463. }
  464.  
  465. function rebind_pager(){
  466. if(pager_timer==null){
  467. pager_timer=setInterval(function(){
  468. if(PageData.pager.cur_page!=cur_page){
  469. clearInterval(pager_timer);
  470. pager_timer=null;
  471. kill_tieba_lazyload();
  472. bind_pager();
  473. cur_page=PageData.pager.cur_page;
  474. next_page=cur_page+1;
  475. total_page=PageData.pager.total_page;
  476. if(loader==null && setting.thread_preload==1)preload_listener();
  477. inner_setting();
  478. }
  479. },1000)
  480. }
  481. }
  482.  
  483. function inner_setting(){
  484. setting_node=document.createElement('li');
  485. page_node=document.getElementsByClassName('l_posts_num');
  486. setting_node.textContent=setting.thread_preload==1?'关闭自动加载':'开启自动加载';
  487. setting_node.className='tb_preload_setting';
  488. setting_node_2=setting_node.cloneNode(true);
  489. setting_node.onclick=function(e){if(e.ctrlKey)set_function(1,false);else set_function(1);};
  490. setting_node_2.onclick=function(e){if(e.ctrlKey)set_function(1,false);else set_function(1);};
  491. setting_node.oncontextmenu=function(){call_setting();return false};
  492. setting_node_2.oncontextmenu=function(){call_setting();return false;};
  493. if(page_node[0])page_node[0].insertBefore(setting_node,page_node[0].getElementsByClassName('l_pager')[0].nextSibling);
  494. if(page_node[1])page_node[1].insertBefore(setting_node_2,page_node[1].getElementsByClassName('l_pager')[0].nextSibling);
  495. }
  496.  
  497. //notification.onclick=function(){set_function(1)};
  498.  
  499. if(PageData.product=='frs'){
  500. /*if(document.getElementsByClassName('th_footer_l')[0]){
  501. var setting_node=document.createElement('a'),
  502. page_node=document.getElementsByClassName('th_footer_l')[0];
  503. setting_node.textContent=setting.thread_list_lazyload==1?'禁用自动去除首页 lazyload':'开启自动去除首页 lazyload'; // 好长 _(:з」∠)_
  504. setting_node.className='tb_preload_setting';
  505. setting_node.onclick=function(){set_function(2)};
  506. page_node.appendChild(setting_node);
  507. }*/
  508. notification.style.pointerEvents='none';
  509. var xhr=new XMLHttpRequest(),
  510. page_url=no_refresh_url_prefix?('//tieba.baidu.com'+no_refresh_url_prefix):location.href.replace(/&?pn=\d+/,''),
  511. cur_page=location.href.match(/pn=(\d+)/)?parseInt(location.href.match(/pn=(\d+)/)[1]):0,
  512. next_page=cur_page+50,
  513. total_page=PageData.forum.thread_num-PageData.forum.thread_num%50||document.querySelector('a.last').href.match(/pn=(\d+)/)[1],
  514. last_hash_data='';
  515. if(setting.thread_list_preload==1){
  516. kill_tieba_lazyload();
  517. preload_listener();
  518. }
  519. else if(setting.thread_list_lazyload==1)kill_tieba_lazyload_listener();
  520. }
  521. else if(PageData.product=='pb'&&PageData.pager){
  522. //Page._bindOpenImg=Page.bindOpenImg;
  523. //Page.bindOpenImg=rebind_image;
  524. kill_tieba_lazyload();
  525. // 以下语句中部分判断代码来自 Chrome 扩展程序 KK 贴吧工具箱 (by kookxiang | https://chrome.google.com/webstore/detail/bcmemjlkdbeephmnklgimfnjlmfhfdgi)
  526. /*cur_page=0,
  527. total_page=0,
  528. page_url='',
  529. see_lz=0,*/
  530. var xhr=new XMLHttpRequest(),
  531. page_url=PageData.thread_url?'//tieba.baidu.com'+PageData.thread_url:location.href.match(/\/\/tieba\.baidu\.com\/p\/\d+/)[0],
  532. see_lz=window.location.href.match(/see_lz/)?window.location.href.match(/see_lz=(\d)/)[1]:PageData.special.lz_only,
  533. cur_page=PageData.pager.cur_page,
  534. total_page=PageData.pager.total_page,
  535. next_page=cur_page+1,
  536. setting_node,
  537. setting_node_2,
  538. page_node;
  539. if(setting.thread_preload==1)preload_listener();
  540. bind_pager();
  541. inner_setting();
  542. /*for(var i in document.scripts){
  543. if(document.scripts[i].textContent.indexOf('ForumListV3')>=0){
  544. var lzl=document.scripts[i].textContent;
  545. show_lzl(lzl);
  546. break;
  547. }
  548. }*/
  549. }
  550. }