Kill TieBa AD

Just Kill TieBa AD

Mint 2017.01.08.. Lásd a legutóbbi verzió

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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         Kill TieBa AD
// @name:zh-CN   贴吧广告清理
// @name:zh-TW   貼吧廣告清理
// @name:ja      贴吧去广告
// @namespace    hoothin
// @version      1.0
// @description        Just Kill TieBa AD
// @description:zh-CN  清理adb等未能清理掉的百度贴吧(tieba.baidu.com)广告
// @description:zh-TW  清理adb等未能清理掉的百度貼吧(tieba.baidu.com)廣告
// @description:ja     去除adb等未能清理掉的百度贴吧(tieba.baidu.com)广告
// @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;} .j_click_stats{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(".l_container");
        if(content){
            delAD("#j_p_postlist","DIV");
            observer = new MutationObserver(function(records){
                delAD("#j_p_postlist","DIV");
            });
            option = {
                'childList': true,
                'subtree': true
            };
            observer.observe(content, option);
        }else{
            content=document.querySelector(".post_list");
            if(content){
                delAD(".threads_list","LI");
                observer = new MutationObserver(function(records){
                    delAD(".threads_list","LI");
                });
                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;
                if(previousSibling.innerHTML.indexOf("广告") != -1)
                    delList.push(previousSibling);
            }else{
                if(thread.getAttribute && thread.getAttribute("data-field")){
                    var tpointTagType=thread.querySelector(".tpoint-tag-type");
                    if(tpointTagType && tpointTagType.innerHTML.indexOf("广告") != -1)delList.push(thread);
                    let tdata=JSON.parse(thread.getAttribute("data-field")),pContent=thread.querySelector(".p_content_fix");
                    if(tdata.content && tdata.content.pb_tpoint && tdata.content.pb_tpoint.is_tpoint==1 && pContent)pContent.classList.remove("p_content_fix");
                }else{
                    if(thread.classList && thread.classList.length==2){
                        delList.push(thread);
                    }
                }
            }
        }
        for(i=0;i<delList.length;i++){
            let del = delList[i];
            if(del.parentNode)
                del.parentNode.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);
            }
        }
        easyADs=document.querySelectorAll("span.ti_time");
        for(i=0;i<easyADs.length;i++){
            easyAD = easyADs[i];
            if(easyAD.innerHTML=="广告" && easyAD.parentNode && easyAD.parentNode.parentNode && easyAD.parentNode.parentNode.parentNode){
                easyAD.parentNode.parentNode.parentNode.removeChild(easyAD.parentNode.parentNode);
            }
        }
    }
})();