监测广告位是否被 AdBlock 拦截

AdBlock JavaScript About 15,281 words

判断样式

当页面加载完成后,判断广告位元素样式display是否为none,即可。

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="testAd" class="google-ad">这里是一个广告位</div>
this is html
</body>
<script>
    function detectAdBlock() {
        let adElement = document.getElementById("testAd");
        return "none" === window.getComputedStyle(adElement).display
    }

    window.onload = function () {
        console.log(detectAdBlock());
    }
</script>
</html>

AdBlock拦截样式

#bottombanner, #gg1, #haoetv, #kfivtwin, .a_mu, .a_pr, .a_pt, .con_ad, .container > .ads, .ggbox, .widget_ui_ads, .wp.a_t, a > img[src*=".sinaimg."][src$=".gif"][style*="width:960"], a > img[width="960"][src*=".alicdn.com/"], a > img[width="960"][src*=".sinaimg."], a > img[width="980"][src*=".sinaimg."], a[href*=".umeng.com"]:not([href="http://www.umeng.com/"]) > img, a[href^="http://www.upupoo.com"], div[class^="ADTOPLB_"], .a_cn, .a_fr, .a_p, .gg1000, a[href*="/cpro."], a[href*="/cpro/"], div[id^="_"] > iframe[scrolling="no"][src^="http"][width][height][frameborder="0"], #AdBar, #AdSense1, #AdSense2, #Adbanner, #BannerAd, #ContentAd1, #DFP_in_article_mpu, #DFP_top_leaderboard, #FooterAd, #GoogleRelatedAds, #HeaderAd, #SidebarAd, #Tadspacehead, #ad-300x250, #ad-728, #ad-aside-1, #ad-banner, #ad-bottom, #ad-container, #ad-flex-top, #ad-frame, #ad-header, #ad-horizontal, #ad-horizontal-header, #ad-lead, #ad-leaderboard, #ad-rectangle, #ad-right-top, #ad-secondary-sidebar-1, #ad-side, #ad-sidebar1, #ad-sidebar2, #ad-skyscraper, #ad-slot-2, #ad-text, #ad-top, #ad-top-slot, #ad-top-wrap, #ad-unit, #ad728, #adBanner, #adBottom, #adContent, #adFooter, #adFrame, #adIframe, #adSet, #adSquare, #adTop, #adUnit, #ad_02, #ad_1, #ad_2, #ad_4, #ad_5, #ad_6, #ad_7, #ad_728x90, #ad_8, #ad_big, #ad_bottom, #ad_box, #ad_content, #ad_footer, #ad_global_above_footer, #ad_header, #ad_home, #ad_left, #ad_main, #ad_main_top, #ad_rec_01, #ad_right, #ad_small, #ad_text:not(textarea), #ad_top, #ad_website_top, #ad_zone1, #adbanner, #adbar, #adblock1, #adblock2, #adbody, #adbottom, #adbox, #adbox2, #adbox_right, #adbrite, #adcontainer1, #adcontainer2, #adcontainer3, #adcontent, #adimg, #adl_300x250, #adleft, #admputop, #adright, #ads-1, #ads-5, #ads-container, #ads-header, #ads-leaderboard, #adsRight, #ads_box, #ads_header, #ads_left, #adsctl00_AdsHome2, #adsense, #adslider, #adslot1, #adslot2, #adslot3, #adsquare, #adswidget1-quick-adsense, #adswidget2-quick-adsense-reloaded-2, #adtop, #adunit, #advWrapper, #adv_728x90, #adver2, #adver5, #advert-placeholder-post-content-image-1, #advert-right, #advert_1, #advertise, #advertisement-detail1, #advertisement-detail2, #advertiserReports, #advertising_300, #advertising_728, #advertorial, #adwrapper, #article-ad, #article-footer-sponsors, #atwAdFrame4, #b5ad300, #banner600, #banner728, #banner_ad, #base-advertising-top, #bbccom_mpu, #block-dfp-billboard-leaderboard, #block-dfp-mpu-1, #block-dfp-mpu-2, #block-sidebarad1, #bottom-ad, #bottom-ads, #bottom-ads-container, #bottomAd, #bottomBannerAd, #bottomDDAd, #bottomad, #boxad, #bsap_aplink, #btmsponsoredcontent, #buysellads, #carbonads-container, #center-ad, #cmn_ad_tag_head, #container_ad, #contentad-adsense-homepage-1, #contentad-adsense-homepage-2, #contentad-story-bottom-1, #contentad-top-adsense-1, #contentad-topbanner-1, #crt-adblock-a, #crt-adblock-b, #cubeAd, #dfp-ad-1, #dfp-ad-2, #dfp-ad-billboard_leaderboard, #dfp-ad-billboard_leaderboard-wrapper, #dfp-ad-mpu_1, #dfp-ad-mpu_1-wrapper, #dfp-ad-mpu_2, #dfp-ad-mpu_2-wrapper, #div-insticator-ad-1, #div-insticator-ad-2, #divAd, #divTopAd, #extraAdsBlock, #footAd, #footer-ad, #footer-ads, #footer_ad, #footerad, #footeradvert, #frnAdSky, #frnBannerAd, #gAds, #google-ad, #google-ads, #google-adsense, #googleAd, #google_ad, #google_ads, #googlead, #googlead1, #googleadsense, #gpt2_ads_widget-6, #halfPageAd, #head_ad, #header-ad, #header-ad-container, #header-ads, #headerAd, #header_ads, #headerad, #index_ad, #inline-ad, #insticator-container, #leftad, #leftrail_dynamic_ad_wrapper, #liste_top_ads_wrapper, #mainAd, #mod-ad-gemini-rm-1, #mpu2, #mvp-post-bot-ad, #my-adsLREC4-base, #p-googleadsense, #perm_ad, #quads-ad1_widget, #quads-ad2, #quads-ad2_widget, #quads-ad4, #reklama, #right-ad, #right-ads-rail, #rightAd300x250, #rightAd300x250Lower, #rightAds, #rightad, #rightsideadstop, #search_ad, #sgAdScGp160x600, #showAd, #sidebar-ad, #sidebar-advertisement, #single-ad, #slider-ad, #source-ad-native-sticky-wrapper, #sponsorBar, #sponsored-links, #sponsored_content, #sponsored_link, #sponsored_link_bottom, #sponsored_links, #stickyad, #td-applet-ads_container, #top-ad, #top-banner-ad, #topAd, #topAd728x90, #topAds, #top_ad, #topad, #towerad, #wp_pro_ad_system_ad_zone, #yandex_ad, .ADBox, .AD_area, .ADbox, .Ad-Container, .Ad-label, .Ad-leaderboard, .AdBorder, .AdBox, .AdContainer-Sidebar, .AdSense, .AdsRec, .Ads_4, .BannerAd, .GalleryViewerAdSuppress, .GeminiAdItem, .MediumRectangleAdPanel, .NGOLocalFooterAd, .PremiumObitAdBar, .RelatedAds, .RightAdWrapper, .SidekickItem-Ads, .SponsoredLinks, .SponsoredResults, .SummaryPage-HeaderAd, .TopAd, .TopAdContainer, .WP_Widget_Ad_manager, ._SummaryPageHeaderAdView, ._SummaryPageSidebarStickyAdView, ._ap_adrecover_ad, ._has-ads, .a-ad, .ad--desktop, .ad-1, .ad-160, .ad-160-600, .ad-160-above, .ad-160x600, .ad-2, .ad-3, .ad-300-250, .ad-300x250, .ad-300x600, .ad-4, .ad-5, .ad-728-90, .ad-728x90, .ad-Leaderboard, .ad-alsorectangle, .ad-atf, .ad-atf-medRect, .ad-b, .ad-background, .ad-banner, .ad-banner-container, .ad-banner-image, .ad-banner-top, .ad-bar, .ad-below, .ad-big, .ad-billboard, .ad-block, .ad-bottom, .ad-break, .ad-card, .ad-cell, .ad-center, .ad-centered, .ad-codes, .ad-column, .ad-container--featured_videos, .ad-container--leaderboard, .ad-container-300x250, .ad-container-top, .ad-content, .ad-custom-size, .ad-desktop, .ad-disclaimer, .ad-div, .ad-entity-container, .ad-ex, .ad-fadeup, .ad-footer, .ad-frame, .ad-google, .ad-gpt, .ad-hdr, .ad-head, .ad-header, .ad-header-container, .ad-holder, .ad-horizontal, .ad-icon, .ad-img, .ad-in-post, .ad-inline, .ad-inner, .ad-inserter, .ad-inserter-widget, .ad-item, .ad-label, .ad-leader, .ad-leaderboard, .ad-leaderboard-top, .ad-left, .ad-line, .ad-link, .ad-location, .ad-marker, .ad-med-rect, .ad-medium-two, .ad-microsites, .ad-midleader, .ad-mobile, .ad-mobile-banner, .ad-mpu, .ad-mrec, .ad-one, .ad-panel, .ad-placeholder, .ad-placement, .ad-position, .ad-right, .ad-root, .ad-row, .ad-s, .ad-s-rendered, .ad-section, .ad-side, .ad-sidebar, .ad-size-leaderboard, .ad-size-medium-rectangle-flex, .ad-sky, .ad-skyscraper, .ad-slider, .ad-slot, .ad-slot--top-banner-ad, .ad-slot-container, .ad-slot-sidebar-b, .ad-source, .ad-space, .ad-spacer, .ad-spot, .ad-square, .ad-stack, .ad-sticky, .ad-sticky-container, .ad-tag, .ad-text, .ad-title, .ad-tl1, .ad-top, .ad-top-banner, .ad-tower, .ad-unit, .ad-unit-container, .ad-unit-label, .ad-unit-wrapper, .ad-vertical, .ad-wide, .ad-widget, .ad-wireframe-wrapper, .ad-with-header-wrapper, .ad-wrap, .ad-wrapper, .ad-zone, .ad.inner, .ad.module, .ad01, .ad300, .ad300x250, .ad300x600, .ad350, .ad728, .ad728x90, .ad960, .adActive, .adArea, .adBanner, .adBlock, .adBox, .adColumn, .adContent, .adDiv, .adFrame, .adFull, .adHeader, .adLabel, .adLeft, .adLink, .adLoaded, .adOuterContainer, .adRight, .adSense, .adSlot, .adSpace, .adTop, .adUnit, .adWrap, .adWrapper, .ad_1, .ad_250, .ad_300, .ad_300_250, .ad_300_600, .ad_468x60, .ad_728_90, .ad_960, .ad__container, .ad__wrapper-element, .ad_adInfo, .ad_area, .ad_banner, .ad_block, .ad_bottom, .ad_box, .ad_boxright1, .ad_center, .ad_container, .ad_content, .ad_crown, .ad_default, .ad_desktop, .ad_footer, .ad_fullwidth, .ad_global_header, .ad_halfpage, .ad_img, .ad_l, .ad_label, .ad_label_method, .ad_leaderboard_atf, .ad_main, .ad_native, .ad_native_xrail, .ad_note, .ad_placeholder, .ad_placement, .ad_r, .ad_slug_table, .ad_space, .ad_spot, .ad_text, .ad_title, .ad_top, .ad_unit, .ad_wrap, .ad_wrapper, .ad_xrail, .ad_xrail_top, .ad_zone, .adarea, .adbar, .adbottom, .adbox-rectangle, .adbox-wrapper, .adcenter, .adchoices, .adchoices-link, .adclass, .adcode, .adcont, .add300, .addarea, .addisclaimer, .addiv, .adframe, .adinjwidget, .adlateral, .adlink, .adlist, .adloaded, .admarker, .admz, .adops, .adpic, .adplace, .adrect, .adright, .adrotate_widgets, .ads--sidebar, .ads--top, .ads-bg, .ads-block, .ads-bottom, .ads-box, .ads-content, .ads-footer, .ads-in-content, .ads-label, .ads-large, .ads-left, .ads-post, .ads-right, .ads-sidebar, .ads-to-hide, .ads-top, .ads-widget, .ads-wrapper, .ads1, .ads160-600, .ads160_600-widget, .adsBox, .ads_300, .ads__sidebar, .ads_ad_box, .ads_ad_box2, .ads_by, .ads_code, .ads_container, .ads_div, .ads_google, .ads_header, .ads_label, .ads_top, .adsanity-group, .adsbillboard, .adsblock, .adsbox, .adsbygoogle, .adsense-block, .adsense_single, .adsense_wrapper, .adside, .adsitem, .adslisting, .adslisting2, .adslistingz, .adsload, .adslot, .adslot_1, .adslot_2, .adslot_3, .adspace, .adspace-widget, .adspacer, .adspot, .adspot1, .adsrecnode, .adssidebar2, .adstop, .adswidget, .adtag, .adtester-container, .adtop, .adunit, .adunit-middle, .adunitContainer, .adv-border, .adv-container, .adv-label, .adv-list, .adv-slide-block-wrapper, .adv_bg, .adv_img, .adv_left, .advads-widget, .advads_widget, .advert-block, .advert-box, .advert-container, .advert-content, .advert-leaderboard, .advert-mpu, .advert-text, .advert1, .advert2, .advertCont, .advertContainer, .advert_top, .advertisement-block, .advertisement-box, .advertisement-container, .advertisement-text, .advertisement-top, .advertisementBanner, .advertisement_above_footer, .advertisement_box, .advertising-block, .advertising-content, .adverts, .adwords, .adwrap-widget, .afs_ads, .after-post-ad, .afw_ad, .article-ad-bottom, .article-adv-right-sideBar, .article-view__footer-ad, .article_ad, .aside-ad, .atf-ad-medRect, .b_ads, .banner-300x250, .banner-728x90, .banner-ad, .banner160x600, .banner_160x600, .banner_728x90, .banner_ad, .bannerad, .bannervcms, .bbccom_advert, .bean-advertisment, .below-next-nativeads, .betteradscontainer, .big-ad, .big-ads, .bigbox-ad, .billboard-ad, .billboard-ads, .block-ads, .block-dfp, .block1--ads, .blogAd, .bomAd, .bottom-ad, .bottom-ad-container, .bottom-ads, .bottom-main-adsense, .bottomAd, .bottomBannerAd, .bottom_ad, .bottom_ads, .bottomad, .bottomads, .box-ad, .box-advert, .box-recommend-ad, .breaker-ad, .browse-banner_ad, .bsa_it_ad, .bsac, .bsac-container, .bullet-sponsored-links-gray, .bunyad-ad, .bxad, .c-ad, .can_ad_slug, .carbon_ads, .card--article-ad, .center-ad, .chitikaAdBlock, .cm-ad, .cmAd, .cns-ads-stage, .column-ad, .contained-ad-container, .contained-ad-shaft, .contained-ad-wrapper, .container_ad, .content-ad, .content-ads, .content-list__ad-label, .contentAds, .content_ad, .content_ads, .contentad, .cta-ad, .cube-ad, .custom-ads, .dcmads, .desktop-ad, .desktop-ads, .desktop_ad, .detail-ad, .dfp-ad, .dfp-slot, .dfp-tag-wrapper, .dfp-wrapper, .dfp_ad, .dfp_slot, .dianomi-ad, .dikr-responsive-ads-slot, .display-ad, .div_adv300, .dmRosMBAdBox, .download-ad, .downloadad, .earAdv, .easyAdsBox, .etad, .ezAdsense, .ezo_ad, .ezoic-ad, .featured-ads, .feed-ad, .feed-s-update--is-sponsored, .feed-shared-post-meta--is-sponsored, .feed-shared-update--is-sponsored, .first-ad, .following-ad, .following-ad-container, .footer-ad, .footer-advert, .footer-leaderboard-ad, .footerad, .fortune-ad-tag__leaderboard, .fp-ads, .full-ad, .full-width-ad, .g1-advertisement, .g_ad, .general_banner_ad, .generic-ad-module, .google-ad, .google-ad-iframe, .google-ads, .googleAd, .googleAds, .google_ad, .google_ads, .google_ads_v3, .googlead, .gpt-ad, .headad, .header-ad, .header-ad-wrapper, .header-top-ad, .headerAd, .header__ad, .header_ad, .headerad, .heatmapthemead_ad_widget, .herald-ad, .hero-ad, .home-ad, .home-ads, .home-top-right-ads, .home_advertisement, .homead, .horizontalAdText, .horizontal_ad, .hp_adv300x250, .hp_advP1, .ht_ad_widget, .iAdserver, .iconads, .iframe-ad, .iframeAd, .img_ad, .imuBox, .in-content-ad, .inline-ad, .inlinead, .innerAds, .internal_ad, .interstitial-ad, .ipsAd, .is-sponsored, .item-container-ad, .iw-leaderboard-ad, .js-ad, .js-ad-hover, .js-ad-slot, .js-ad-static, .js-dfp-ad, .js-native-ad, .js-stream-ad, .js-stream-featured-ad, .js_contained-ad-container, .label-ad, .layout-ad, .lazyadslot, .lbc-ad, .leader-ad, .leaderboard-ad, .leaderboard-ad-container, .leaderboard-ad-module, .leaderboard_ad, .left-ad, .left-ads, .leftAd, .ligatus, .logo-ad, .lower-ad, .lx_ad_title, .m-ad, .m-header-ad, .m-header-ad--slot, .m-in-content-ad, .m-in-content-ad--slot, .m-in-content-ad-row, .main-ad, .mainAd, .main_adv, .mediumRectangleAd, .member-ads, .midAd, .middle-ad, .mmads, .mobads, .mobile-ad, .module-ads, .moduleAdSpot, .mom-ad, .mp-ad, .mpu-ad, .mpu_container, .mvp-ad-label, .mvp-feat1-list-ad, .mvp-widget-ad, .mvp_ad_widget, .myAds, .native-ad, .native-ad-item, .native-leaderboard-ad, .nativeAd, .native_ad, .nav-ad, .newsad, .ob_ads_header, .ob_container .item-container-obpd, .ob_dual_right > .ob_ads_header ~ .odb_div, .oio-banner-zone, .one-ad, .onf-ad, .openx, .overlay-ad, .page-ad, .page_ad, .pagefair-acceptable, .panel-ad, .panel-ad-mr, .partner-overlay-top-ad, .pencil-ad-section, .player-leaderboard-ad-wrapper, .plistaList > .itemLinkPET, .plistaList > .plista_widget_underArticle_item[data-type="pet"], .pm-ad-zone, .post-ad, .post__inarticle-ad-template, .poster-ad-asset-module, .profile-ad-container, .proper-ad-unit, .pubDesk, .pub_300x250, .pub_300x250m, .pub_728x90, .quads-ad1_widget, .quads-ad2, .quads-ad4, .quads-location, .rail-ad, .region-top-ad, .reklam2, .reklama, .reklama1, .responsive-ads, .right-ad, .right-ads, .right-rail-ad, .rightAd, .rightColumnAd, .right_ad, .right_side_ads, .rightad, .rightads, .rmx-ad, .s_ad_160x600, .s_ad_300x250, .sam_ad, .search-ad, .section-ads, .sgAd, .side-ad, .side-ads, .side-ads-container, .side-ads_sticky-group, .sideAd, .sideAdv-wrapper, .side_ad, .sidead, .sidebar-ad, .sidebar-ad-slot, .sidebar-ad-wrapper, .sidebar-ads, .sidebar-advertisement, .sidebarAd, .sidebar_ad_1, .sidebar_ad_2, .sidebar_ad_3, .sidebar_ads, .sidebar_right_ad, .single-ad, .single_ad, .sister-ads, .slide-ad, .sponsor-block, .sponsor-logo, .sponsor-text, .sponsored-content, .sponsored-headlines, .sponsored-inmail, .sponsored-inmail-legacy, .sponsored-link, .sponsored-links, .sponsored_ad, .sponsored_content, .sponsors-box, .sponsorshipbox, .squareAd, .square_ad, .squaread, .sr-in-feed-ads, .standalone-ad-container, .static-ad, .sticky-ad, .sticky-ad-container, .sticky-sidebar-ad, .stickyad, .story-ad-container, .str-300x250-ad, .strawberry-ads, .stream-ad, .td-a-ad, .td-a-rec-id-custom_ad_1, .td-a-rec-id-custom_ad_2, .td-a-rec-id-custom_ad_3, .td-a-rec-id-custom_ad_4, .td-a-rec-id-custom_ad_5, .td-adspot-title, .td-header-ad-wrap, .text-ad, .text-ad-links, .text-ads, .textAd, .text_ad, .text_ads, .textad, .themonic-ad2, .tile-ad, .tmsads, .toolbar-ad, .top-300-ad, .top-ad, .top-ad-container, .top-adv, .top-advert, .top-advertisement {
    display: none !important;
}
Views: 2,188 · Posted: 2020-09-22

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh