您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
强力去除各种扰眼模块、广告模块和触点推广等各类伪装广告,免登录看帖
当前为
// ==UserScript== // @name 贴吧页面精简 // @namespace http://greasyfork.icu/zh-CN/scripts/23687 // @namespace https://coding.net/u/BackRunner/p/GreaseMonkey-JS/git // @contributionURL https://sinacloud.net/backrunner/img/alipay.jpg // @version 2.3.3 // @description 强力去除各种扰眼模块、广告模块和触点推广等各类伪装广告,免登录看帖 // @author BackRunner // @include *://tieba.baidu.com/f?* // @include *://tieba.baidu.com/p/* // @include *://tieba.baidu.com/group/* // @include *://tieba.baidu.com/ // @run-at document-body // @require https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js // @license MIT // @grant unsafeWindow // @grant GM_setValue // @grant GM_getValue // @grant GM_info // ==/UserScript== // ==== Tips ===== // 使用TamperMonkey的用户可以将脚本的加载位置设置为document-start获得更好效果,若出现不生效等错误请还原设置 // 请根据您的需要根据下面代码的注释选择需要隐藏的模块,有不想隐藏的模块可以注释掉那一行代码 // 请根据您的需要与注释调整变量定义内的内容 // 遇到问题请立即反馈 // ==== Donate ==== // 如果您觉得本脚本好用可以赞助我一点零花 // [email protected] (支付宝) // === 更新日志 === // 2016.11.12 - 2.3.3 // 添加版本更新提醒 // ================ // 2016.11.5 - 2.2.6 - 2.3.2 // 修复GreaseMonkey的兼容性 // 修正console的一些信息错误 // 添加对免登录看帖只看楼主的支持 // 修正延迟脚本错误 // 更换jquery CDN // ================ (function() { //========================= // 变量定义 //========================= var sleepTime = 750; //如果对清理效果不满意可以尝试改大上面数值,不推荐超过1500 var sleepTimeWhenPageTurn = 50; //如果对清理效果不满意可以尝试改大上面数值,不推荐超过100 var postprocess = true; //如果您配合使用了其他脚本,请将上面的值改为false var homePageProcess = true; //如果您不想精简主页,请注释掉下面主页精简的代码或者将上面的值更改为false var groupPageProcess = true; //如果您不想精简群组页,请注释掉下面主页精简的代码或者将上面的值更改为false var noLoginProcess = true; //如果您不想启用免登录看帖功能,请将上面的值更改为false var checkrate = 1; //如果您在翻页时感觉到卡顿请更改上面的数值,该值为翻页后脚本执行频率倍数,推荐范围1-3 //===================== //以上内容可以修改,请勿修改以下内容 //===================== var startTime = new Date().getTime(); var finishTime = 0; //========================= // 主执行区 //========================= //控制台信息 console.warn('贴吧页面精简 by BackRunner: 启动'); //css修改 appendCSS(); //更新信息 updateAlert(); if (postprocess){ //延迟执行 setTimeout(function(){ var interval = setInterval(check,100); var n=0; function check(){ var times = n+1; console.warn('贴吧页面精简 by BackRunner: 延迟脚本正在执行第 ' + times + ' 次'); //列表翻页监听 if (window.location.href.indexOf("tieba.baidu.com/f?") != -1){ addListenerToList(); adinListClean(); reStart(); } else { if (window.location.href.indexOf("tieba.baidu.com/p/") != -1){ addListenerToPage(); tpointADClean(); adinPageClean(); if (noLoginProcess){ addNoLoginLZEventListener(); noLogin(); } reStart(); } else { if (window.location.href.indexOf("tieba.baidu.com/group") != -1){ console.warn('贴吧页面精简 by BackRunner: 当前位于群组页面,不执行延迟脚本'); clearInterval(interval); } else { if (window.location.href === "http://tieba.baidu.com/"){ console.warn('贴吧页面精简 by BackRunner: 当前位于主页,不执行延迟脚本'); clearInterval(interval); } else { console.warn('贴吧页面精简 by BackRunner: 页面未适配延迟脚本'); clearInterval(interval); } } } } function reStart(){ n++; if (n>2){ clearInterval(interval); } } } },sleepTime); //惰性脚本执行 window.onload=function(){ finishTime = new Date().getTime() - startTime; console.log('贴吧页面精简 by BackRunner: 页面加载用时: ' + finishTime); console.warn('贴吧页面精简 by BackRunner: 开始执行惰性脚本'); //列表翻页监听 if (window.location.href.indexOf("tieba.baidu.com/f?") != -1){ addListenerToList(); adinListClean(); } else { if (window.location.href.indexOf("tieba.baidu.com/p/") != -1){ addListenerToPage(); tpointADClean(); adinPageClean(); //执行免登录模块 if (noLoginProcess){ addNoLoginLZEventListener(); noLogin(); } } else { if (window.location.href.indexOf("") != -1){ console.warn('贴吧页面精简 by BackRunner: 当前位于群组页面,不执行惰性脚本'); clearInterval(interval); } else { if (window.location.href == "http://tieba.baidu.com/"){ console.warn('贴吧页面精简 by BackRunner: 当前位于主页,不执行惰性脚本'); clearInterval(interval); } else { console.warn('贴吧页面精简 by BackRunner: 页面未适配延迟脚本'); clearInterval(interval); } } } } }; } else { console.warning('贴吧页面精简 by BackRunner: 后处理脚本已跳过'); } //========================= //========================= //功能区 请勿修改下面的内容 //========================= //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;}'; //内页顶部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;}'; //访谈直播 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;}'; //图片签名档 cssText += '.j_user_sign {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 != "http://tieba.baidu.com/#" && window.location.href != "http://tieba.baidu.com/##" && window.location.href != "http://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;}'; //群组页面右侧下载 if (groupPageProcess){ if (window.location.href.indexOf("tieba.baidu.com/group") != -1){ cssText += '.right {display: none !important;}'; } } //主页模块精简 if (homePageProcess){ if (window.location.href == "http://tieba.baidu.com/" || window.location.href == "http://tieba.baidu.com/#" || window.location.href == "http://tieba.baidu.com/##" || window.location.href == "http://tieba.baidu.com/###"){ //顶部 try{ if (unsafeWindow.PageData.user.is_login == 1){ cssText += '.top-sec {display: none !important;}'; } } catch (e){ console.error('贴吧页面精简 by BackRunner: 登录状态检查错误'); 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;}'; } } console.log('贴吧页面精简 by BackRunner: css创建完成'); if (navigator.userAgent.indexOf('Chrome') > -1){ var element = document.createElement('link'); element.rel="stylesheet"; element.type="text/css"; element.href='data:text/css,'+cssText; document.documentElement.appendChild(element); } else { if (navigator.userAgent.indexOf('Firefox') > -1){ var modStyle = document.querySelector('#modCSS'); if (modStyle === null){ modStyle = document.createElement('style'); modStyle.id = 'modCSS'; document.body.appendChild(modStyle); modStyle.innerHTML = cssText; } } console.log('贴吧页面精简 by BackRunner: css已添加'); } } //列表翻页监听 function addListenerToList(){ $('#frs_list_pager a').each(function(){ this.addEventListener('click',listPageTurnEvent); }); console.log('贴吧页面精简 by BackRunner: 列表翻页监听添加完毕'); } //列表翻页监听事件 function listPageTurnEvent(e){ console.warn('贴吧页面精简 by BackRunner: 列表翻页事件触发'); setTimeout(function(){ var interval = setInterval(check,150 * checkrate); function check(){ addListenerToList(); adinListClean(); } setTimeout(function(){ addListenerToList(); adinListClean(); },sleepTime); setTimeout(function(){ addListenerToList(); adinListClean(); clearInterval(interval); },finishTime/3); },sleepTimeWhenPageTurn); } function addListenerToPage(){ $('.l_pager a').each(function(){ this.addEventListener('click',pageTurnEvent); }); console.log('贴吧页面精简 by BackRunner: 帖子翻页监听添加完毕'); } function pageTurnEvent(e){ console.warn('贴吧页面精简 by BackRunner: 帖子翻页事件触发'); setTimeout(function(){ var interval = setInterval(check,150 * checkrate); function check(){ addListenerToPage(); adinPageClean(); tpointADClean(); } setTimeout(function(){ addListenerToPage(); adinPageClean(); tpointADClean(); },sleepTime); setTimeout(function(){ addListenerToPage(); adinPageClean(); tpointADClean(); clearInterval(interval); },finishTime/3); },sleepTimeWhenPageTurn); } //触点推广 function tpointADClean(){ console.log('贴吧页面精简 by BackRunner: 开始精简触点推广'); var pointad = document.getElementsByClassName('tpoint-imgs'); console.log('贴吧页面精简 by BackRunner: 抓取到的广告元素数量: '+pointad.length); for(var i=0;i<pointad.length;i++){ pointad[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.removeChild(pointad[i].parentNode.parentNode.parentNode.parentNode.parentNode); } console.log('贴吧页面精简 by BackRunner: 触点推广精简完毕'); } //列表内广告 function adinListClean(){ console.log('贴吧页面精简 by BackRunner: 开始精简列表内广告'); var adinList = document.getElementsByClassName('threadlist_rep_num'); var num = 0; console.log('贴吧页面精简 by BackRunner: 列表内元素抓取量: '+adinList.length); for (i=0;i<adinList.length;i++){ if (adinList[i].title === "广告"){ num++; adinList[i].parentNode.parentNode.parentNode.parentNode.removeChild(adinList[i].parentNode.parentNode.parentNode); } } console.log('贴吧页面精简 by BackRunner: 列表内广告精简完毕,共精简 '+ num + ' 个'); } //贴内广告 function adinPageClean(){ console.log('贴吧页面精简 by BackRunner: 开始精简贴内广告'); var ad = document.getElementsByClassName('iframe_wrapper'); console.log('贴吧页面精简 by BackRunner: 抓取到的广告元素数量: '+ad.length); for(i=0;i<ad.length;i++){ ad[i].parentNode.parentNode.removeChild(ad[i].parentNode); } console.log('贴吧页面精简 by BackRunner: 贴内广告精简完毕'); } //免登录看帖 function noLogin(){ try{ if (unsafeWindow.PageData.user.is_login === 0){ unsafeWindow.Object.freeze = null; unsafeWindow.PageData.user.is_login = 1; console.warn('贴吧页面精简 by BackRunner: 已开启免登录看帖'); } else { console.warn('贴吧页面精简 by BackRunner: 当前已在登录状态'); } } catch(e){ console.error('贴吧页面精简 by BackRunner: 免登录看帖加载错误'); console.error(e); } } function addNoLoginLZEventListener(){ $('#lzonly_cntn').each(function(){ this.addEventListener('click',noLoginLZEvent); }); console.warn('贴吧页面精简 by BackRunner: 只看楼主按钮监听添加完毕'); } //免登录只看楼主 function noLoginLZEvent(){ var search = location.search; var url; var seelz = false; if (search !== null){ url = search.toString(); if (url.indexOf('see_lz=1') != -1){ seelz=true; } } if (seelz){ search = search.replace(/see_lz=1/g,""); if (location.search!=search){ location.search = search; console.warn('贴吧页面精简 by BackRunner: 取消只看楼主'); } } else { search += '&see_lz=1'; if (location.search!=search){ location.search = search; console.warn('贴吧页面精简 by BackRunner: 只看楼主'); } } } //更新提醒 function updateAlert(){ GM_setValue("displayUpdateInfo",true); var s_update = "贴吧页面精简 by BackRunner:\n检测到脚本版本更改"; var s_info = ""; var version = GM_getValue("version"); if (version !== GM_info.script.version){ console.warn("贴吧页面精简 by BackRunner:检测到脚本版本更改:" + version + " → " + GM_info.script.version); if (version === undefined){ version = "未知"; } s_update += "版本已从 " + version + " 更新为 " + GM_info.script.version + "\n\n当前版本的更新内容为:\n"; switch(GM_info.script.version){ case "2.3.3": s_info += "添加版本更新提醒\n"; break; } if (s_info === ""){ s_info = "无"; } s_update += s_info; s_update += "\n遇到任何问题请立刻到GreasyFork反馈\n觉得脚本好用可通过GreasyFork中的二维码赞助我"; window.alert(s_update); GM_setValue("version",GM_info.script.version); } else { console.warn("贴吧页面精简 by BackRunner:未检测到脚本版本更改"); } } })();