贴吧伪装广告清理

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

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

  1. // ==UserScript==
  2. // @name Kill TieBa AD
  3. // @name:zh-CN 贴吧伪装广告清理
  4. // @name:zh-TW 貼吧僞裝廣告清理
  5. // @name:ja 贴吧去广告
  6. // @namespace hoothin
  7. // @version 0.53
  8. // @description Just Kill TieBa AD
  9. // @description:zh-CN 清理AdBlock或uBlock Origin等未能清理掉的百度贴吧列表伪装广告、帖内伪装广告与推荐应用广告
  10. // @description:zh-TW 清理AdBlock或uBlock Origin等未能清理掉的百度貼吧列表偽裝廣告、帖內偽裝廣告與推薦應用廣告
  11. // @description:ja 去除AdBlock或uBlock Origin等未能清理掉的百度贴吧列表伪装广告、帖内伪装广告与推荐应用广告
  12. // @author hoothin
  13. // @include http*://tieba.baidu.com/*
  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{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;}";
  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. let tdata=JSON.parse(thread.getAttribute("data-field"));
  87. if(tdata.content && tdata.content.pb_tpoint && tdata.content.pb_tpoint.is_tpoint==1)delList.push(thread);
  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. })();