贴吧广告清理

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

目前為 2016-10-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         贴吧广告清理
// @namespace    hoothin
// @version      0.2
// @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("#thread_list","LI");
        });
        var option = {
            'childList': true,
            'subtree': true
        };
        observer.observe(content, option);
    }else{
        delAD("#j_p_postlist","DIV");
    }

    function delAD(a,b){
        var threadList = document.querySelector(a);
        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 == b?previousSibling:previousSibling.previousSibling;
            threadList.removeChild(previousSibling);
            threadList.removeChild(del);
        }
    }
})();