贴吧广告清理

清理百度贴吧(tieba.baidu.com)内的列表伪装,帖内伪装,触点广告,页首广告,推荐应用等各类广告

当前为 2024-01-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Kill TieBa AD
  3. // @name:zh-CN 贴吧广告清理
  4. // @name:zh-TW 貼吧廣告去除
  5. // @namespace hoothin
  6. // @version 1.3.2
  7. // @description Just Kill TieBa AD
  8. // @description:zh-CN 清理百度贴吧(tieba.baidu.com)内的列表伪装,帖内伪装,触点广告,页首广告,推荐应用等各类广告
  9. // @description:zh-TW 去除百度貼吧(tieba.baidu.com)内的列表偽裝,帖內偽裝,觸點廣告,頁首廣告,推薦應用等各類廣告
  10. // @author hoothin
  11. // @include http*://tieba.baidu.com/*
  12. // @exclude http*://tieba.baidu.com/
  13. // @exclude http*://tieba.baidu.com/index.html
  14. // @grant none
  15. // @run-at document-body
  16. // @supportURL http://www.hoothin.com
  17. // @license MIT License
  18. // @compatible chrome
  19. // @compatible firefox
  20. // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=rixixi@sina.com&item_name=Greasy+Fork+donation
  21. // @contributionAmount 1
  22. // ==/UserScript==
  23.  
  24. (function() {
  25. 'use strict';
  26. var observer, option;
  27. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  28. var tcss = ".j_encourage_entry,#video_frs_head,#encourage_entry,.tpoint-skin,#pb_adbanner,.iframe_wrapper,div.tpoint-skin,.j_click_stats,#thread_list>li:not(.j_thread_list):not(.thread_top_list_folder),#j_p_postlist>.clearfix:not([data-field*=post_id]){display:none !important;}";
  29. var snod = document.createElement('style');
  30. snod.innerHTML = tcss;
  31. document.getElementsByTagName("head")[0].appendChild(snod);
  32. var content = document.querySelector("#content");
  33. if(content){
  34. delAD("#thread_list","LI");
  35. observer = new MutationObserver(function(records){
  36. delAD("#thread_list","LI");
  37. });
  38. option = {
  39. 'childList': true,
  40. 'subtree': true
  41. };
  42. observer.observe(content, option);
  43. }else{
  44. content=document.querySelector(".l_container");
  45. if(content){
  46. delAD("#j_p_postlist","DIV");
  47. observer = new MutationObserver(function(records){
  48. delAD("#j_p_postlist","DIV");
  49. });
  50. option = {
  51. 'childList': true,
  52. 'subtree': true
  53. };
  54. observer.observe(content, option);
  55. }else{
  56. content=document.querySelector(".post_list");
  57. if(content){
  58. delAD(".threads_list","LI");
  59. observer = new MutationObserver(function(records){
  60. delAD(".threads_list","LI");
  61. });
  62. option = {
  63. 'childList': true,
  64. 'subtree': true
  65. };
  66. observer.observe(content, option);
  67. }
  68. }
  69. }
  70.  
  71. function delAD(a,b){
  72. var threadList = document.querySelector(a+">"+a),i;
  73. if(!threadList) threadList = document.querySelector(a);
  74. if(!threadList) return;
  75. var delList = [];
  76. for(i=0;i<threadList.childNodes.length;i++){
  77. let thread = threadList.childNodes[i];
  78. if(thread.tagName == "STYLE"){
  79. delList.push(thread);
  80. var previousSibling = thread.previousSibling;
  81. previousSibling = previousSibling.tagName == b?previousSibling:previousSibling.previousSibling;
  82. if(previousSibling.innerHTML.indexOf("广告") != -1)
  83. delList.push(previousSibling);
  84. }else{
  85. if(thread.getAttribute && thread.getAttribute("data-field")){
  86. var tpointTagType=thread.querySelector(".tpoint-tag-type");
  87. if(tpointTagType && tpointTagType.innerHTML.indexOf("广告") != -1)delList.push(thread);
  88. let tdata=JSON.parse(thread.getAttribute("data-field")),pContent=thread.querySelector(".p_content_fix");
  89. if(tdata.content && tdata.content.pb_tpoint && tdata.content.pb_tpoint.is_tpoint==1 && pContent)pContent.classList.remove("p_content_fix");
  90. }else{
  91. if(thread.classList && thread.classList.length==2){
  92. delList.push(thread);
  93. }
  94. }
  95. }
  96. }
  97. for(i=0;i<delList.length;i++){
  98. let del = delList[i];
  99. if(del.parentNode)
  100. del.parentNode.removeChild(del);
  101. }
  102. var easyAD, easyADs=document.querySelectorAll("span.label_text");
  103. for(i=0;i<easyADs.length;i++){
  104. easyAD = easyADs[i];
  105. if(easyAD.innerHTML=="广告" && easyAD.parentNode && easyAD.parentNode.parentNode){
  106. easyAD.parentNode.parentNode.removeChild(easyAD.parentNode);
  107. }
  108. }
  109. easyADs=document.querySelectorAll("span.ti_time");
  110. for(i=0;i<easyADs.length;i++){
  111. easyAD = easyADs[i];
  112. if(easyAD.innerHTML=="广告" && easyAD.parentNode && easyAD.parentNode.parentNode && easyAD.parentNode.parentNode.parentNode){
  113. easyAD.parentNode.parentNode.parentNode.removeChild(easyAD.parentNode.parentNode);
  114. }
  115. }
  116. }
  117. })();