贴吧广告清理

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

当前为 2017-02-01 提交的版本,查看 最新版本

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