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;
},
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.

13
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

50
templates/post_form.html

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

Loading…
Cancel
Save