From 1b3b8cb9b698c78a61cd36dc95221c9911cdaabb Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sun, 4 Aug 2024 01:16:51 +0200 Subject: [PATCH] main.js: refactor captcha parameters to be managed in JS --- templates/captcha_script.html | 2 +- templates/index.html | 4 ++-- templates/main.js | 30 +++++++++++++++++++-------- templates/post_form.html | 2 +- templates/themes/catalog/catalog.html | 4 ++-- templates/thread.html | 4 ++-- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/templates/captcha_script.html b/templates/captcha_script.html index 2573682b..a511d51e 100644 --- a/templates/captcha_script.html +++ b/templates/captcha_script.html @@ -1,3 +1,3 @@ {% if config.turnstile %} - + {% endif %} diff --git a/templates/index.html b/templates/index.html index 2fda9773..f5b64c96 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,7 +13,7 @@ active_page = "ukko"; {% endif %} - {% include 'captcha_script.html' %} + {{ include('captcha_script.html', { form_action_type: 'post_thread' }) }} {% include 'header.html' %} {% set page_num %}{% for page in pages %}{% if page.selected %}{% if page.num != 1 %}{{ page.num }}{% endif %}{% endif %}{% endfor %}{% endset %} @@ -59,7 +59,7 @@ {{ config.ad.top }} {% if not no_post_form %} - {{ include('post_form.html', {form_action_type: 'post-thread'}) }} + {% include 'post_form.html' %} {% else %} {% include 'boardlist.html' %} {% endif %} diff --git a/templates/main.js b/templates/main.js index 9369353c..938320dd 100755 --- a/templates/main.js +++ b/templates/main.js @@ -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 = ""; } diff --git a/templates/post_form.html b/templates/post_form.html index 6c5a6205..220902e6 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -117,7 +117,7 @@ {{ antibot.html() }} -
+
{{ antibot.html() }} diff --git a/templates/themes/catalog/catalog.html b/templates/themes/catalog/catalog.html index 44204e48..a9bee317 100644 --- a/templates/themes/catalog/catalog.html +++ b/templates/themes/catalog/catalog.html @@ -9,7 +9,7 @@ , board_name = "{{ board.uri }}" , is_overboard = "{{ is_overboard }}"; - {% include 'captcha_script.html' %} + {{ include('captcha_script.html', { form_action_type: 'post_thread' }) }} {{ settings.title }} ( /{{ board.title|e }}/ ) {% include 'header.html' %} @@ -29,7 +29,7 @@
[ {% trans 'Create new thread' %} ]
- {{ include('post_form.html', {form_action_type: 'post-thread'}) }} + {% include 'post_form.html' %}
{% endif %} diff --git a/templates/thread.html b/templates/thread.html index 6888f56f..9d034a2b 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -8,7 +8,7 @@ , board_name = "{{ board.uri }}" , thread_id = "{{ thread.id }}"; - {% include 'captcha_script.html' %} + {{ include('captcha_script.html', { form_action_type: 'post_reply' }) }} {% include 'header.html' %} @@ -54,7 +54,7 @@ {{ config.ad.top }} - {{ include('post_form.html', {form_action_type: 'post-reply'}) }} + {% include 'post_form.html' %} {% if config.global_message %}
{{ config.global_message }}
{% endif %}