Browse Source

Remove captcha JavaScript call for local captchas, add automatic and manual reloading of captchas

main
discomrade 2 years ago
parent
commit
0afbeac7bd
  1. 1
      js/ajax.js
  2. 13
      templates/main.js
  3. 50
      templates/post_form.html

1
js/ajax.js

@ -56,6 +56,7 @@ $(window).ready(function() {
return xhr; return xhr;
}, },
success: function(post_response) { success: function(post_response) {
reloadCaptcha()
if (post_response.error) { if (post_response.error) {
if (post_response.banned) { if (post_response.banned) {
// You are banned or warned. Must post the form normally so the user can see the ban message. // You are banned or warned. Must post the form normally so the user can see the ban message.

13
templates/main.js

@ -220,6 +220,19 @@ function get_cookie(cookie_name) {
return null; 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) { function highlightReply(id) {
if (typeof window.event != "undefined" && event.which == 2) { if (typeof window.event != "undefined" && event.which == 2) {
// don't highlight on middle click // don't highlight on middle click

50
templates/post_form.html

@ -82,36 +82,34 @@
</tr> </tr>
{% endif %} {% endif %}
{% if config.captcha.enabled %} {% if config.captcha.enabled %}
<tr class='captcha'> <tr class='captcha'>
<th> <th>
{% trans %}Verification{% endtrans %} {% trans %}Verification{% endtrans %}
</th> </th>
<td> <td>
<script>load_captcha("{{ config.captcha.provider_get }}", "{{ config.captcha.extra }}");</script> {% if not config.captcha.local %}<script>load_captcha("{{ config.captcha.provider_get }}", "{{ config.captcha.extra }}");</script><noscript>{% endif %}
<noscript> <input id='captcha_text' class='captcha_text' type='text' name='captcha_text' size='32' maxlength='6' autocomplete='off'>
<input class='captcha_text' type='text' name='captcha_text' size='32' maxlength='6' autocomplete='off'> <div class="captcha_html">
<div class="captcha_html"> <img id="captcha_img" src="{{ config.captcha.provider_get }}?mode=get&raw=1" onClick="this.src='{{ config.captcha.provider_get }}?mode=get&raw=1&'+Date.now();document.getElementById('captcha_text').value = '';">
<img src="{{ config.captcha.provider_get }}?mode=get&raw=1"> </div>
</div> {% if not config.captcha.local %}</noscript>{% endif %}
</noscript> </td>
</td> </tr>
</tr> {% elseif config.new_thread_capt %}
{% elseif config.new_thread_capt %}
{% if not id %} {% if not id %}
<tr class='captcha'> <tr class='captcha'>
<th> <th>
{% trans %}Verification{% endtrans %} {% trans %}Verification{% endtrans %}
</th> </th>
<td> <td>
<script>load_captcha("{{ config.captcha.provider_get }}", "{{ config.captcha.extra }}");</script> {% if not config.captcha.local %}<script>load_captcha("{{ config.captcha.provider_get }}", "{{ config.captcha.extra }}");</script><noscript>{% endif %}
<noscript> <input id='captcha_text' class='captcha_text' type='text' name='captcha_text' size='32' maxlength='6' autocomplete='off'>
<input class='captcha_text' type='text' name='captcha_text' size='32' maxlength='6' autocomplete='off'>
<div class="captcha_html"> <div class="captcha_html">
<img src="{{ config.captcha.provider_get }}?mode=get&raw=1"> <img id="captcha_img" src="{{ config.captcha.provider_get }}?mode=get&raw=1" onClick="this.src='{{ config.captcha.provider_get }}?mode=get&raw=1&'+Date.now();document.getElementById('captcha_text').value = '';">
</div> </div>
</noscript> {% if not config.captcha.local %}</noscript>{% endif %}
</td> </td>
</tr> </tr>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if config.user_flag %} {% if config.user_flag %}

Loading…
Cancel
Save