贴吧页面精简

【可能是你遇到的最好用的贴吧精简脚本】,去除各种广告及扰眼模块,全面支持各种贴吧页面,免登录看帖,【倒序看帖】

As of 28/06/2020. See the latest version.

  1. // ==UserScript==
  2. // @name 贴吧页面精简
  3. // @namespace https://greasyfork.org/zh-CN/scripts/23687
  4. // @namespace https://coding.net/u/BackRunner/p/GreaseMonkey-JS/git
  5. // @version 2.8.0
  6. // @description 【可能是你遇到的最好用的贴吧精简脚本】,去除各种广告及扰眼模块,全面支持各种贴吧页面,免登录看帖,【倒序看帖】
  7. // @author BackRunner
  8. // @include *://tieba.baidu.com/*
  9. // @include *://dq.tieba.com/*
  10. // @include *://jump2.bdimg.com/*
  11. // @include *://jump.bdimg.com/*
  12. // @exclude *://tieba.baidu.com/f/fdir*
  13. // @run-at document-body
  14. // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
  15. // @license MIT
  16. // @grant unsafeWindow
  17. // @grant GM_setValue
  18. // @grant GM_getValue
  19. // @grant GM_deleteValue
  20. // @grant GM_listValues
  21. // @grant GM_info
  22. // ==/UserScript==
  23.  
  24. // ==== Tips =====
  25. // 使用TamperMonkey的用户可以将脚本的加载位置设置为document-start获得更好效果,若出现不生效等错误请还原设置
  26. // 请根据您的需要根据下面代码的注释选择需要隐藏的模块,有不想隐藏的模块可以注释掉那一行代码
  27. // 请根据您的需要与注释调整变量定义内的内容
  28. // 您自行修改的代码会在更新的时候被覆盖,建议您备份您修改的内容
  29. // 遇到问题请立即反馈
  30. // ==== Donate ====
  31. // 如果您觉得本脚本好用可以赞助我一点零花
  32. // donate@backrunner.top (支付宝)
  33. // === 更新日志 ===
  34. // 2020.01.16 - 2.8.0
  35. // 修复问题
  36. // 2018.12.26 - 2.7.15
  37. // 修复Chrome新版本上的兼容问题。
  38. // 2018.10.21 - 2.7.14
  39. // 添加一个域名重定向规则
  40. // 2018.10.13 - 2.7.13
  41. // 更换jQuery的CDN,脚本加载提速
  42. // 修复了一些问题
  43. // ================
  44.  
  45.  
  46. (function() {
  47. //=========================
  48. // 变量定义
  49. //=========================
  50. var sleepTime;
  51. var sleepTimeWhenPageTurn;
  52. var reverseSleepTime;
  53. var postprocess;
  54. var homePageProcess;
  55. var groupPageProcess;
  56. var noLoginProcess;
  57. var reverse;
  58. var homeProcess;
  59. var isHeadimg;
  60. var checkrate;
  61. var delayScriptRunTimes;
  62. var isRedirect;
  63. var displayLive;
  64. var displaySign;
  65. var autoCloseGuide;
  66. //脚本固定开关
  67. var isCtrlPanelOn;
  68. //底部信息div
  69. var foot;
  70. var homePageMatch = RegExp("(http|https):\/\/tieba.baidu.com\/(#*$)|(http|https):\/\/tieba.baidu.com\/(index\.html#*$)");
  71. //=====================
  72. //以上内容可以修改,请勿修改以下内容
  73. //=====================
  74. var startTime = new Date().getTime();
  75. var finishTime = -1;
  76. //=========================
  77. // 主执行区
  78. //=========================
  79. //控制台信息
  80. console.warn('贴吧页面精简: 初始化');
  81. //初始化
  82. initialize();
  83. console.warn('贴吧页面精简: 启动');
  84. //重定向
  85. if (isRedirect){
  86. redirect();
  87. }
  88. //css修改
  89. appendCSS();
  90. //更新信息
  91. updateAlert();
  92. //免登录
  93. if (noLoginProcess){
  94. noLogin();
  95. }
  96. if (postprocess){
  97. //惰性脚本执行
  98. $(document).ready(function(){
  99. //加载计时
  100. finishTime = new Date().getTime() - startTime;
  101. console.log('贴吧页面精简: 页面加载用时: ' + finishTime);
  102. console.warn('贴吧页面精简: 开始执行惰性脚本');
  103. //控制面板
  104. try{
  105. console.warn('贴吧页面精简: 正在创建控制面板');
  106. if(isCtrlPanelOn){
  107. createControlPanel();
  108. }
  109. } catch(e){
  110. console.error(e);
  111. }
  112. //底部信息
  113. try{
  114. createFooterLayer();
  115. addFinishTimeToFooter();
  116. } catch(e){
  117. console.error(e);
  118. }
  119. //导航栏翻页监听
  120. addListenerToNav();
  121. //列表翻页监听
  122. if (window.location.search.indexOf("kw=")!= -1 && window.location.href.indexOf("search")==-1){
  123. addListenerToList();
  124. adinListClean();
  125. disableForumCard();
  126. //自动收起指引 *20180509
  127. closeGuide();
  128. //弹框关闭 *20181013
  129. removePopupModal();
  130. //关注按钮修复 *20200116
  131. fixFocusButton();
  132. } else {
  133. if (window.location.href.indexOf("tieba.baidu.com/p/") != -1){
  134. addListenerToPage();
  135. tpointADClean();
  136. adinPageClean();
  137. reverseorder();
  138. } else {
  139. if (window.location.href.indexOf("tieba.baidu.com/group") != -1){
  140. console.warn('贴吧页面精简: 当前位于群组页面,不执行群组页面惰性脚本');
  141. } else {
  142. if (homePageMatch.test(window.location.href)){
  143. bindCleanIndexADEvent();
  144. } else {
  145. console.warn('贴吧页面精简: 页面未适配延迟脚本');
  146. }
  147. }
  148. }
  149. }
  150. });
  151. //延迟执行
  152. setTimeout(function(){
  153. var interval = setInterval(check,sleepTime * checkrate);
  154. var n=0;
  155. function check(){
  156. var times = n+1;
  157. console.warn('贴吧页面精简: 延迟脚本正在执行第 ' + times + ' 次');
  158. //控制面板
  159. try{
  160. console.warn('贴吧页面精简: 正在创建控制面板');
  161. if(isCtrlPanelOn){
  162. createControlPanel();
  163. }
  164. } catch(e){
  165. console.error(e);
  166. }
  167. //底部信息
  168. try{
  169. createFooterLayer();
  170. } catch(e){
  171. console.error(e);
  172. }
  173. //导航栏翻页监听
  174. addListenerToNav();
  175. //列表翻页监听
  176. if (window.location.search.indexOf("kw=")!= -1 && window.location.href.indexOf("search")==-1){
  177. addListenerToList();
  178. adinListClean();
  179. disableForumCard();
  180. //自动收起指引 *20180509
  181. closeGuide();
  182. //弹框关闭 *20181013
  183. removePopupModal();
  184. //修复关注按钮 *20200116
  185. fixFocusButton();
  186. } else {
  187. if (window.location.href.indexOf("tieba.baidu.com/p/") != -1){
  188. addListenerToPage();
  189. tpointADClean();
  190. adinPageClean();
  191. reverseorder();
  192. } else {
  193. if (homePageMatch.test(window.location.href)){
  194. bindCleanIndexADEvent();
  195. cleanADinIndex();
  196. }
  197. }
  198. }
  199. reStart();
  200. function reStart(){
  201. n++;
  202. if (n>delayScriptRunTimes-1){
  203. clearInterval(interval);
  204. }
  205. }
  206. }
  207. },sleepTime);
  208. } else {
  209. setTimeout(function(){
  210. var interval = setInterval(check,sleepTime * checkrate);
  211. var n = 0;
  212. function check(){
  213. //控制面板
  214. try{
  215. console.warn('贴吧页面精简: 正在创建控制面板');
  216. if(isCtrlPanelOn){
  217. createControlPanel();
  218. }
  219. } catch(e){
  220. console.error(e);
  221. }
  222. //底部信息
  223. try{
  224. createFooterLayer();
  225. } catch(e){
  226. console.error(e);
  227. }
  228. n++;
  229. if (n>delayScriptRunTimes -1){
  230. clearInterval(interval);
  231. }
  232. }
  233. });
  234.  
  235. $(document).ready(function(){
  236. //加载计时
  237. finishTime = new Date().getTime() - startTime;
  238. console.log('贴吧页面精简: 页面加载用时: ' + finishTime);
  239. //控制面板
  240. try{
  241. console.warn('贴吧页面精简: 正在创建控制面板');
  242. if(isCtrlPanelOn){
  243. createControlPanel();
  244. }
  245. } catch(e){
  246. console.error(e);
  247. }
  248. //底部信息
  249. try{
  250. createFooterLayer();
  251. addFinishTimeToFooter();
  252. } catch(e){
  253. console.error(e);
  254. }
  255. });
  256. console.warn('贴吧页面精简: 后处理脚本已跳过');
  257. }
  258. //=========================
  259.  
  260. //=========================
  261. //功能区 请勿修改下面的内容
  262. //=========================
  263. //初始化
  264. function initialize(){
  265. sleepTime = initialize_var("sleepTime",300);
  266. sleepTimeWhenPageTurn = initialize_var("sleepTimeWhenPageTurn",800);
  267. reverseSleepTime = initialize_var("reverseSleepTime",200);
  268. postprocess = initialize_var("postprocess",true);
  269. isRedirect = initialize_var("isRedirect",true);
  270. homePageProcess = initialize_var("homePageProcess",true);
  271. groupPageProcess = initialize_var("groupPageProcess",true);
  272. noLoginProcess = initialize_var("noLoginProcess",true);
  273. reverse = initialize_var("reverse",false);
  274. homeProcess = initialize_var("homeProcess",true);
  275. isHeadimg = initialize_var("isHeadimg",false);
  276. checkrate = initialize_var("checkrate",1);
  277. delayScriptRunTimes = initialize_var("delayScriptRunTimes",6);
  278. displayLive = initialize_var("displayLive",false);
  279. displaySign = initialize_var("displaySign",false);
  280. autoCloseGuide = initialize_var("autoCloseGuide",true);
  281. //固定开关 *20180510
  282. isCtrlPanelOn = initialize_var("isCtrlPanelOn",true);
  283. }
  284. function initialize_var(name,defaultSet){
  285. var obj = GM_getValue(name,defaultSet);
  286. if (obj === undefined){
  287. obj = defaultSet;
  288. }
  289. return obj;
  290. }
  291. //css修改
  292. function appendCSS(){
  293. var cssText = "";
  294. //顶部直播栏
  295. cssText += '#video_frs_head {display: none !important;}';
  296. //右侧会员模块
  297. cssText += '.celebrity {display: none !important;}';
  298. //右侧我的应用模块
  299. cssText += '.my_app {display: none !important;}';
  300. //热议榜
  301. cssText += '.topic_list_box {display: none !important;}';
  302. //广告灰色label
  303. cssText += '.label_text {display: none !important;}';
  304. //右边一排图标
  305. cssText += '.j_icon_slot {display: none !important;}';
  306. //会员图标(会造成用户名左移,一定程度上影响整体美观)
  307. //cssText += '.icon_tbworld {display: none !important;}';
  308. //您可能感兴趣的吧
  309. cssText += '.forum_recommend {display: none !important;}';
  310. //右上角应用中心
  311. cssText += '.u_menu_wrap.u_appcenterEntrance_wrap {display: none !important;}';
  312. //右上角会员官网
  313. cssText += '.u_joinvip_wrap.vip_red.j_btn_getmember {display: none !important;}';
  314. cssText += '.u_joinvip {display: none !important;}';
  315. //内页顶部banner
  316. cssText += '.l_banner {display: none !important;}';
  317. //内页成就section
  318. cssText += '.achievement_medal_section {display: none !important;}';
  319. //顶部游戏信息
  320. cssText += '.game-head-game-info-wrapper {display: none !important;}';
  321. //内页送礼物按钮
  322. cssText += '.post-foot-send-gift-btn {display: none !important;}';
  323. //会员挽尊按钮
  324. cssText += '.save_face_bg {display: none !important;}';
  325. cssText += '.save_face_bg_2 {display: none !important;}';
  326. //底部游戏开测
  327. cssText += '#duoku_servers_list {display: none !important;}';
  328. //右侧热门卡包
  329. cssText += '.u9_aside {display: none !important;}';
  330. //右侧小说人气榜
  331. cssText += '.novel-ranking-frs-body {display: none !important;}';
  332. //头像下面的一排图标
  333. cssText += '.icon_wrap {display: none !important;}';
  334. //贴吧触点推广图片(在延迟处理前预处理)
  335. cssText += '.tpoint-imgs {display: none !important;}';
  336. //右下角炮筒
  337. cssText += '.j-firework-sender {display: none !important;}';
  338. //访谈直播
  339. if (!displayLive){
  340. cssText += '.interview {display: none !important;}';
  341. }
  342. //贴内相关推荐
  343. cssText += '.thread_recommend {display: none !important;}';
  344. //贴内广告
  345. cssText += '.iframe_wrapper {display: none !important;}';
  346. //右侧贴吧作者认证
  347. cssText += '.author-manager {display: none !important;}';
  348. //输入框placeholder
  349. cssText += '.tb_poster_placeholder {display: none !important;}';
  350. //图片签名档
  351. if (!displaySign){
  352. cssText += '.j_user_sign {display: none !important;}';
  353. cssText += '.d_sign_split {display: none !important;}';
  354. }
  355. //会员名牌
  356. cssText += '.pb_nameplate {display: none !important;}';
  357. //右侧菜单栏精简
  358. cssText += '.tbui_fbar_props {display: none !important;}';
  359. cssText += '.tbui_fbar_tsukkomi {display: none !important;}';
  360. //吧主专版
  361. cssText += '.tbui_fbar_bazhu {display: none !important;}';
  362. //右侧可点击广告
  363. if (window.location.href !== "http://tieba.baidu.com/" && window.location.href !== "https://tieba.baidu.com/"){
  364. cssText += '.j_click_stats {display: none !important;}';
  365. }
  366. //右侧视频推荐
  367. cssText += '#video_aside {display: none !important;}';
  368. //一楼电影广告
  369. cssText += '.tpoint-skin {display: none !important;}';
  370. //直播页面底部弹出栏
  371. cssText += '.attention_tip_wrap {display: none !important;}';
  372. //底部注册/登录横条
  373. cssText += '.guidance_fc {display: none !important;}';
  374. //content-ad span
  375. cssText += '.content-ad {display: none !important;}';
  376. //head ad span
  377. cssText += '.head_ad_tag {display: none !important;}';
  378. cssText += '.head_ad_pop {display: none !important;}';
  379. //会员置顶bubble
  380. cssText += '#tb_message_tip_d {display: none !important;}';
  381. //应用中心nav
  382. cssText += '.app_forum_top_nav {display: none !important;}';
  383. cssText += '#j_core_title_wrap {top:0px !important;}';
  384. //顶栏会员
  385. cssText += '.u_member {display: none !important;}';
  386. //导航栏游戏
  387. cssText += '#j_navtab_game {display: none !important;}';
  388. //发帖框气泡
  389. cssText += '.ui_bubble_body {display: none !important;}';
  390. //礼赞
  391. cssText += '.gift-goin {display: none !important;}';
  392. //漂流瓶
  393. cssText += '.tbui_fbar_nobottle {display: none !important;}';
  394. //扫描下载APP
  395. cssText += '.app_download_box {display: none !important;}';
  396. //某个右侧浮动广告的close按钮
  397. cssText += '.j_click_close {display: none !important;}';
  398. //618 Banner
  399. cssText += '.showBar {display: none !important;}';
  400. //右上角气泡
  401. cssText += '.ui_bubble_content {display: none !important}';
  402. //Hao123
  403. cssText += '.j_u_menu_extra_url_link {display: none !important}';
  404. //大家都在搜
  405. cssText += '.search_back_box {display:none !important}';
  406. //下载APP
  407. cssText += '.tbui_fbar_down {display:none !important}';
  408. //nani
  409. cssText += '.nani_app_download_box {display:none !important;}';
  410. //会员菜单
  411. cssText += '.u_menu_member {display:none !important;}';
  412. //菜单 *20181012
  413. cssText += '.u_mytbmall,.u_game,.u_blue{display:none !important;}';
  414.  
  415. //群组页面右侧下载
  416. if (groupPageProcess){
  417. if (window.location.href.indexOf("tieba.baidu.com/group") != -1){
  418. cssText += '.right {display: none !important;}';
  419. }
  420. }
  421.  
  422. //主页模块精简
  423. if (homePageProcess){
  424. if (homePageMatch.test(window.location.href)){
  425. //顶部
  426. try{
  427. if (unsafeWindow.PageData.user.is_login === 1){
  428. cssText += '.top-sec {display: none !important;}';
  429. }
  430. } catch (e){
  431. console.error('贴吧页面精简: 登录状态检查错误');
  432. console.error(e);
  433. }
  434. //直播秀
  435. cssText += '.spage_liveshow_slide {display: none !important;}';
  436. //以下模块因为在右侧有一个下滑页面时让模块仍然保持在可视区域内的设计,单独精简一个会造成滚动页面时模块错位,所以全部精简
  437. //乱七八糟的滚动活动模块
  438. cssText += '#plat_act_wrapper {display: none !important;}';
  439. //豪友俱乐部
  440. cssText += '.member_rank {display: none !important;}';
  441. //媒体进驻
  442. cssText += '#adide_platform {display: none !important;}';
  443. //贴吧娱乐
  444. cssText += '#media_item {display: none !important;}';
  445. //我的游戏
  446. cssText += '#spage_game_tab_wrapper {display: none !important;}';
  447. //公告板
  448. cssText += '#notice_item {display: none !important;}';
  449. //调整位置 *20171223
  450. cssText += '.right-sec {margin-top:-15px !important;}';
  451. //贴吧精选专题 *20171223
  452. cssText += '.aggregate_entrance_wrap {display:none !important;}';
  453. //未登录时的滚动横幅 *20180504
  454. cssText += '#rec_left {display:none !important;} #rec_right{float:right;position:absolute;right:30px;margin-top:15px;}';
  455. //用户面板的一些图表等 *20181012
  456. cssText += '.icon_tbworld {display:none !important;} .user_score{display:none !important;}';
  457. }
  458. }
  459.  
  460. //个人主页精简
  461. if (homeProcess){
  462. if (window.location.href.indexOf("tieba.baidu.com/home") !== -1){
  463. //右侧礼物面板
  464. cssText += ".ihome-aside-gift-center {display: none !important}";
  465. //求婚按钮
  466. cssText += ".userinfo-marry {display: none !important}";
  467. //我的夺宝
  468. cssText += ".ihome-aside-grab-treasure {display: none !important}";
  469. //我的T豆、蓝钻
  470. cssText += ".userinfo_scores {display: none !important}";
  471. }
  472. }
  473.  
  474. //列表页头图精简
  475. if (window.location.href.indexOf("tieba.baidu.com/f") !== -1){
  476. if (isHeadimg){
  477. cssText += ".head_banner_img,.head_ad_pop,.head_banner {display: none !important}";
  478. //顶部css调整 *20171223
  479. cssText += '.head_content {padding-top:20px !important}';
  480. cssText += '.card_banner,.plat_recom_carousel {display:none !important}';
  481. cssText += '.card_head {width:70px !important;height:70px !important;margin-bottom:10px !important;margin-top:100px !important}';
  482. cssText += '.card_head_img {width:70px !important;height:70px !important;}';
  483. cssText += '.card_title {margin-left:-50px !important;}';
  484. cssText += '.card_slogan {margin-left:-50px !important;}';
  485. }
  486. }
  487.  
  488. //设置面板css
  489. cssText += '#backrunnerJSSetting_root {right:0 !important;} #backrunnerJSSetting_con {right:0 !important;width:200px important;}';
  490. cssText += '#backrunnerJSSetting_con a {display:block !important;white-space:nowrap; !important}';
  491. cssText += '#backrunnerJSSetting_con li {line-height:23px !important;display:block !important;white-space:nowrap !important;}';
  492. 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;}';
  493. cssText += '.search_nav {margin-right:470px !important;}';
  494.  
  495. //reverse相关css *20171223
  496. cssText += '.br_reverse_li {display:inline-block !important;margin-left:15px !important;margin-top:-14px !important;}';
  497. cssText += '.core_title_txt {width:400px !important;}';
  498.  
  499. //底部信息css
  500. cssText += '#footer {padding-bottom:0px !important;}';
  501.  
  502. console.log('贴吧页面精简: css创建完成');
  503.  
  504. var element = document.createElement('link');
  505. element.rel="stylesheet";
  506. element.type="text/css";
  507. element.href='data:text/css,'+cssText;
  508.  
  509. document.documentElement.appendChild(element);
  510.  
  511. var modStyle = document.querySelector('#modCSS');
  512. if (modStyle === null){
  513. modStyle = document.createElement('style');
  514. modStyle.id = 'modCSS';
  515. document.body.appendChild(modStyle);
  516. modStyle.innerHTML = cssText;
  517. }
  518. console.log('贴吧页面精简: css已添加');
  519. }
  520. //列表翻页监听
  521. function addListenerToList(){
  522. $('#frs_list_pager a').each(function(){
  523. this.addEventListener('click',listPageTurnEvent);
  524. });
  525. console.log('贴吧页面精简: 列表翻页监听添加完毕');
  526. }
  527. //帖子、精品翻页监听
  528. function addListenerToNav(){
  529. $('.nav_list li').each(function(){
  530. if(this.attributes['data-tab-main'] || this.attributes['data-tab-good']){
  531. this.getElementsByTagName('a')[0].addEventListener('click',listPageTurnEvent);
  532. }
  533. });
  534. }
  535. //列表翻页监听事件
  536. function listPageTurnEvent(){
  537. console.warn('贴吧页面精简: 列表翻页事件触发');
  538. setTimeout(function(){
  539. var interval = setInterval(check,sleepTimeWhenPageTurn * checkrate);
  540. function check(){
  541. addListenerToNav();
  542. addListenerToList();
  543. adinListClean();
  544. }
  545. setTimeout(function(){
  546. addListenerToNav();
  547. addListenerToList();
  548. adinListClean();
  549. },sleepTime);
  550. setTimeout(function(){
  551. addListenerToNav();
  552. addListenerToList();
  553. adinListClean();
  554. clearInterval(interval);
  555. },finishTime/3);
  556. },sleepTimeWhenPageTurn);
  557. }
  558. function addListenerToPage(){
  559. $('.l_pager a').each(function(){
  560. this.addEventListener('click',pageTurnEvent);
  561. });
  562. console.log('贴吧页面精简: 帖子翻页监听添加完毕');
  563. }
  564. function pageTurnEvent(){
  565. console.warn('贴吧页面精简: 帖子翻页事件触发');
  566. setTimeout(function(){
  567. var interval = setInterval(check,sleepTimeWhenPageTurn * checkrate);
  568. function check(){
  569. addListenerToNav();
  570. addListenerToPage();
  571. adinPageClean();
  572. tpointADClean();
  573. reverseorder();
  574. }
  575. setTimeout(function(){
  576. addListenerToNav();
  577. addListenerToPage();
  578. adinPageClean();
  579. tpointADClean();
  580. reverseorder();
  581. },sleepTime);
  582. setTimeout(function(){
  583. addListenerToNav();
  584. addListenerToPage();
  585. adinPageClean();
  586. tpointADClean();
  587. reverseorder();
  588. clearInterval(interval);
  589. },finishTime/3);
  590. },sleepTimeWhenPageTurn);
  591. }
  592. //触点推广
  593. function tpointADClean(){
  594. console.log('贴吧页面精简: 开始精简触点推广');
  595. var pointad = document.getElementsByClassName('tpoint-imgs');
  596. console.log('贴吧页面精简: 抓取到的广告元素数量: '+pointad.length);
  597. for(var i=0;i<pointad.length;i++){
  598. pointad[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.removeChild(pointad[i].parentNode.parentNode.parentNode.parentNode.parentNode);
  599. }
  600. console.log('贴吧页面精简: 触点推广精简完毕');
  601. }
  602.  
  603. //列表内广告
  604. function adinListClean(){
  605. console.log('贴吧页面精简: 开始精简列表内广告');
  606. var adinList = document.getElementsByClassName('threadlist_rep_num');
  607. var num = 0;
  608. console.log('贴吧页面精简: 列表内元素抓取量: '+adinList.length);
  609. for (var i=0;i<adinList.length;i++){
  610. if (adinList[i].title === "广告" || adinList[i].title === "热门"){
  611. num++;
  612. adinList[i].parentNode.parentNode.parentNode.parentNode.removeChild(adinList[i].parentNode.parentNode.parentNode);
  613. }
  614. }
  615. console.log('贴吧页面精简: 列表内广告精简完毕,共精简 '+ num + ' 个');
  616. //新增根据class过滤
  617. var list = document.getElementById('thread_list').children;
  618. for (i=0;i<list.length;i++){
  619. var className=list[i].getAttribute('class');
  620. if (className != null){
  621. if (list[i].getAttribute('class').indexOf('thread_top_list_folder')==-1 && list[i].getAttribute('class').indexOf('j_thread_list')==-1){
  622. list[i].parentNode.removeChild(list[i]);
  623. }
  624. }
  625. }
  626. console.log('贴吧页面精简: 扫描列表精简其他广告');
  627. //清理无用tab *20181012
  628. var tabs = document.getElementsByClassName("j_tbnav_tab_a");
  629. for (i=0;i<tabs.length;i++){
  630. if (tabs[i].innerHTML.indexOf("直播") != -1){
  631. tabs[i].parentNode.removeChild(tabs[i]);
  632. }
  633. if (tabs[i].innerHTML.indexOf("应用") != -1){
  634. tabs[i].parentNode.removeChild(tabs[i]);
  635. }
  636. }
  637. }
  638.  
  639. //贴内广告
  640. function adinPageClean(){
  641. console.log('贴吧页面精简: 开始精简贴内广告');
  642. var ad = document.getElementsByClassName('iframe_wrapper');
  643. console.log('贴吧页面精简: 抓取到的广告元素数量: '+ad.length);
  644. for(var i=0;i<ad.length;i++){
  645. ad[i].parentNode.parentNode.removeChild(ad[i].parentNode);
  646. }
  647. console.log('贴吧页面精简: 贴内广告精简完毕');
  648. //贴内插入广告
  649. var plus = document.getElementsByClassName('d_name');
  650. for (i=0;i<plus.length;i++){
  651. var dat = plus[i].getAttribute('data-field');
  652. if(!dat || !dat.replace(/\s/g,'')){
  653. plus[i].parentNode.parentNode.parentNode.parentNode.removeChild(plus[i].parentNode.parentNode.parentNode);
  654. }
  655. }
  656. }
  657.  
  658. //免登录看帖
  659. function noLogin(){
  660. try{
  661. var login = document.createElement('script');
  662. login.innerHTML="PageData.user.is_login = true";
  663. document.head.appendChild(login);
  664. } catch(e){
  665. console.error('贴吧页面精简: 免登录看帖加载错误');
  666. console.error(e);
  667. }
  668. }
  669.  
  670. //更新提醒
  671. function updateAlert(){
  672. var s_update = "贴吧页面精简:\n检测到脚本版本更改\n\n";
  673. var version = GM_getValue("version");
  674. if (version !== GM_info.script.version){
  675. console.warn("贴吧页面精简:检测到脚本版本更改:" + version + " → " + GM_info.script.version);
  676. if (version === undefined){
  677. version = "未知";
  678. }
  679. switch (version){
  680. default:
  681. //版本更新时删除废弃变量
  682. deleteTrashValue();
  683. s_update += "版本已从 " + version + " 更新为 " + GM_info.script.version + "\n\n" + GM_info.script.version + "版本的更新内容为:\n修复对新版Chrome的兼容性问题。\n\n如果遇到Bug请及时提交反馈,感谢。\n\n【重要提醒!必看!】\n如果您没有安装Adblock,请安装Adblock以获得最佳体验\n\n由于这个脚本已经比较稳定,后续只修复Bug和根据贴吧的变化添补新功能\n";
  684. break;
  685. case "未知":
  686. s_update += "欢迎使用贴吧页面精简脚本\n您当前的脚本版本为: " + version + "\n\n【关于设置】\n您可以通过右上角的设置面板设置相关功能以获得最佳体验\n\n【重要提醒!必看!】\n如果您没有安装Adblock,请安装Adblock以获得最佳体验\n\n由于这个脚本已经比较稳定,后续只修复Bug和根据贴吧的变化添补新功能\n";
  687. break;
  688. case "2.8.0":
  689. s_update += "版本已从 " + version + " 降级为 " + GM_info.script.version + "\n\n" + "建议使用最新版本的脚本以获得最佳体验\n降级会造成您的设置丢失,请检查您的设置\n";
  690. break;
  691. }
  692. s_update += "\n遇到任何问题请立刻到GreasyFork反馈\n或者发送邮件至dev@backrunner.top\n如果您觉得本脚本好用可使用支付宝扫描GreasyFork中的二维码或底部赞助链接中的二维码向我捐赠\n收到您的捐赠后我会将您的id加入到感谢名单\n感谢名单显示在这里和脚本描述内";
  693. alert(s_update);
  694. GM_setValue("version",GM_info.script.version);
  695. } else {
  696. console.warn("贴吧页面精简:未检测到脚本版本更改");
  697. }
  698. }
  699. //创建顶栏控制面板
  700. function createControlPanel(){
  701. if (document.querySelector('#backrunnerJSSetting_root') === null){
  702. try{
  703. //userbar获取与主层创建
  704. var userbar = $('#com_userbar').children('ul')[0];
  705. var li = document.createElement('li');
  706. var div = document.createElement('div');
  707. var a = document.createElement('a');
  708.  
  709. //主层设置
  710. a.innerHTML = "脚本设置";
  711.  
  712. //主层事件
  713. div.addEventListener('mouseenter',cpOnMouseEnter);
  714. div.addEventListener('mouseleave',cpOnMouseLeave);
  715.  
  716. //菜单层创建
  717. var menuroot = document.createElement('div');
  718. var menucon = document.createElement('div');
  719. var menudiv = document.createElement('div');
  720. menuroot.setAttribute('class','u_ddl');
  721. menuroot.setAttribute('id','backrunnerJSSetting_root');
  722. menucon.setAttribute('class','u_ddl_con');
  723. menucon.setAttribute('id','backrunnerJSSetting_con');
  724. menudiv.setAttribute('class','u_ddl_con_top');
  725. menudiv.setAttribute('id','backrunnerJSSetting_main');
  726. menucon.appendChild(menudiv);
  727. menuroot.appendChild(menucon);
  728.  
  729. //菜单层事件
  730. menuroot.addEventListener('mouseenter',cpOnMouseEnter);
  731. menuroot.addEventListener('mouseleave',cpOnMouseLeave);
  732.  
  733. //菜单列表创建
  734. var menu = document.createElement('ui');
  735. //0:文本框 1:复选框 2:按钮
  736. createMenuItem(menu,1,"postprocess","后处理脚本","");
  737. createMenuItem(menu,1,"isRedirect","重定向","");
  738. createMenuItem(menu,1,"homepageprocess","主页精简","");
  739. createMenuItem(menu,1,"isHeadimg","精简列表页头图","");
  740. createMenuItem(menu,1,"displayLive","是否显示直播帖","");
  741. createMenuItem(menu,1,"displaySign","是否显示用户签名档","");
  742. createMenuItem(menu,1,"autoCloseGuide","自动收起指引","");
  743. createMenuItem(menu,1,"homeProcess","个人主页精简","");
  744. createMenuItem(menu,1,"groupprocess","群组页面精简","");
  745. createMenuItem(menu,1,"nologin","免登录看帖","");
  746. createMenuItem(menu,1,"reverse","倒序看帖(实验性)","");
  747. createMenuItem(menu,0,"sleepTime","主脚本延迟时间");
  748. createMenuItem(menu,0,"delayScriptRunTimes","延迟脚本执行次数","");
  749. createMenuItem(menu,0,"sleepTimePage","翻页脚本延迟时间","");
  750. createMenuItem(menu,0,"reverseSleepTime","倒序查看脚本延迟时间","");
  751. createMenuItem(menu,0,"checkrate","脚本延迟时间倍率","");
  752. createMenuItem(menu,2,"refresh","刷新页面","刷新");
  753. createMenuItem(menu,2,"submit","提交设置","提交");
  754. createMenuItem(menu,2,"reset","重置设置","重置");
  755. menudiv.appendChild(menu);
  756.  
  757. //菜单入口
  758. div.appendChild(a);
  759. div.setAttribute('class','u_menu_item');
  760. div.setAttribute('id','backrunnerJSSetting_item');
  761. li.appendChild(div);
  762. li.appendChild(menuroot);
  763. userbar.appendChild(li);
  764.  
  765. //菜单内容初始化
  766. menuInitialize();
  767.  
  768. //菜单内事件创建
  769. createMenuEvent();
  770. } catch(e){
  771. console.error(e);
  772. }
  773. } else {
  774. console.warn('贴吧页面精简: 控制面板已存在');
  775. }
  776. }
  777. //菜单项创建
  778. function createMenuItem(menu,type,id,labelContent,innerContent){
  779. //层创建
  780. var li = document.createElement('li');
  781. var div = document.createElement('div');
  782. var d_a = document.createElement('div');
  783. var d_i = document.createElement('div');
  784. //层设置
  785. d_a.setAttribute('style','float:left;width:150px');
  786. switch(type){
  787. case 0:
  788. d_i.setAttribute('style','padding-top:7px;padding-left:150px;padding-right:10px;');
  789. break;
  790. case 1:
  791. d_i.setAttribute('style','padding-top:8px;padding-left:192px;padding-right:10px;');
  792. break;
  793. case 2:
  794. d_i.setAttribute('style','padding-top:6px;padding-left:150px;padding-right:10px;');
  795. break;
  796. }
  797. //元素创建
  798. var a = document.createElement('a');
  799. var i = document.createElement('input');
  800. //元素设置
  801. a.innerHTML = labelContent;
  802. switch(type){
  803. case 0:
  804. i.setAttribute('style','width:50px;text-align:right');
  805. i.setAttribute('id','backrunner_i_'+id);
  806. break;
  807. case 1:
  808. //复选框
  809. i.setAttribute('type','checkbox');
  810. i.setAttribute('id','backrunner_i_'+id);
  811. break;
  812. case 2:
  813. //按钮
  814. i = document.createElement('button');
  815. i.innerHTML = innerContent;
  816. i.setAttribute('style','width:52px');
  817. i.setAttribute('id','backrunner_btn_'+id);
  818. break;
  819. }
  820.  
  821. //元素添加到层
  822. d_a.appendChild(a);
  823. d_i.appendChild(i);
  824. //元素层添加到主层
  825. div.appendChild(d_a);
  826. div.appendChild(d_i);
  827. //主层添加到li
  828. li.appendChild(div);
  829. //li添加到menu
  830. menu.appendChild(li);
  831. }
  832. //菜单初始化
  833. function menuInitialize(){
  834. menuInitialize_checkbox('postprocess',postprocess);
  835. menuInitialize_checkbox('isRedirect',isRedirect);
  836. menuInitialize_checkbox('homepageprocess',homePageProcess);
  837. menuInitialize_checkbox('homeProcess',homeProcess);
  838. menuInitialize_checkbox('isHeadimg',isHeadimg);
  839. menuInitialize_checkbox('groupprocess',groupPageProcess);
  840. menuInitialize_checkbox('nologin',noLoginProcess);
  841. menuInitialize_checkbox('reverse',reverse);
  842. menuInitialize_checkbox('displayLive',displayLive);
  843. menuInitialize_checkbox('displaySign',displaySign);
  844. menuInitialize_checkbox('autoCloseGuide',autoCloseGuide);
  845. menuInitialize_input('sleepTime',sleepTime);
  846. menuInitialize_input('delayScriptRunTimes',delayScriptRunTimes);
  847. menuInitialize_input('sleepTimePage',sleepTimeWhenPageTurn);
  848. menuInitialize_input('reverseSleepTime',reverseSleepTime);
  849. menuInitialize_input('checkrate',checkrate);
  850. }
  851. //菜单checkbox初始化
  852. function menuInitialize_checkbox(id,variable){
  853. var i = document.getElementById('backrunner_i_'+id);
  854. if (i !== null){
  855. if (variable){
  856. i.checked = true;
  857. } else {
  858. i.checked = false;
  859. }
  860. }
  861. }
  862. //菜单input初始化
  863. function menuInitialize_input(id,variable){
  864. var i = document.getElementById('backrunner_i_'+id);
  865. if (i !== null){
  866. i.value = variable;
  867. }
  868. }
  869.  
  870. //菜单内事件创建
  871. function createMenuEvent(){
  872. try{
  873. //刷新
  874. var btn_refresh = document.getElementById('backrunner_btn_refresh');
  875. if (btn_refresh !== null){
  876. btn_refresh.addEventListener('click',btn_refresh_click);
  877. }
  878. //提交
  879. var btn_submit = document.getElementById('backrunner_btn_submit');
  880. if (btn_submit !== null){
  881. btn_submit.addEventListener('click',btn_submit_click);
  882. }
  883. //重置
  884. var btn_reset = document.getElementById('backrunner_btn_reset');
  885. if (btn_reset !== null){
  886. btn_reset.addEventListener('click',btn_reset_click);
  887. }
  888. }catch(e){
  889. console.error(e);
  890. }
  891. }
  892. //刷新按钮事件
  893. function btn_refresh_click(){
  894. window.location.reload(true);
  895. }
  896. //提交按钮事件
  897. function btn_submit_click(){
  898. postprocess = convertBoolValue('postprocess');
  899. isRedirect = convertBoolValue('isRedirect');
  900. homePageProcess = convertBoolValue('homepageprocess');
  901. homeProcess = convertBoolValue('homeProcess');
  902. isHeadimg = convertBoolValue('isHeadimg');
  903. displayLive = convertBoolValue('displayLive');
  904. displaySign = convertBoolValue('displaySign');
  905. autoCloseGuide = convertBoolValue('autoCloseGuide');
  906. groupPageProcess = convertBoolValue('groupprocess');
  907. noLoginProcess = convertBoolValue('nologin');
  908. reverse = convertBoolValue('reverse');
  909. sleepTime = convertNumValue('sleepTime');
  910. delayScriptRunTimes = convertNumValue('delayScriptRunTimes');
  911. sleepTimeWhenPageTurn = convertNumValue('sleepTimePage');
  912. reverseSleepTime = convertNumValue('reverseSleepTime');
  913. checkrate = convertNumValue('checkrate');
  914.  
  915. if (postprocess){
  916. if (window.confirm('确认要更改设置?')){
  917. replaceStoredSettings();
  918. menuInitialize();
  919. window.location.reload(true);
  920. } else {
  921. menuInitialize();
  922. }
  923. } else {
  924. if (window.confirm('【重要】\n您禁用了后处理脚本,本脚本绝大部分功能将无法使用\n\n确认要更改设置?')){
  925. replaceStoredSettings();
  926. menuInitialize();
  927. window.location.reload(true);
  928. } else {
  929. menuInitialize();
  930. }
  931. }
  932. }
  933. function btn_reset_click(){
  934. if (window.confirm('确认要重置设置?')){
  935. GM_deleteValue("postprocess");
  936. GM_deleteValue("isRedirect");
  937. GM_deleteValue("sleepTime");
  938. GM_deleteValue("delayScriptRunTimes");
  939. GM_deleteValue("displayLive");
  940. GM_deleteValue("displaySign");
  941. GM_deleteValue("autoCloseGuide");
  942. GM_deleteValue("sleepTimeWhenPageTurn");
  943. GM_deleteValue("reverseSleepTime");
  944. GM_deleteValue("homePageProcess");
  945. GM_deleteValue("homeProcess");
  946. GM_deleteValue("isHeadimg");
  947. GM_deleteValue("groupPageProcess");
  948. GM_deleteValue("noLoginProcess");
  949. GM_deleteValue("reverse");
  950. GM_deleteValue("checkrate");
  951. window.location.reload(true);
  952. }
  953. }
  954. //将菜单中的bool值赋给变量
  955. function convertBoolValue(id){
  956. var i = document.getElementById('backrunner_i_'+id);
  957. if (i !== null){
  958. if (i.checked){
  959. return true;
  960. } else {
  961. return false;
  962. }
  963. }
  964. }
  965. //将菜单中的数值赋给变量
  966. function convertNumValue(id){
  967. var i = document.getElementById('backrunner_i_'+id);
  968. if (i !== null){
  969. return(parseFloat(i.value));
  970. }
  971. }
  972. //控制面板鼠标事件
  973. function cpOnMouseEnter(){
  974. try{
  975. var cp = document.getElementById('backrunnerJSSetting_root');
  976. cp.setAttribute('style','display:block;right:0;');
  977. } catch(e){
  978. console.error(e);
  979. }
  980. }
  981. function cpOnMouseLeave(){
  982. try{
  983. var cp = document.getElementById('backrunnerJSSetting_root');
  984. cp.setAttribute('style','display:none;right:0');
  985. } catch(e){
  986. console.error(e);
  987. }
  988. }
  989.  
  990. //替换储存的设置
  991. function replaceStoredSettings(){
  992. GM_setValue("postprocess",postprocess);
  993. GM_setValue("isRedirect",isRedirect);
  994. GM_setValue("sleepTime",sleepTime);
  995. GM_setValue("delayScriptRunTimes",delayScriptRunTimes);
  996. GM_setValue("displayLive",displayLive);
  997. GM_setValue("displaySign",displaySign);
  998. GM_setValue("autoCloseGuide",autoCloseGuide);
  999. GM_setValue("sleepTimeWhenPageTurn",sleepTimeWhenPageTurn);
  1000. GM_setValue("reverseSleepTime",reverseSleepTime);
  1001. GM_setValue("homePageProcess",homePageProcess);
  1002. GM_setValue("homeProcess",homeProcess);
  1003. GM_setValue("isHeadimg",isHeadimg);
  1004. GM_setValue("groupPageProcess",groupPageProcess);
  1005. GM_setValue("noLoginProcess",noLoginProcess);
  1006. GM_setValue("reverse",reverse);
  1007. GM_setValue("checkrate",checkrate);
  1008. }
  1009.  
  1010. //底部信息输出
  1011. function createFooterLayer(){
  1012. var footDiv;
  1013. var id;
  1014. if (document.querySelector('#backrunnerJSFooter')===null){
  1015. if (window.location.href.indexOf("tieba.baidu.com/f?") !== -1){
  1016. try{
  1017. footDiv = document.getElementsByClassName('frs_content_footer_pagelet')[0];
  1018. foot = document.createElement('div');
  1019. id = document.createElement('div');
  1020. foot.setAttribute('class','footer');
  1021. foot.setAttribute('id','footer');
  1022. foot.setAttribute('style','padding-top:0px !important;');
  1023. id.setAttribute('id','backrunnerJSFooter');
  1024. createFooterElement(foot,"已应用由BackRunner制作的贴吧精简脚本 ("+ GM_info.script.version+")","https://greasyfork.org/zh-CN/scripts/23687",false);
  1025. createFooterElement(foot,"捐赠作者(支付宝二维码)","https://smallfile.backrunner.top/images/alipay.jpg",true);
  1026. footDiv.appendChild(foot);
  1027. footDiv.appendChild(id);
  1028. console.warn('贴吧页面精简: 底部信息添加完成');
  1029. } catch(e){
  1030. console.error(e);
  1031. }
  1032. } else {
  1033. if (window.location.href.indexOf("tieba.baidu.com/p/") !== -1){
  1034. try{
  1035. footDiv = document.getElementsByClassName('pb_footer')[0];
  1036. foot = document.createElement('div');
  1037. id = document.createElement('div');
  1038. foot.setAttribute('class','footer');
  1039. foot.setAttribute('id','footer');
  1040. foot.setAttribute('style','padding-top:0px !important;');
  1041. id.setAttribute('id','backrunnerJSFooter');
  1042. createFooterElement(foot,"已应用由BackRunner制作的贴吧精简脚本 ("+ GM_info.script.version+")","https://greasyfork.org/zh-CN/scripts/23687",false);
  1043. createFooterElement(foot,"向作者捐款(支付宝二维码)","https://smallfile.backrunner.top/images/alipay.jpg",true);
  1044. footDiv.appendChild(foot);
  1045. footDiv.appendChild(id);
  1046. console.warn('贴吧页面精简: 底部信息添加完成');
  1047. } catch(e){
  1048. console.error(e);
  1049. }
  1050. }
  1051. }
  1052. } else {
  1053. console.warn('贴吧页面精简: 底部信息已存在');
  1054. }
  1055. }
  1056. function addFinishTimeToFooter(){
  1057. if (finishTime !== -1){
  1058. addSplitLineToFooter(foot);
  1059. createFooterElement(foot,"页面加载时间:" + finishTime+"ms","javascript:;",true);
  1060. }
  1061. }
  1062. function addSplitLineToFooter(footer){
  1063. try{
  1064. var splitLine=document.createElement('span');
  1065. splitLine.innerHTML="|";
  1066. footer.appendChild(splitLine);
  1067. }catch(e){
  1068. console.error(e);
  1069. }
  1070. }
  1071. function createFooterElement(footer,text,href,isLast){
  1072. var splitLine=document.createElement('span');
  1073. splitLine.innerHTML="|";
  1074. var content = document.createElement('a');
  1075. content.innerHTML=text;
  1076. content.setAttribute('href',href);
  1077. content.setAttribute('target',"_blank");
  1078. content.setAttribute('pv_code',"0");
  1079. footer.appendChild(content);
  1080. if (!isLast){
  1081. footer.appendChild(splitLine);
  1082. }
  1083. }
  1084. //头图禁用
  1085. function disableForumCard(){
  1086. if (isHeadimg){
  1087. try{
  1088. var forumcard = document.getElementById('forum-card-banner');
  1089. console.warn('贴吧页面精简: 正在精简头图');
  1090. if (forumcard !== null){
  1091. if (forumcard.getAttribute("src")!==""){
  1092. forumcard.setAttribute("src","");
  1093. forumcard.setAttribute("style","height:180px !important;background-color:white !important;");
  1094. }
  1095. }
  1096. } catch(e){
  1097. console.error(e);
  1098. }
  1099. }
  1100. }
  1101. //重定向
  1102. function redirect(){
  1103. var url = window.location.href;
  1104. //?red_tag重定向
  1105. var elements = window.location.search.toString().split('&');
  1106. for (var i = 0;i<elements.length;i++){
  1107. if (elements[i].indexOf('red_tag') !== -1){
  1108. url = url.replace('&'+elements[i],'');
  1109. url = url.replace(elements[i],'');
  1110. }
  1111. }
  1112. //奇怪域名重定向
  1113. if (url.indexOf('dq.tieba.com')!=-1){
  1114. url = url.replace('dq.tieba.com','tieba.baidu.com');
  1115. }
  1116. if (url.indexOf('jump.bdimg.com')!=-1){
  1117. url = url.replace('jump2.bdimg.com','tieba.baidu.com');
  1118. }
  1119. if (url.indexOf('jump2.bdimg.com')!=-1){
  1120. url = url.replace('jump2.bdimg.com','tieba.baidu.com');
  1121. }
  1122. if (url.indexOf('?traceid=')!=-1){
  1123. url = url.replace('?traceid=','');
  1124. }
  1125. if (url !== window.location.href){
  1126. window.location = url;
  1127. }
  1128. }
  1129. //倒序看帖按钮添加
  1130. function reverseorder(){
  1131. if (reverse){
  1132. //判定当前状态
  1133. var status = initialize_var('reverse_status',false);
  1134. if (document.querySelector('#br_reverse') === null){
  1135. var rightbtn = document.getElementsByClassName('core_title_btns')[0];
  1136. var btnli = document.createElement('li');
  1137. var btn = document.createElement('a');
  1138. console.warn('贴吧页面精简: 正在创建倒序查看按钮');
  1139. //判定是否为另一个帖子
  1140. var lastpage = initialize_var('reverse_lastpage','');
  1141. var currenthref = window.location.href;
  1142. var currentsearch = window.location.search;
  1143. var currentpage = currenthref.replace(currentsearch,'').replace('https://tieba.baidu.com/p/','').replace('http://tieba.baidu.com/p/','');
  1144. if (currentpage!=lastpage){
  1145. status = false;
  1146. }
  1147. GM_setValue('reverse_lastpage',currentpage);
  1148. GM_setValue('reverse_status',status);
  1149. if (status){
  1150. btn.innerHTML = '正序查看';
  1151. }else {
  1152. btn.innerHTML='倒序查看';
  1153. }
  1154. btn.setAttribute('id','br_reverse');
  1155. btn.setAttribute('class','btn-sub btn-small');
  1156. btnli.setAttribute('class','br_reverse_li quick_reply');
  1157. btnli.appendChild(btn);
  1158. rightbtn.appendChild(btnli);
  1159. rightbtn.addEventListener('click',reverse_click);
  1160. currenthref = window.location.href;
  1161. reverse_contents();
  1162. }
  1163. }
  1164. }
  1165. //倒序看帖点击事件
  1166. function reverse_click(){
  1167. var status = initialize_var('reverse_status',false);
  1168. if(status){
  1169. console.log('click');
  1170. //恢复正序
  1171. GM_setValue('reverse_status',false);
  1172. var btns = document.getElementsByClassName('pb_list_pager')[0].children;
  1173. if (btns.length === 0){
  1174. window.location.reload(true);
  1175. }else {
  1176. for (var i = 0;i < btns.length;i++){
  1177. if (btns[i].innerHTML == '1'){
  1178. //向首页跳转
  1179. window.location.href = btns[i].href;
  1180. }
  1181. }
  1182. }
  1183. } else {
  1184. //倒序
  1185. GM_setValue('reverse_status',true);
  1186. btns = document.getElementsByClassName('pb_list_pager')[0].children;
  1187. if (btns.length === 0){
  1188. window.location.reload(true);
  1189. }else {
  1190. for (var j = 0;j<btns.length;j++){
  1191. if (btns[j].innerHTML == '尾页'){
  1192. //向尾页跳转
  1193. window.location.href = btns[j].href;
  1194. }
  1195. }
  1196. }
  1197. }
  1198. }
  1199. //翻转当前页内容
  1200. function reverse_contents(){
  1201. setTimeout(function(){
  1202. var status = initialize_var('reverse_status',false);
  1203. if (status){
  1204. console.warn('贴吧页面精简: 正在翻转当前页内容');
  1205.  
  1206. //获取当前的pn
  1207. var search = window.location.search;
  1208. var searchs = search.split('&');
  1209. var pn;
  1210. for (var child = 0;child<searchs.length;child++){
  1211. if (searchs[child].indexOf('pn=') !== -1){
  1212. pn = searchs[child].replace('?','').replace('pn=','');
  1213. }
  1214. }
  1215. var list = document.getElementById('j_p_postlist');
  1216. var contents = list.children;
  1217. console.warn(contents);
  1218. if (contents.length == 1 && contents[0].id == "j_p_postlist"){
  1219. list = document.getElementsByClassName('p_postlist')[1];
  1220. contents = list.children;
  1221. }
  1222. console.warn(contents);
  1223. //倒序
  1224. for(var i = contents.length - 1; i >= 0; i--) {
  1225. list.appendChild(contents[i]);
  1226. }
  1227. }
  1228. },reverseSleepTime);
  1229. }
  1230. //自动收起指引
  1231. var isAutoCloseGuideSet = false;
  1232. function closeGuide(){
  1233. if (autoCloseGuide && !isAutoCloseGuideSet){
  1234. var topContent = document.getElementsByClassName("top_content");
  1235. var topContentMain = document.getElementsByClassName("top_cont_main");
  1236. if (topContent.length>0 && topContentMain.length>0){
  1237. topContent[0].setAttribute("class","top_content top_content_closed");
  1238. topContentMain[0].setAttribute("style","display:none;");
  1239. isAutoCloseGuideSet = true;
  1240. }
  1241. }
  1242. }
  1243. //版本更新删除废弃变量
  1244. function deleteTrashValue(){
  1245. var trashList = {};
  1246. for (var i = 0;i<trashList.length;i++){
  1247. GM_deleteValue("trashList[i]");
  1248. }
  1249. console.warn('贴吧页面精简: 版本更新,已删除废弃变量');
  1250. }
  1251. //打折卡等弹框屏蔽
  1252. function removePopupModal(){
  1253. var dialog = document.getElementsByClassName('dialogJ');
  1254. var dialogmodal = document.getElementsByClassName('dialogJmodal');
  1255. for (var i = 0;i<dialog.length;i++){
  1256. dialog[i].parentNode.removeChild(dialog[i]);
  1257. if (dialog[i].innerHTML.indexOf('确定不再关注' != -1)){
  1258. continue;
  1259. }
  1260. }
  1261. for (i = 0;i<dialogmodal.length;i++){
  1262. dialogmodal[i].parentNode.removeChild(dialogmodal[i]);
  1263. }
  1264. setTimeout(function(){
  1265. var dialog = document.getElementsByClassName('dialogJ');
  1266. var dialogmodal = document.getElementsByClassName('dialogJmodal');
  1267. for (var i = 0;i<dialog.length;i++){
  1268. dialog[i].parentNode.removeChild(dialog[i]);
  1269. }
  1270. for (i = 0;i<dialogmodal.length;i++){
  1271. dialogmodal[i].parentNode.removeChild(dialogmodal[i]);
  1272. }
  1273. },5000);
  1274. }
  1275. //清理首页动态内的广告 *20181022
  1276. var indexADEvent_a = false;
  1277. var indexADEvent_scroll = false;
  1278. var indexADEvent_tag_hot = false;
  1279. var indexADEvent_tag_personal = false;
  1280. var windowTempScrollTop = 0;
  1281. function bindCleanIndexADEvent(){
  1282. var btn = document.getElementById('btn_more');
  1283. var a = btn.children[0];
  1284. if (!indexADEvent_a){
  1285. console.log("贴吧页面精简: 已绑定首页动态广告清理的按钮点击事件");
  1286. a.addEventListener('click',function(){
  1287. setTimeout(function(){
  1288. cleanADinIndex();
  1289. },sleepTime);
  1290. });
  1291. indexADEvent_a = true;
  1292. }
  1293. if (!indexADEvent_scroll){
  1294. console.log("贴吧页面精简: 已绑定首页动态广告清理的滚动事件");
  1295. document.onscroll = function(){
  1296. if (document.documentElement.scrollTop - windowTempScrollTop > 300){
  1297. console.log("贴吧页面精简: 滚动触发,正在清理动态内的广告");
  1298. cleanADinIndex();
  1299. windowTempScrollTop = document.documentElement.scrollTop;
  1300. }
  1301. }
  1302. indexADEvent_scroll = true;
  1303. }
  1304. if (!indexADEvent_tag_hot){
  1305. var tag_hot = document.getElementById('j_remen_nav');
  1306. tag_hot.addEventListener('click',function(){
  1307. clearScrollTopTemp();
  1308. });
  1309. indexADEvent_tag_hot = true;
  1310. }
  1311. if (!indexADEvent_tag_personal){
  1312. var tag_personal = document.getElementById('nav-personal');
  1313. tag_personal.addEventListener('click',function(){
  1314. clearScrollTopTemp();
  1315. });
  1316. indexADEvent_tag_hot = true;
  1317. }
  1318. }
  1319. function clearScrollTopTemp(){
  1320. console.log("贴吧页面精简: 清理滚动高度缓存");
  1321. windowTempScrollTop = 0;
  1322. }
  1323. function cleanADinIndex(){
  1324. var ads = document.getElementsByClassName('home-place-item');
  1325. var count = 0;
  1326. for (var i = 0;i<ads.length;i++){
  1327. var extinfo = ads[i].getAttribute('data-ext_info');
  1328. if (typeof extinfo != 'undefined'){
  1329. ads[i].parentNode.removeChild(ads[i]);
  1330. count++;
  1331. };
  1332. }
  1333. console.log("贴吧页面精简: 清理了"+count+"条动态内的广告");
  1334. }
  1335. // 修复关注按钮
  1336. function fixFocusButton(){
  1337. $(document).on('mousedown', '.islike_focus' ,function(){
  1338. console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
  1339. setTimeout(function(){
  1340. window.location.reload();
  1341. }, 100);
  1342. });
  1343. }
  1344. })();