Last active
January 20, 2023 19:42
-
-
Save ravindu9701/d51b90655b1b51fee3ea629716084ddb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function checkForAdBlocker() { | |
let Blocked; | |
async function Request() { | |
try { | |
return fetch( | |
new Request( | |
"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js", { | |
method: 'HEAD', | |
mode: 'no-cors' | |
})) | |
.then(function(response) { | |
// There is no AdBlocker | |
Blocked = false; | |
return Blocked; | |
}).catch(function(e) { | |
// Failed, Because of an AdBlocker | |
Blocked = true; | |
return Blocked; | |
}); | |
} catch (error) { | |
console.log(error); | |
Blocked = true; | |
return Blocked; | |
} | |
} | |
return Blocked !== undefined ? Blocked : await Request(); | |
} | |
const usingBlocker = await checkForAdBlocker(); |
and renaming the function at line 4.
@LCweb-ita
Can you write your final code? Thank you.
How is this script used? there is no readme file
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great trick, but your code throws two errors on firefox:
I solved it using
checkForAdBlocker().then(response => {do-something});
at line 31and renaming the function at line 4.