diff --git a/anoncaptcha/README.md b/anoncaptcha/README.md index d567135..ec434b0 100644 --- a/anoncaptcha/README.md +++ b/anoncaptcha/README.md @@ -3,7 +3,7 @@ AnonCaptcha Addon 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. diff --git a/anoncaptcha/anoncaptcha.php b/anoncaptcha/anoncaptcha.php index 89d9f2e..5ae568f 100644 --- a/anoncaptcha/anoncaptcha.php +++ b/anoncaptcha/anoncaptcha.php @@ -2,7 +2,7 @@ /** * Name: AnonCaptcha * Description: Adds a math captcha for anonymous commenters to prevent spam - * Version: 0.91 + * Version: 0.92 * Author: 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){ if(settings && settings.url && settings.url.indexOf('item')!==-1){ dc('ajaxComplete for item request, url='+settings.url); + dc('responseStatus='+xhr.status+' responseLength='+xhr.responseText.length); try{ - var resp = JSON.parse(xhr.responseText); - dc('response parsed, captcha_fail='+resp.captcha_fail); - if(resp && resp.captcha_fail){ - alert(resp.error_msg || 'Captcha failed'); + if(xhr.responseText){ + var resp = JSON.parse(xhr.responseText); + dc('response parsed, captcha_fail='+resp.captcha_fail); + 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){ dc('error parsing response: '+e.message); @@ -280,17 +286,17 @@ function addC(){ } // Try immediately 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 if(document.querySelectorAll('[id^="comment-edit-anon"]').length===0){ var retries=0; var retry=setInterval(function(){ retries++; 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); } - },400); + },300); } // Observe for dynamically added comment forms if(typeof MutationObserver!=="undefined"){