贴吧伪装广告清理

清理AdBlock或uBlock Origin等未能清理掉的百度贴吧列表伪装广告、帖内伪装广告与推荐应用广告

当前为 2016-12-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Kill TieBa AD
  3. // @name:zh-CN 贴吧伪装广告清理
  4. // @name:zh-TW 貼吧僞裝廣告清理
  5. // @namespace hoothin
  6. // @version 0.52
  7. // @description Just Kill TieBa AD
  8. // @description:zh-CN 清理AdBlock或uBlock Origin等未能清理掉的百度贴吧列表伪装广告、帖内伪装广告与推荐应用广告
  9. // @description:zh-TW 清理AdBlock或uBlock Origin等未能清理掉的百度貼吧列表偽裝廣告、帖內偽裝廣告與推薦應用廣告
  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. let tdata=JSON.parse(thread.getAttribute("data-field"));
  85. if(tdata.content && tdata.content.pb_tpoint && tdata.content.pb_tpoint.is_tpoint==1)delList.push(thread);
  86. }else{
  87. if(thread.classList && thread.classList.length==2){
  88. delList.push(thread);
  89. }
  90. }
  91. }
  92. }
  93. for(i=0;i<delList.length;i++){
  94. let del = delList[i];
  95. threadList.removeChild(del);
  96. }
  97. var easyAD, easyADs=document.querySelectorAll("span.label_text");
  98. for(i=0;i<easyADs.length;i++){
  99. easyAD = easyADs[i];
  100. if(easyAD.innerHTML=="广告" && easyAD.parentNode && easyAD.parentNode.parentNode){
  101. easyAD.parentNode.parentNode.removeChild(easyAD.parentNode);
  102. }
  103. }
  104. easyADs=document.querySelectorAll("span.ti_time");
  105. for(i=0;i<easyADs.length;i++){
  106. easyAD = easyADs[i];
  107. if(easyAD.innerHTML=="广告" && easyAD.parentNode && easyAD.parentNode.parentNode && easyAD.parentNode.parentNode.parentNode){
  108. easyAD.parentNode.parentNode.parentNode.removeChild(easyAD.parentNode.parentNode);
  109. }
  110. }
  111. }
  112. })();