main.js: refactor captcha parameters to be managed in JS

This commit is contained in:
Zankaria 2024-08-04 01:16:51 +02:00
parent 584fac7caa
commit 1b3b8cb9b6
6 changed files with 29 additions and 17 deletions

View file

@ -255,10 +255,28 @@ function getCaptchaPubKey() {
{% endif %}
}
// Wrapper function to be called from thread.html
window.onCaptchaLoadTurnstile_post_reply = function() {
onCaptchaLoadTurnstile('post-reply');
}
// Wrapper function to be called from index.html and catalog.html
window.onCaptchaLoadTurnstile_post_thread = function() {
onCaptchaLoadTurnstile('post-thread');
}
// Should be called by the captcha API when it's ready. Ugly I know... D:
window.onCaptchaLoadTurnstile = function() {
// Do not actually pass any parameters, as those should already be included in the HTML node.
let widgetId = turnstile.render('captcha-container', {});
function onCaptchaLoadTurnstile(action) {
let pub_key = getCaptchaPubKey();
if (!pub_key) {
console.error("Missing public captcha key!");
return;
}
let widgetId = turnstile.render('captcha-container', {
sitekey: pub_key,
action: action,
});
if (widgetId === undefined) {
console.error('Could not render Turnstile captcha!');
return;
@ -271,12 +289,6 @@ window.onCaptchaLoadTurnstile = function() {
function initDynamicCaptcha() {
if (isDynamicCaptchaEnabled()) {
let pub_key = getCaptchaPubKey();
if (!pub_key) {
console.error("Missing public captcha key!");
return;
}
let captcha_hook = document.getElementById('captcha');
captcha_hook.style = "";
}