main.js: store captcha mode

This commit is contained in:
Zankaria 2025-02-08 21:30:08 +01:00
parent d48ba6113a
commit 262e8971bd

View file

@ -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.