anoncaptcha v0.92 - timeout fix
This commit is contained in:
@@ -3,7 +3,7 @@ AnonCaptcha Addon
|
|||||||
|
|
||||||
Adds a math-based captcha for anonymous commenters to prevent spam.
|
Adds a math-based captcha for anonymous commenters to prevent spam.
|
||||||
|
|
||||||
When enabled, anonymous visitors who wish to leave a comment must solve a simple addition problem (e.g. "What is 12 + 37?").
|
When enabled, anonymous visitors who wish to leave a comment must solve a simple addition problem.
|
||||||
|
|
||||||
Based on Zotlabs hook system.
|
Based on Zotlabs hook system.
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* Name: AnonCaptcha
|
* Name: AnonCaptcha
|
||||||
* Description: Adds a math captcha for anonymous commenters to prevent spam
|
* Description: Adds a math captcha for anonymous commenters to prevent spam
|
||||||
* Version: 0.91
|
* Version: 0.92
|
||||||
* Author: ivan zlax <@zlax@ussr.win>
|
* Author: ivan zlax <@zlax@ussr.win>
|
||||||
* Maintainer: ivan zlax <@zlax@ussr.win>
|
* Maintainer: ivan zlax <@zlax@ussr.win>
|
||||||
*/
|
*/
|
||||||
@@ -218,11 +218,17 @@ if(typeof jQuery!=='undefined'){
|
|||||||
jQuery(document).ajaxComplete(function(event, xhr, settings){
|
jQuery(document).ajaxComplete(function(event, xhr, settings){
|
||||||
if(settings && settings.url && settings.url.indexOf('item')!==-1){
|
if(settings && settings.url && settings.url.indexOf('item')!==-1){
|
||||||
dc('ajaxComplete for item request, url='+settings.url);
|
dc('ajaxComplete for item request, url='+settings.url);
|
||||||
|
dc('responseStatus='+xhr.status+' responseLength='+xhr.responseText.length);
|
||||||
try{
|
try{
|
||||||
var resp = JSON.parse(xhr.responseText);
|
if(xhr.responseText){
|
||||||
dc('response parsed, captcha_fail='+resp.captcha_fail);
|
var resp = JSON.parse(xhr.responseText);
|
||||||
if(resp && resp.captcha_fail){
|
dc('response parsed, captcha_fail='+resp.captcha_fail);
|
||||||
alert(resp.error_msg || 'Captcha failed');
|
if(resp && resp.captcha_fail){
|
||||||
|
alert(resp.error_msg || 'Captcha failed');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dc('empty response from server');
|
||||||
|
dc('check if anoncaptcha_token is in form data');
|
||||||
}
|
}
|
||||||
}catch(e){
|
}catch(e){
|
||||||
dc('error parsing response: '+e.message);
|
dc('error parsing response: '+e.message);
|
||||||
@@ -280,17 +286,17 @@ function addC(){
|
|||||||
}
|
}
|
||||||
// Try immediately
|
// Try immediately
|
||||||
addC();
|
addC();
|
||||||
// If no elements found, retry up to 25 times with 400ms delay (10 seconds total)
|
// If no elements found, retry up to 30 times with 300ms delay (9 seconds total)
|
||||||
// Hubzilla loads comment forms via AJAX after initial page load
|
// Hubzilla loads comment forms via AJAX after initial page load
|
||||||
if(document.querySelectorAll('[id^="comment-edit-anon"]').length===0){
|
if(document.querySelectorAll('[id^="comment-edit-anon"]').length===0){
|
||||||
var retries=0;
|
var retries=0;
|
||||||
var retry=setInterval(function(){
|
var retry=setInterval(function(){
|
||||||
retries++;
|
retries++;
|
||||||
addC();
|
addC();
|
||||||
if(retries>=25 || document.querySelectorAll('[id^="comment-edit-anon"]').length>0){
|
if(retries>=30 || document.querySelectorAll('[id^="comment-edit-anon"]').length>0){
|
||||||
clearInterval(retry);
|
clearInterval(retry);
|
||||||
}
|
}
|
||||||
},400);
|
},300);
|
||||||
}
|
}
|
||||||
// Observe for dynamically added comment forms
|
// Observe for dynamically added comment forms
|
||||||
if(typeof MutationObserver!=="undefined"){
|
if(typeof MutationObserver!=="undefined"){
|
||||||
|
|||||||
Reference in New Issue
Block a user