From 262e8971bdda56e82b557ffef72adff61921a479 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 8 Feb 2025 21:30:08 +0100 Subject: [PATCH] main.js: store captcha mode --- templates/main.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/templates/main.js b/templates/main.js index 574a3611..c4c71bc3 100755 --- a/templates/main.js +++ b/templates/main.js @@ -357,6 +357,8 @@ function onCaptchaLoad(renderer) { } {% if config.dynamic_captcha %} // If dynamic captcha +var captchaMode = 'dynamic'; + function isDynamicCaptchaEnabled() { let cookie = getCookie('captcha-required'); return cookie === '1'; @@ -370,8 +372,15 @@ function initCaptcha() { } } } +{% else %} +var captchaMode = 'static'; {% endif %} // End if dynamic captcha {% else %} // Else if any captcha +var captchaMode = 'none'; + +function isDynamicCaptchaEnabled() { + return false; +} // No-op for `init()`. function initCaptcha() {} {% endif %} // End if any captcha @@ -427,9 +436,11 @@ function doPost(form) { saved[document.location] = form.elements['body'].value; sessionStorage.body = JSON.stringify(saved); - if (captcha_renderer && postCaptchaId && !captcha_renderer.hasResponse(postCaptchaId)) { - captcha_renderer.execute(postCaptchaId); - return false; + if (captchaMode === 'static' || (captchaMode === 'dynamic' && isDynamicCaptchaEnabled())) { + if (captcha_renderer && postCaptchaId && !captcha_renderer.hasResponse(postCaptchaId)) { + captcha_renderer.execute(postCaptchaId); + return false; + } } // Needs to be delayed by at least 1 frame, otherwise it may reset the form (read captcha) fields before they're sent.