貼吧僞裝廣告清理

清理ADB或UBO等未能清理掉的百度貼吧列表偽裝廣告、帖內偽裝廣告與推薦應用廣告

目前為 2016-11-13 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Kill TieBa AD
// @name:zh-CN   贴吧伪装广告清理
// @name:zh-TW   貼吧僞裝廣告清理
// @namespace    hoothin
// @version      0.50
// @description        Just Kill TieBa AD
// @description:zh-CN  清理ADB或UBO等未能清理掉的百度贴吧列表伪装广告、帖内伪装广告与推荐应用广告
// @description:zh-TW  清理ADB或UBO等未能清理掉的百度貼吧列表偽裝廣告、帖內偽裝廣告與推薦應用廣告
// @author       hoothin
// @include      http*://tieba.baidu.com/*
// @grant        none
// @run-at       document-body
// @supportURL   http://www.hoothin.com
// @license     MIT License
// @compatible        chrome
// @compatible        firefox
// @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_donations&[email protected]&item_name=Greasy+Fork+donation
// @contributionAmount 1
// ==/UserScript==

(function() {
    'use strict';
    var observer, option;
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
    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;}";
    var snod = document.createElement('style');
    snod.innerHTML = tcss;
    document.getElementsByTagName("head")[0].appendChild(snod);
    var content = document.querySelector("#content");
    if(content){
        delAD("#thread_list","LI");
        observer = new MutationObserver(function(records){
            delAD("#thread_list","LI");
        });
        option = {
            'childList': true,
            'subtree': true
        };
        observer.observe(content, option);
    }else{
        content=document.querySelector(".content");
        if(!content)return;
        delAD("#j_p_postlist","DIV");
        observer = new MutationObserver(function(records){
            delAD("#j_p_postlist","DIV");
        });
        option = {
            'childList': true,
            'subtree': true
        };
        observer.observe(content, option);
    }

    function delAD(a,b){
        var threadList = document.querySelector(a+">"+a),i;
        if(!threadList) threadList = document.querySelector(a);
        if(!threadList) return;
        var delList = [];
        for(i=0;i<threadList.childNodes.length;i++){
            let thread = threadList.childNodes[i];
            if(thread.tagName == "STYLE"){
                delList.push(thread);
                var previousSibling = thread.previousSibling;
                previousSibling = previousSibling.tagName == b?previousSibling:previousSibling.previousSibling;
                delList.push(previousSibling);
            }else{
                if(thread.getAttribute && thread.getAttribute("data-field")){
                    let tdata=JSON.parse(thread.getAttribute("data-field"));
                    if(tdata.content && tdata.content.pb_tpoint && tdata.content.pb_tpoint.is_tpoint==1)delList.push(thread);
                }
            }
        }
        for(i=0;i<delList.length;i++){
            let del = delList[i];
            threadList.removeChild(del);
        }
        var easyAD, easyADs=document.querySelectorAll("span.label_text");
        for(i=0;i<easyADs.length;i++){
            easyAD = easyADs[i];
            if(easyAD.innerHTML=="广告" && easyAD.parentNode && easyAD.parentNode.parentNode){
                easyAD.parentNode.parentNode.removeChild(easyAD.parentNode);
            }
        }
    }
})();