From 0afbeac7bda1bb66690dc6986038dd9c614fbd0c Mon Sep 17 00:00:00 2001 From: discomrade Date: Mon, 31 Jan 2022 00:19:44 -0100 Subject: [PATCH] Remove captcha JavaScript call for local captchas, add automatic and manual reloading of captchas --- js/ajax.js | 1 + templates/main.js | 13 +++++++++++ templates/post_form.html | 50 +++++++++++++++++++--------------------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/js/ajax.js b/js/ajax.js index 186e927b..d90af383 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -56,6 +56,7 @@ $(window).ready(function() { return xhr; }, success: function(post_response) { + reloadCaptcha() if (post_response.error) { if (post_response.banned) { // You are banned or warned. Must post the form normally so the user can see the ban message. diff --git a/templates/main.js b/templates/main.js index de887510..a4352ee1 100644 --- a/templates/main.js +++ b/templates/main.js @@ -220,6 +220,19 @@ function get_cookie(cookie_name) { return null; } + +function reloadCaptcha() { + // Reload captcha images (date reduces chance of caching) + // If no captcha is enabled, no elements will be found + captchaImgs = document.querySelectorAll('[id=captcha_img]'); + captchaSrc = "{% endverbatim %}{{ config.captcha.provider_get }}{% verbatim %}?mode=get&raw=1&"+Date.now(); + for (var i = 0; i < captchaImgs.length; ++i) + captchaImgs[i].src = captchaSrc; + captchas = document.querySelectorAll('[id=captcha_text]'); + for (var i = 0; i < captchas.length; ++i) + captchas[i].value = ""; +} + function highlightReply(id) { if (typeof window.event != "undefined" && event.which == 2) { // don't highlight on middle click diff --git a/templates/post_form.html b/templates/post_form.html index 343168bb..12286034 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -82,36 +82,34 @@ {% endif %} {% if config.captcha.enabled %} - - - {% trans %}Verification{% endtrans %} - - - - - - - {% elseif config.new_thread_capt %} + + + {% trans %}Verification{% endtrans %} + + + {% if not config.captcha.local %}{% endif %} + + + {% elseif config.new_thread_capt %} {% if not id %} - - {% trans %}Verification{% endtrans %} - - - - {% endif %} + + {% endif %} {% endif %} {% if config.user_flag %}