From 7c5a5e494cc87e5a9457d3ec2888cf004bc9737c Mon Sep 17 00:00:00 2001 From: overflowerror Date: Fri, 16 Aug 2024 23:14:58 +0200 Subject: [PATCH] add direct success callback --- public/index.html | 2 +- src/main.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/public/index.html b/public/index.html index 92d9349..4cfdae5 100644 --- a/public/index.html +++ b/public/index.html @@ -5,6 +5,6 @@ -
+
diff --git a/src/main.ts b/src/main.ts index ec36ba9..8efa8bf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -37,14 +37,11 @@ const toggleChecked = (checkbox: Element) => const toggleLoading = (checkbox: Element) => checkbox.classList.toggle(CLASS_LOADING); -function prepareChallengeExecution(challenge: Challenge): () => Promise { +function prepareChallengeExecution(challenge: Challenge, callback: (response: string) => void): () => Promise { return async function() { - console.log("Calculating..."); - toggleLoading(this); - const response = await findHashWithPrefix(challenge.algo, challenge.prefixBits, challenge.input); - console.log("Challenge Response: " + response); + callback(await findHashWithPrefix(challenge.algo, challenge.prefixBits, challenge.input)); toggleLoading(this); toggleChecked(this); @@ -57,6 +54,8 @@ const prepareCaptcha = async (captcha: Element) => { throw "No challenge URL found."; } + let successCallback = captcha.getAttribute("data-success-callback"); + const checkbox = initCaptchaContentAndGetCheckbox(captcha); const challengeResponse = await fetch(challengeUrl); @@ -68,7 +67,9 @@ const prepareCaptcha = async (captcha: Element) => { toggleLoading(checkbox); - checkbox.addEventListener("click", prepareChallengeExecution(challenge)); + checkbox.addEventListener("click", prepareChallengeExecution(challenge, response => { + if (successCallback) eval(successCallback)(response); + })); } window.addEventListener("load", () =>