wmcmurray / just-detect-adblock

It's FuckAdBlock with a minimalist API.
https://wmcmurray.github.io/just-detect-adblock/
84 stars 14 forks source link

Feature not working. #3

Closed Psoz closed 4 years ago

Psoz commented 4 years ago

I believe that this feature stop working. I'm trying to figure out, and maybe help with a Merge request.

Any help you can give, is a plus.

Thanks

guanzo commented 4 years ago

Stopped working for me too, but I can't remember exactly when. Probably around chrome 85/86?

EDIT: @Psoz. Got it working again! Tested on Chrome 86 and Firefox 81, with uBlock, Ghostery, Adblock Ultimate.

All I did was update the bait's CSS classes.

from: pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links to: text-ad ad-text adSense adBlock adContent adBanner

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))

// Modified from https://github.com/wmcmurray/just-detect-adblock
// Detects: uBlock, Adblock, Adblock Plus, AdBlocker Ultimate, Ghostery,
export async function isAdblockDetected () {
    let detected = false

    // create the bait
    const bait = document.createElement('div')
    bait.setAttribute('class', `text-ad ad-text adSense adBlock adContent adBanner`)
    bait.setAttribute('style', `width: 1px ! important; height: 1px !important;
        position: absolute !important; left: -10000px !important;
        top: -1000px !important;`)
    document.body.appendChild(bait)

    // Give time for extensions to block.
    await sleep(100)

    // Check if the bait has been affected by an adblocker.
    if (window.document.body.getAttribute('abp') !== null ||
        bait.offsetParent === null ||
        bait.offsetHeight === 0 ||
        bait.offsetLeft === 0 ||
        bait.offsetTop === 0 ||
        bait.offsetWidth === 0 ||
        bait.clientHeight === 0 ||
        bait.clientWidth === 0) {
        detected = true
    } else if (window.getComputedStyle !== undefined) {
        const baitTemp = window.getComputedStyle(bait, null)
        if (baitTemp && (baitTemp.getPropertyValue('display') === 'none' ||
            baitTemp.getPropertyValue('visibility') === 'hidden')) {
            detected = true
        }
    }

    // Destroy the bait.
    document.body.removeChild(bait)

    return detected
}

Screenshot of the blocked bait, you can see the huge CSS selector on the right matches the bait CSS classes. detect-adblock

wmcmurray commented 4 years ago

Thanks for your investigation @guanzo !

I implemented your findings in this commit, it should be fixed and available in the latest release v1.1.0 ! ( if I did not mess up something 🤞🏻 I haven't played with npm packages for years 😬 ! )