Kill TieBa AD

Just Kill TieBa AD

当前为 2016-10-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Kill TieBa AD
  3. // @name:zh 贴吧伪装广告清理
  4. // @namespace hoothin
  5. // @version 0.4
  6. // @description Just Kill TieBa AD
  7. // @description:zh 清理ADB与ADP未能清理掉的百度贴吧列表伪装广告、帖内伪装广告与推荐应用广告
  8. // @author hoothin
  9. // @include http*://tieba.baidu.com/*
  10. // @grant none
  11. // @run-at document-body
  12. // @supportURL http://www.hoothin.com
  13. // @license MIT License
  14. // @compatible chrome
  15. // @compatible firefox
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20. var observer, option;
  21. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  22. var tcss = ".j_encourage_entry{display: none !important;} .encourage_entry{display: none !important;}";
  23. var snod = document.createElement('style');
  24. snod.innerHTML = tcss;
  25. document.getElementsByTagName("head")[0].appendChild(snod);
  26. var content = document.querySelector("#content");
  27. if(content){
  28. observer = new MutationObserver(function(records){
  29. delAD("#thread_list","LI");
  30. });
  31. option = {
  32. 'childList': true,
  33. 'subtree': true
  34. };
  35. observer.observe(content, option);
  36. }else{
  37. content=document.querySelector(".content");
  38. if(!content)return;
  39. observer = new MutationObserver(function(records){
  40. delAD("#j_p_postlist","DIV");
  41. });
  42. option = {
  43. 'childList': true,
  44. 'subtree': true
  45. };
  46. observer.observe(content, option);
  47. }
  48.  
  49. function delAD(a,b){
  50. var threadList = document.querySelector(a);
  51. if(!threadList) return;
  52. var delList = [];
  53. for(let thread of threadList.childNodes){
  54. if(thread.tagName == "STYLE"){
  55. delList.push(thread);
  56. var previousSibling = thread.previousSibling;
  57. previousSibling = previousSibling.tagName == b?previousSibling:previousSibling.previousSibling;
  58. delList.push(previousSibling);
  59. }else if(thread.getAttribute && thread.getAttribute("data-isautoreply")){
  60. delList.push(thread);
  61. }
  62. }
  63. for(let del of delList){
  64. threadList.removeChild(del);
  65. }
  66. }
  67. })();