// ==UserScript== // @name Tieba Preload // @version 1.3.2 // @description 贴吧预加载,自动加载下一页内容,同时附带消灭贴吧自带 Lazy Load 功能 // @match http://tieba.baidu.com/* // @include http://tieba.baidu.com/* // @exclude http://tieba.baidu.com/*tp=1* // @exclude http://tieba.baidu.com/*tab=* // @author 864907600cc // @icon http://1.gravatar.com/avatar/147834caf9ccb0a66b2505c753747867 // @run-at document-end // @grant GM_registerMenuCommand // @namespace https://greasyfork.org/users/141 // @downloadURL none // ==/UserScript== // 贴子判断方式由 kookxiang 提供 // 本脚本基于 GPLv3 协议开源 http://www.gnu.org/licenses/gpl.html‎ // (c) 86497600cc. Some Rights Reserved. // 修复使用 GM 函数后脚本失效的问题,thanks to shyangs var window=unsafeWindow, _=unsafeWindow._, PageData=unsafeWindow.PageData, Page=unsafeWindow.Page, $=unsafeWindow.$, no_refresh_url_prefix=(typeof unsafeWindow.no_refresh_url_prefix!='undefined')?unsafeWindow.no_refresh_url_prefix:null; var notification=document.createElement('div'), setting=(window.localStorage.getItem('tb_preload_setting')&&window.localStorage.getItem('tb_preload_setting').indexOf('{')>=0)?JSON.parse(window.localStorage.getItem('tb_preload_setting')):{}, 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";text-shadow: #000 0 0 2px}.tb_preload_setting_panel a{color:#7FB900;font-family:"Segoe Script";text-align:center}.tbui_follow_fixed{display:block!important}img[origin-src]{display:none!important}', setting_panel=false, ss=document.createElement('style'), notification_timer=null; ss.textContent=stylesheet; document.head.appendChild(ss); notification.className='tb_preload_notification'; document.body.appendChild(notification); if(setting.thread_preload==null)setting.thread_preload=1; if(setting.thread_list_lazyload==null)setting.thread_list_lazyload=1; if(setting.thread_list_preload==null){ setting.thread_list_preload=1; setting.thread_list_lazyload=1; var f=document.createElement('script'); f.textContent='$.dialog.alert("
请在此呼出设置界面进行设置

",{title:"Tieba Preload Setting Notification",width:1000})'; document.body.appendChild(f); document.body.removeChild(f); window.localStorage.setItem('tb_preload_setting',JSON.stringify(setting)); } function set_function(v){ switch(v){ case 1: if(setting.thread_preload==1){ setting.thread_preload=0; if(setting_node){ setting_node.textContent='开启自动加载'; setting_node_2.textContent='开启自动加载'; } if(PageData.product=='pb'&&typeof loader!='undefined'&&loader!=null){ clearInterval(loader); loader=null; } show_notification(1,'已关闭自动加载......'); notification.setAttribute('show','true'); notification_timer=setTimeout(function(){notification.removeAttribute('show')},5000); } else{ setting.thread_preload=1; if(setting_node){ setting_node.textContent='关闭自动加载'; setting_node_2.textContent='关闭自动加载'; } if(PageData.product=='pb'&&typeof loader!='undefined'&&loader==null)preload_listener(); show_notification(1,'已开启自动加载......'); } break; case 2: if(setting.thread_list_preload==1){ alert('当开启首页贴子列表预加载时,该项不能关闭。'); } else if(setting.thread_list_lazyload==1){ setting.thread_list_lazyload=0; if(PageData.product=='frs'&&typeof loader!='undefined'&&loader!=null){ clearInterval(loader); loader=null; if(document.getElementById('frs_list_pager'))document.getElementById('frs_list_pager').onclick=null; } show_notification(1,'已禁用自动去除首页 lazyload......'); } else{ setting.thread_list_lazyload=1; //setting_node.textContent='禁用自动去除首页 lazyload'; if(PageData.product=='frs'&&typeof loader!='undefined'&&loader==null){ kill_tieba_lazyload_listener(); } show_notification(1,'已开启自动去除首页 lazyload......'); } break; case 3: if(setting.thread_list_preload==1){ setting.thread_list_preload=0; if(PageData.product=='frs'&&typeof loader!='undefined'&&loader!=null){ clearInterval(loader); loader=null; if(document.getElementById('frs_list_pager'))document.getElementById('frs_list_pager').onclick=null; } show_notification(1,'已关闭自动加载......'); } else{ setting.thread_list_preload=1; setting.thread_list_lazyload=1; if(PageData.product=='frs'&&typeof loader!='undefined'&&loader==null){ preload_listener(); } show_notification(1,'已开启自动加载......'); } break; } window.localStorage.setItem('tb_preload_setting',JSON.stringify(setting)); update_setting_panel(); } function call_setting(){ if(setting_panel==false){ setting_panel=true; var panel=document.createElement('div'), panel_bg=document.createElement('div'); panel_bg.className='tb_preload_setting_panel_bg'; panel.className='tb_preload_setting_panel'; panel_bg.onclick=function(){ panel.setAttribute('close',true); setTimeout(function(){panel.parentElement.removeChild(panel);},700); panel_bg.parentElement.removeChild(panel_bg); setting_panel=false; } panel_bg.setAttribute('title','点击以关闭设置界面'); panel.innerHTML='

