// ==UserScript== // @name 贴吧页面精简 // @version 1.10 // @description 【可能是你遇到的最好用的贴吧精简脚本】,去除各种广告及扰眼模块,全面支持各种贴吧页面,免登录看帖,【倒序看帖】 // @author 执念e1 // @include *://tieba.baidu.com/* // @include *://dq.tieba.com/* // @include *://jump2.bdimg.com/* // @include *://jump.bdimg.com/* // @exclude *://tieba.baidu.com/f/fdir* // @run-at document-body // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js // @license MIT // @grant unsafeWindow // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_listValues // @grant GM_info // ==/UserScript== (function() { //========================= // 变量定义 //========================= var sleepTime; var sleepTimeWhenPageTurn; var reverseSleepTime; var postprocess; var homePageProcess; var groupPageProcess; var noLoginProcess; var reverse; var homeProcess; var isHeadimg; var checkrate; var delayScriptRunTimes; var isRedirect; var displayLive; var displaySign; var autoCloseGuide; //脚本固定开关 var isCtrlPanelOn; //底部信息div var foot; var homePageMatch = RegExp("(http|https):\/\/tieba.baidu.com\/(#*$)|(http|https):\/\/tieba.baidu.com\/(index\.html#*$)"); //===================== //以上内容可以修改,请勿修改以下内容 //===================== var startTime = new Date().getTime(); var finishTime = -1; //========================= // 主执行区 //========================= //控制台信息 console.warn('贴吧页面精简: 初始化'); //初始化 initialize(); console.warn('贴吧页面精简: 启动'); //重定向 if (isRedirect){ redirect(); } //css修改 appendCSS(); //更新信息 updateAlert(); //免登录 if (noLoginProcess){ noLogin(); } if (postprocess){ //惰性脚本执行 $(document).ready(function(){ //加载计时 finishTime = new Date().getTime() - startTime; console.log('贴吧页面精简: 页面加载用时: ' + finishTime); console.warn('贴吧页面精简: 开始执行惰性脚本'); //控制面板 try{ console.warn('贴吧页面精简: 正在创建控制面板'); if(isCtrlPanelOn){ createControlPanel(); } } catch(e){ console.error(e); } //底部信息 try{ createFooterLayer(); addFinishTimeToFooter(); } catch(e){ console.error(e); } //导航栏翻页监听 addListenerToNav(); //列表翻页监听 if (window.location.search.indexOf("kw=")!= -1 && window.location.href.indexOf("search")==-1){ addListenerToList(); adinListClean(); disableForumCard(); //自动收起指引 *20180509 closeGuide(); //弹框关闭 *20181013 removePopupModal(); //关注按钮修复 *20200116 fixFocusButton(); } else { if (window.location.href.indexOf("tieba.baidu.com/p/") != -1){ addListenerToPage(); tpointADClean(); adinPageClean(); reverseorder(); } else { if (window.location.href.indexOf("tieba.baidu.com/group") != -1){ console.warn('贴吧页面精简: 当前位于群组页面,不执行群组页面惰性脚本'); } else { if (homePageMatch.test(window.location.href)){ bindCleanIndexADEvent(); } else { console.warn('贴吧页面精简: 页面未适配延迟脚本'); } } } } }); //延迟执行 setTimeout(function(){ var interval = setInterval(check,sleepTime * checkrate); var n=0; function check(){ var times = n+1; console.warn('贴吧页面精简: 延迟脚本正在执行第 ' + times + ' 次'); //控制面板 try{ console.warn('贴吧页面精简: 正在创建控制面板'); if(isCtrlPanelOn){ createControlPanel(); } } catch(e){ console.error(e); } //底部信息 try{ createFooterLayer(); } catch(e){ console.error(e); } //导航栏翻页监听 addListenerToNav(); //列表翻页监听 if (window.location.search.indexOf("kw=")!= -1 && window.location.href.indexOf("search")==-1){ addListenerToList(); adinListClean(); disableForumCard(); //自动收起指引 *20180509 closeGuide(); //弹框关闭 *20181013 removePopupModal(); //修复关注按钮 *20200116 fixFocusButton(); } else { if (window.location.href.indexOf("tieba.baidu.com/p/") != -1){ addListenerToPage(); tpointADClean(); adinPageClean(); reverseorder(); } else { if (homePageMatch.test(window.location.href)){ bindCleanIndexADEvent(); cleanADinIndex(); } } } reStart(); function reStart(){ n++; if (n>delayScriptRunTimes-1){ clearInterval(interval); } } } },sleepTime); } else { setTimeout(function(){ var interval = setInterval(check,sleepTime * checkrate); var n = 0; function check(){ //控制面板 try{ console.warn('贴吧页面精简: 正在创建控制面板'); if(isCtrlPanelOn){ createControlPanel(); } } catch(e){ console.error(e); } //底部信息 try{ createFooterLayer(); } catch(e){ console.error(e); } n++; if (n>delayScriptRunTimes -1){ clearInterval(interval); } } }); $(document).ready(function(){ //加载计时 finishTime = new Date().getTime() - startTime; console.log('贴吧页面精简: 页面加载用时: ' + finishTime); //控制面板 try{ console.warn('贴吧页面精简: 正在创建控制面板'); if(isCtrlPanelOn){ createControlPanel(); } } catch(e){ console.error(e); } //底部信息 try{ createFooterLayer(); addFinishTimeToFooter(); } catch(e){ console.error(e); } }); console.warn('贴吧页面精简: 后处理脚本已跳过'); } //========================= //========================= //功能区 请勿修改下面的内容 //========================= //初始化 function initialize(){ sleepTime = initialize_var("sleepTime",300); sleepTimeWhenPageTurn = initialize_var("sleepTimeWhenPageTurn",800); reverseSleepTime = initialize_var("reverseSleepTime",200); postprocess = initialize_var("postprocess",true); isRedirect = initialize_var("isRedirect",true); homePageProcess = initialize_var("homePageProcess",true); groupPageProcess = initialize_var("groupPageProcess",true); noLoginProcess = initialize_var("noLoginProcess",true); reverse = initialize_var("reverse",false); homeProcess = initialize_var("homeProcess",true); isHeadimg = initialize_var("isHeadimg",false); checkrate = initialize_var("checkrate",1); delayScriptRunTimes = initialize_var("delayScriptRunTimes",6); displayLive = initialize_var("displayLive",false); displaySign = initialize_var("displaySign",false); autoCloseGuide = initialize_var("autoCloseGuide",true); //固定开关 *20180510 isCtrlPanelOn = initialize_var("isCtrlPanelOn",true); } function initialize_var(name,defaultSet){ var obj = GM_getValue(name,defaultSet); if (obj === undefined){ obj = defaultSet; } return obj; } //css修改 function appendCSS(){ var cssText = ""; //顶部直播栏 cssText += '#video_frs_head {display: none !important;}'; //右侧会员模块 cssText += '.celebrity {display: none !important;}'; //右侧我的应用模块 cssText += '.my_app {display: none !important;}'; //热议榜 cssText += '.topic_list_box {display: none !important;}'; //广告灰色label cssText += '.label_text {display: none !important;}'; //右边一排图标 cssText += '.j_icon_slot {display: none !important;}'; //会员图标(会造成用户名左移,一定程度上影响整体美观) //cssText += '.icon_tbworld {display: none !important;}'; //您可能感兴趣的吧 cssText += '.forum_recommend {display: none !important;}'; //右上角应用中心 cssText += '.u_menu_wrap.u_appcenterEntrance_wrap {display: none !important;}'; //右上角会员官网 cssText += '.u_joinvip_wrap.vip_red.j_btn_getmember {display: none !important;}'; cssText += '.u_joinvip {display: none !important;}'; //内页顶部banner cssText += '.l_banner {display: none !important;}'; //内页成就section cssText += '.achievement_medal_section {display: none !important;}'; //顶部游戏信息 cssText += '.game-head-game-info-wrapper {display: none !important;}'; //内页送礼物按钮 cssText += '.post-foot-send-gift-btn {display: none !important;}'; //会员挽尊按钮 cssText += '.save_face_bg {display: none !important;}'; cssText += '.save_face_bg_2 {display: none !important;}'; //底部游戏开测 cssText += '#duoku_servers_list {display: none !important;}'; //右侧热门卡包 cssText += '.u9_aside {display: none !important;}'; //右侧小说人气榜 cssText += '.novel-ranking-frs-body {display: none !important;}'; //头像下面的一排图标 cssText += '.icon_wrap {display: none !important;}'; //贴吧触点推广图片(在延迟处理前预处理) cssText += '.tpoint-imgs {display: none !important;}'; //右下角炮筒 cssText += '.j-firework-sender {display: none !important;}'; //访谈直播 if (!displayLive){ cssText += '.interview {display: none !important;}'; } //贴内相关推荐 cssText += '.thread_recommend {display: none !important;}'; //贴内广告 cssText += '.iframe_wrapper {display: none !important;}'; //右侧贴吧作者认证 cssText += '.author-manager {display: none !important;}'; //输入框placeholder cssText += '.tb_poster_placeholder {display: none !important;}'; //图片签名档 if (!displaySign){ cssText += '.j_user_sign {display: none !important;}'; cssText += '.d_sign_split {display: none !important;}'; } //会员名牌 cssText += '.pb_nameplate {display: none !important;}'; //右侧菜单栏精简 cssText += '.tbui_fbar_props {display: none !important;}'; cssText += '.tbui_fbar_tsukkomi {display: none !important;}'; //吧主专版 cssText += '.tbui_fbar_bazhu {display: none !important;}'; //右侧可点击广告 if (window.location.href !== "http://tieba.baidu.com/" && window.location.href !== "https://tieba.baidu.com/"){ cssText += '.j_click_stats {display: none !important;}'; } //右侧视频推荐 cssText += '#video_aside {display: none !important;}'; //一楼电影广告 cssText += '.tpoint-skin {display: none !important;}'; //直播页面底部弹出栏 cssText += '.attention_tip_wrap {display: none !important;}'; //底部注册/登录横条 cssText += '.guidance_fc {display: none !important;}'; //content-ad span cssText += '.content-ad {display: none !important;}'; //head ad span cssText += '.head_ad_tag {display: none !important;}'; cssText += '.head_ad_pop {display: none !important;}'; //会员置顶bubble cssText += '#tb_message_tip_d {display: none !important;}'; //应用中心nav cssText += '.app_forum_top_nav {display: none !important;}'; cssText += '#j_core_title_wrap {top:0px !important;}'; //顶栏会员 cssText += '.u_member {display: none !important;}'; //导航栏游戏 cssText += '#j_navtab_game {display: none !important;}'; //发帖框气泡 cssText += '.ui_bubble_body {display: none !important;}'; //礼赞 cssText += '.gift-goin {display: none !important;}'; //漂流瓶 cssText += '.tbui_fbar_nobottle {display: none !important;}'; //扫描下载APP cssText += '.app_download_box {display: none !important;}'; //某个右侧浮动广告的close按钮 cssText += '.j_click_close {display: none !important;}'; //618 Banner cssText += '.showBar {display: none !important;}'; //右上角气泡 cssText += '.ui_bubble_content {display: none !important}'; //Hao123 cssText += '.j_u_menu_extra_url_link {display: none !important}'; //大家都在搜 cssText += '.search_back_box {display:none !important}'; //下载APP cssText += '.tbui_fbar_down {display:none !important}'; //nani cssText += '.nani_app_download_box {display:none !important;}'; //会员菜单 cssText += '.u_menu_member {display:none !important;}'; //菜单 *20181012 cssText += '.u_mytbmall,.u_game,.u_blue{display:none !important;}'; //群组页面右侧下载 if (groupPageProcess){ if (window.location.href.indexOf("tieba.baidu.com/group") != -1){ cssText += '.right {display: none !important;}'; } } //主页模块精简 if (homePageProcess){ if (homePageMatch.test(window.location.href)){ //顶部 try{ if (unsafeWindow.PageData.user.is_login === 1){ cssText += '.top-sec {display: none !important;}'; } } catch (e){ console.error('贴吧页面精简: 登录状态检查错误'); console.error(e); } //直播秀 cssText += '.spage_liveshow_slide {display: none !important;}'; //以下模块因为在右侧有一个下滑页面时让模块仍然保持在可视区域内的设计,单独精简一个会造成滚动页面时模块错位,所以全部精简 //乱七八糟的滚动活动模块 cssText += '#plat_act_wrapper {display: none !important;}'; //豪友俱乐部 cssText += '.member_rank {display: none !important;}'; //媒体进驻 cssText += '#adide_platform {display: none !important;}'; //贴吧娱乐 cssText += '#media_item {display: none !important;}'; //我的游戏 cssText += '#spage_game_tab_wrapper {display: none !important;}'; //公告板 cssText += '#notice_item {display: none !important;}'; //调整位置 *20171223 cssText += '.right-sec {margin-top:-15px !important;}'; //贴吧精选专题 *20171223 cssText += '.aggregate_entrance_wrap {display:none !important;}'; //未登录时的滚动横幅 *20180504 cssText += '#rec_left {display:none !important;} #rec_right{float:right;position:absolute;right:30px;margin-top:15px;}'; //用户面板的一些图表等 *20181012 cssText += '.icon_tbworld {display:none !important;} .user_score{display:none !important;}'; } } //个人主页精简 if (homeProcess){ if (window.location.href.indexOf("tieba.baidu.com/home") !== -1){ //右侧礼物面板 cssText += ".ihome-aside-gift-center {display: none !important}"; //求婚按钮 cssText += ".userinfo-marry {display: none !important}"; //我的夺宝 cssText += ".ihome-aside-grab-treasure {display: none !important}"; //我的T豆、蓝钻 cssText += ".userinfo_scores {display: none !important}"; } } //列表页头图精简 if (window.location.href.indexOf("tieba.baidu.com/f") !== -1){ if (isHeadimg){ cssText += ".head_banner_img,.head_ad_pop,.head_banner {display: none !important}"; //顶部css调整 *20171223 cssText += '.head_content {padding-top:20px !important}'; cssText += '.card_banner,.plat_recom_carousel {display:none !important}'; cssText += '.card_head {width:70px !important;height:70px !important;margin-bottom:10px !important;margin-top:100px !important}'; cssText += '.card_head_img {width:70px !important;height:70px !important;}'; cssText += '.card_title {margin-left:-50px !important;}'; cssText += '.card_slogan {margin-left:-50px !important;}'; } } //设置面板css cssText += '#backrunnerJSSetting_root {right:0 !important;} #backrunnerJSSetting_con {right:0 !important;width:200px important;}'; cssText += '#backrunnerJSSetting_con a {display:block !important;white-space:nowrap; !important}'; cssText += '#backrunnerJSSetting_con li {line-height:23px !important;display:block !important;white-space:nowrap !important;}'; cssText += '#backrunnerJSSetting_con li a {padding-top:0px !important;padding-bottom:0px !important;padding-right:1em !important;padding-left:1em !important;margin:0 !important;line-height:2.4em !important;}'; cssText += '.search_nav {margin-right:470px !important;}'; //reverse相关css *20171223 cssText += '.br_reverse_li {display:inline-block !important;margin-left:15px !important;margin-top:-14px !important;}'; cssText += '.core_title_txt {width:400px !important;}'; //底部信息css cssText += '#footer {padding-bottom:0px !important;}'; console.log('贴吧页面精简: css创建完成'); var element = document.createElement('link'); element.rel="stylesheet"; element.type="text/css"; element.href='data:text/css,'+cssText; document.documentElement.appendChild(element); var modStyle = document.querySelector('#modCSS'); if (modStyle === null){ modStyle = document.createElement('style'); modStyle.id = 'modCSS'; document.body.appendChild(modStyle); modStyle.innerHTML = cssText; } console.log('贴吧页面精简: css已添加'); } //列表翻页监听 function addListenerToList(){ $('#frs_list_pager a').each(function(){ this.addEventListener('click',listPageTurnEvent); }); console.log('贴吧页面精简: 列表翻页监听添加完毕'); } //帖子、精品翻页监听 function addListenerToNav(){ $('.nav_list li').each(function(){ if(this.attributes['data-tab-main'] || this.attributes['data-tab-good']){ this.getElementsByTagName('a')[0].addEventListener('click',listPageTurnEvent); } }); } //列表翻页监听事件 function listPageTurnEvent(){ console.warn('贴吧页面精简: 列表翻页事件触发'); setTimeout(function(){ var interval = setInterval(check,sleepTimeWhenPageTurn * checkrate); function check(){ addListenerToNav(); addListenerToList(); adinListClean(); } setTimeout(function(){ addListenerToNav(); addListenerToList(); adinListClean(); },sleepTime); setTimeout(function(){ addListenerToNav(); addListenerToList(); adinListClean(); clearInterval(interval); },finishTime/3); },sleepTimeWhenPageTurn); } function addListenerToPage(){ $('.l_pager a').each(function(){ this.addEventListener('click',pageTurnEvent); }); console.log('贴吧页面精简: 帖子翻页监听添加完毕'); } function pageTurnEvent(){ console.warn('贴吧页面精简: 帖子翻页事件触发'); setTimeout(function(){ var interval = setInterval(check,sleepTimeWhenPageTurn * checkrate); function check(){ addListenerToNav(); addListenerToPage(); adinPageClean(); tpointADClean(); reverseorder(); } setTimeout(function(){ addListenerToNav(); addListenerToPage(); adinPageClean(); tpointADClean(); reverseorder(); },sleepTime); setTimeout(function(){ addListenerToNav(); addListenerToPage(); adinPageClean(); tpointADClean(); reverseorder(); clearInterval(interval); },finishTime/3); },sleepTimeWhenPageTurn); } //触点推广 function tpointADClean(){ console.log('贴吧页面精简: 开始精简触点推广'); var pointad = document.getElementsByClassName('tpoint-imgs'); console.log('贴吧页面精简: 抓取到的广告元素数量: '+pointad.length); for(var i=0;i= 0; i--) { list.appendChild(contents[i]); } } },reverseSleepTime); } //自动收起指引 var isAutoCloseGuideSet = false; function closeGuide(){ if (autoCloseGuide && !isAutoCloseGuideSet){ var topContent = document.getElementsByClassName("top_content"); var topContentMain = document.getElementsByClassName("top_cont_main"); if (topContent.length>0 && topContentMain.length>0){ topContent[0].setAttribute("class","top_content top_content_closed"); topContentMain[0].setAttribute("style","display:none;"); isAutoCloseGuideSet = true; } } } //版本更新删除废弃变量 function deleteTrashValue(){ var trashList = {}; for (var i = 0;i 300){ console.log("贴吧页面精简: 滚动触发,正在清理动态内的广告"); cleanADinIndex(); windowTempScrollTop = document.documentElement.scrollTop; } } indexADEvent_scroll = true; } if (!indexADEvent_tag_hot){ var tag_hot = document.getElementById('j_remen_nav'); tag_hot.addEventListener('click',function(){ clearScrollTopTemp(); }); indexADEvent_tag_hot = true; } if (!indexADEvent_tag_personal){ var tag_personal = document.getElementById('nav-personal'); tag_personal.addEventListener('click',function(){ clearScrollTopTemp(); }); indexADEvent_tag_hot = true; } } function clearScrollTopTemp(){ console.log("贴吧页面精简: 清理滚动高度缓存"); windowTempScrollTop = 0; } function cleanADinIndex(){ var ads = document.getElementsByClassName('home-place-item'); var count = 0; for (var i = 0;i