Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyang0507 committed Nov 26, 2024
1 parent 7107c05 commit df8aa1d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/components/CheckAdBlocked.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,22 @@
}
function checkAdScriptBanned(scriptUrl) {
return fetch(scriptUrl)
.then(response => !response.ok)
.catch(() => true);
try {
return fetch(scriptUrl, {
method: 'HEAD',
mode: 'no-cors',
redirect: 'follow'
})
.then(response => {
if (!response.ok || response.type === 'error' || response.status === 0) {
return true;
}
return false;
})
.catch(() => true);
} catch (error) {
return Promise.resolve(true);
}
}
async function checkAdBlocker() {
Expand All @@ -33,14 +46,8 @@
return;
}
// const isAdBlockDetected = await checkAdBlockInit();
// if (isAdBlockDetected) {
// adBlockDetected = true;
// return;
// }
const isScriptBanned = await checkAdScriptBanned(getRandomUrl());
if (isScriptBanned) {
if (checkAdBlockInit() || isScriptBanned) {
adBlockDetected = true;
}
}
Expand Down

0 comments on commit df8aa1d

Please sign in to comment.