CSDN广告

去除CSDN文章广告

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         CSDN广告
// @namespace    leevsee
// @version      0.1
// @description  去除CSDN文章广告
// @author       Leeves
// @match        http*://blog.csdn.net/**/article/details/**
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
    var observer = new MutationObserver(function(records) {
        clearAD();
    });
    var option = {
        'childList': true,
        'subtree': true
    };
    document.onreadystatechange = function() {
        if(document.readyState == "interactive") {
            observer.observe(document.body, option);
        }
    };

    function clearAD() {

        var mAds = document.querySelectorAll(".pulllog-box,#asideFooter,.meau-gotop-box,.csdn-tracking-statistics.mb8.box-shadow,.bdsharebuttonbox _360_interactive bdshare-button-style0-16,.recommend-item-box.recommend-ad-box,.fourth_column,.right-item _paradigm_S3_csdn_ads_render,#dmp_ad_58"),
            i;
        for(i = 0; i < mAds.length; i++) {
            var mAd = mAds[i];
            mAd.remove();
        }

        var rAds = document.querySelectorAll(".right-item"),j;
        for (j = 0; j < rAds.length; j++) {
            var rAd = rAds[j];
            if(rAd.getAttribute("id")){
                rAd.remove();
            }
        }
    }
    setTimeout(() => {
        clearAD();
    }, 2000);
})();