From df8aa1d093067bee6e8918dc7e52dff713b1bef0 Mon Sep 17 00:00:00 2001 From: "D.Yang" Date: Tue, 26 Nov 2024 15:41:14 +0800 Subject: [PATCH] update --- src/components/CheckAdBlocked.svelte | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/CheckAdBlocked.svelte b/src/components/CheckAdBlocked.svelte index dba599bd..837b9ae7 100644 --- a/src/components/CheckAdBlocked.svelte +++ b/src/components/CheckAdBlocked.svelte @@ -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() { @@ -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; } }