贴吧广告清理

清理ADB与ADP未能清理掉的贴吧列表伪装广告、帖内伪装广告与推荐应用广告

ของเมื่อวันที่ 20-10-2016 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         贴吧广告清理
// @namespace    hoothin
// @version      0.1
// @description  清理ADB与ADP未能清理掉的贴吧列表伪装广告、帖内伪装广告与推荐应用广告
// @author       hoothin
// @match        http*://tieba.baidu.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    var tcss = "div.l_post.l_post_bright.j_l_post.clearfix{display: none !important;} .j_encourage_entry{display: none !important;} .encourage_entry{display: none !important;}";
    var snod = document.createElement('style');
    snod.innerHTML = tcss;
    document.getElementsByTagName("head")[0].appendChild(snod);
    var content = document.querySelector("#content");
    if(content){
        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
        var observer = new MutationObserver(function(records){
            delAD();
        });
        var option = {
            'childList': true,
            'subtree': true
        };
        observer.observe(content, option);
    }

    function delAD(){
        var threadList = document.querySelector("#thread_list");
        if(!threadList) return;
        var delList = [];
        for(let thread of threadList.childNodes){
            if(thread.tagName == "STYLE"){
                delList.push(thread);
            }
        }
        for(let del of delList){
            var previousSibling = del.previousSibling;
            previousSibling = previousSibling.tagName == "LI"?previousSibling:previousSibling.previousSibling;
            threadList.removeChild(previousSibling);
            threadList.removeChild(del);
        }
    }
})();