From 60a62232ad24b392730d68f4a645793405d8bc50 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 23 Jan 2012 20:52:00 +0100 Subject: [PATCH] Yeah, checking captcha timeout is probably better like that. --- 4chan_x.user.js | 22 ++++++++-------------- script.coffee | 20 ++++++++------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 3b5ac5c0e..2df80f498 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1442,22 +1442,19 @@ return window.location = 'javascript:(function(){Recaptcha.focus_response_field=function(){}})()'; }, save: function() { - var captchas, length, now, response; + var captcha, captchas, response; if (!(response = this.input.value)) return; captchas = $.get('captchas', []); - now = Date.now(); - if (captchas.length) { - while (captchas[0].time < now) { - captchas.shift(); - } + while ((captcha = captchas[0]) && captcha.time < Date.now()) { + captchas.shift(); } - length = captchas.push({ + captchas.push({ challenge: this.challenge.firstChild.value, response: response, time: this.timeout }); $.set('captchas', captchas); - this.count(length); + this.count(captchas.length); return this.reload(); }, load: function() { @@ -1545,7 +1542,7 @@ return $.add(d.body, qr.el); }, submit: function(e) { - var captcha, captchas, challenge, err, file, m, now, post, reader, reply, response, threadID, time; + var captcha, captchas, challenge, err, file, m, post, reader, reply, response, threadID; if (e != null) e.preventDefault(); qr.message.send({ abort: true @@ -1555,11 +1552,8 @@ err = 'Error: No file selected.'; } else { captchas = $.get('captchas', []); - if (captchas.length) { - now = Date.now(); - while ((time = captchas[0].time) && time < now) { - captchas.shift(); - } + while ((captcha = captchas[0]) && captcha.time < Date.now()) { + captchas.shift(); } if (captcha = captchas.shift()) { challenge = captcha.challenge; diff --git a/script.coffee b/script.coffee index 6bdace5b1..d92dc2599 100644 --- a/script.coffee +++ b/script.coffee @@ -1071,16 +1071,14 @@ qr = return unless response = @input.value captchas = $.get 'captchas', [] # remove old captchas - now = Date.now() - if captchas.length - while captchas[0].time < now - captchas.shift() - length = captchas.push + while (captcha = captchas[0]) and captcha.time < Date.now() + captchas.shift() + captchas.push challenge: @challenge.firstChild.value response: response time: @timeout $.set 'captchas', captchas - @count length + @count captchas.length @reload() load: -> @timeout = Date.now() + 25*MINUTE @@ -1170,12 +1168,10 @@ qr = else # get oldest valid captcha captchas = $.get 'captchas', [] - if captchas.length - # remove old captchas - now = Date.now() - while (time = captchas[0].time) and time < now - captchas.shift() - if captcha = captchas.shift() + # remove old captchas + while (captcha = captchas[0]) and captcha.time < Date.now() + captchas.shift() + if captcha = captchas.shift() challenge = captcha.challenge response = captcha.response else