Tieba Preload Setting

自动加载贴子下一页去除贴吧首页 lazyload自动加载贴子列表下一页Feedback'; document.body.appendChild(panel); document.body.appendChild(panel_bg); var panel_thread_preload=document.getElementsByClassName('tbpreload_setting_panel_thread_preload')[0], panel_thread_list_lazyload=document.getElementsByClassName('tbpreload_setting_panel_thread_list_lazyload')[0], panel_thread_list_preload=document.getElementsByClassName('tbpreload_setting_panel_thread_list_preload')[0]; panel_thread_preload.onclick=function(){ set_function(1); } panel_thread_list_lazyload.onclick=function(){ set_function(2); } panel_thread_list_preload.onclick=function(){ set_function(3); } update_setting_panel(); } } function update_setting_panel(){ var panel_thread_preload=document.getElementsByClassName('tbpreload_setting_panel_thread_preload')[0], panel_thread_list_lazyload=document.getElementsByClassName('tbpreload_setting_panel_thread_list_lazyload')[0], panel_thread_list_preload=document.getElementsByClassName('tbpreload_setting_panel_thread_list_preload')[0]; if(setting.thread_preload==1)panel_thread_preload.setAttribute('active','true'); else if(panel_thread_preload.hasAttribute('active'))panel_thread_preload.removeAttribute('active'); if(setting.thread_list_lazyload==1)panel_thread_list_lazyload.setAttribute('active','true'); else if(panel_thread_list_lazyload.hasAttribute('active'))panel_thread_list_lazyload.removeAttribute('active'); if(setting.thread_list_preload==1)panel_thread_list_preload.setAttribute('active','true'); else if(panel_thread_list_preload.hasAttribute('active'))panel_thread_list_preload.removeAttribute('active'); } function show_notification(n,c){ notification.textContent=c; notification.setAttribute('show','true'); if(notification_timer!=null){ clearTimeout(notification_timer); notification_timer=null; } if(n==1){ notification_timer=setTimeout(function(){ notification.removeAttribute('show'); notification_timer=null; },5000); } } GM_registerMenuCommand('Tieba Preload Setting',call_setting); if(typeof PageData!='undefined'&&PageData&&(PageData.product=='pb'||PageData.product=='frs')){ // 判断是否载入 var loading=false, loader=null; // 以下语句中代码来自 Kill Tieba Lazy Load (by 864907600cc, Licence: WTFPL) function kill_tieba_lazyload(){ var codearea=document.getElementById('pblistCodeArea')||document.getElementById('frslistCodeArea')||null; if(codearea!=null){ //document.getElementById('list_loading').outerHTML=document.getElementById('pblistCodeArea').value; //document.getElementById('pblistCodeArea').parentElement.removeChild(document.getElementById('pblistCodeArea')); var lazyload_t_nodes=codearea.childNodes; for(var i=0;i([\s\S]+)<\/div>[\s\S]*<\/div>[\s\S]*
20s → <1s) var node=document.getElementsByClassName('p_postlist')[0], t_node=document.createElement('div'), p_node=document.createElement('div'); p_node.className='tb_preload_page'; p_node.innerHTML='第 '+next_page+' 页,共 '+total_page+' 页'; node.appendChild(p_node); node.appendChild(t_node); t_node.outerHTML=data; if(str.match(/