Skip to content

Instantly share code, notes, and snippets.

@ravindu9701
Last active January 20, 2023 19:42
Show Gist options
  • Save ravindu9701/d51b90655b1b51fee3ea629716084ddb to your computer and use it in GitHub Desktop.
Save ravindu9701/d51b90655b1b51fee3ea629716084ddb to your computer and use it in GitHub Desktop.
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();
@dchubad
Copy link

dchubad commented Jan 20, 2023

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