diff --git a/4chan_x.user.js b/4chan_x.user.js
index a03bd363d..5f454a5ec 100644
--- a/4chan_x.user.js
+++ b/4chan_x.user.js
@@ -1262,42 +1262,39 @@
}
},
captchaNode: function(e) {
- var target;
if (!qr.el) {
return;
}
- target = e.target;
- $('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=" + target.value;
- $('#recaptcha_challenge_field', qr.el).value = target.value;
+ val = e.target.value;
+ $('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=" + val;
+ qr.challenge = val;
return qr.captchaTime = Date.now();
},
captchaKeydown: function(e) {
- var blank, captchas;
+ var captchas;
if (!(e.keyCode === 13 && this.value)) {
return;
}
- blank = !$('textarea', qr.el).value && !$('input[type=file]', qr.el).files.length;
- if (!(blank || cooldown.duration)) {
- return;
- }
- e.preventDefault();
captchas = $.get('captchas', []);
captchas.push({
- challenge: $('#recaptcha_challenge_field', qr.el).value,
+ challenge: qr.challenge,
response: this.value,
time: qr.captchaTime
});
$.set('captchas', captchas);
- this.nextSibling.textContent = captchas.length + ' captchas';
+ $('#captchas', qr.el).textContent = captchas.length + ' captchas';
Recaptcha.reload();
- return this.value = '';
+ this.value = '';
+ if (!$('textarea', qr.el).value && !$('input[type=file]', qr.el).files.length) {
+ return e.preventDefault();
+ }
},
close: function() {
$.rm(qr.el);
return qr.el = null;
},
dialog: function(link) {
- var THREAD_ID, c, challenge, email, html, m, name, pwd, spoiler, submitDisabled, submitValue;
+ var THREAD_ID, c, email, html, m, name, pwd, spoiler, submitDisabled, submitValue;
c = d.cookie;
name = (m = c.match(/4chan_name=([^;]+)/)) ? decodeURIComponent(m[1]) : '';
email = (m = c.match(/4chan_email=([^;]+)/)) ? decodeURIComponent(m[1]) : '';
@@ -1306,8 +1303,8 @@
submitDisabled = $('#com_submit').disabled ? 'disabled' : '';
THREAD_ID = g.THREAD_ID || $.x('ancestor::div[@class="thread"]/div', link).id;
spoiler = $('.postarea label') ? '' : '';
- challenge = $('#recaptcha_challenge_field').value;
- html = " X
Quick Reply
";
+ qr.challenge = $('#recaptcha_challenge_field').value;
+ html = " X Quick Reply
";
qr.el = ui.dialog('qr', {
top: '0px',
left: '0px'
@@ -1320,8 +1317,8 @@
$.bind($('form', qr.el), 'submit', qr.submit);
$.bind($('#attach', qr.el), 'click', qr.attach);
$.bind($('img', qr.el), 'click', Recaptcha.reload);
- $.bind($('#recaptcha_response_field', qr.el), 'keydown', Recaptcha.listener);
- $.bind($('#recaptcha_response_field', qr.el), 'keydown', qr.captchaKeydown);
+ $.bind($('#dummy', qr.el), 'keydown', Recaptcha.listener);
+ $.bind($('#dummy', qr.el), 'keydown', qr.captchaKeydown);
return $.append(d.body, qr.el);
},
message: function(e) {
@@ -1366,15 +1363,11 @@
return $.bind(quote, 'click', qr.quote);
},
postInvalid: function() {
- var captcha, captchas, content, cutoff, responseField;
+ var captcha, captchas, content, cutoff;
content = $('textarea', qr.el).value || $('input[type=file]', qr.el).files.length;
if (!content) {
return 'Error: No text entered.';
}
- responseField = $('#recaptcha_response_field', qr.el);
- if (responseField.value) {
- return;
- }
/*
captchas expire after 5 hours (couldn't find an official source, so
anonymous empirically verified). cutoff 5 minutes before then, b/c posting
@@ -1388,12 +1381,12 @@
}
}
$.set('captchas', captchas);
- responseField.nextSibling.textContent = captchas.length + ' captchas';
+ $('#captchas', qr.el).textContent = captchas.length + ' captchas';
if (!captcha) {
return 'You forgot to type in the verification.';
}
$('#recaptcha_challenge_field', qr.el).value = captcha.challenge;
- responseField.value = captcha.response;
+ $('#recaptcha_response_field', qr.el).value = captcha.response;
return false;
},
quote: function(e) {
@@ -1438,7 +1431,7 @@
e.preventDefault();
alert(msg);
if (msg === 'You forgot to type in the verification.') {
- $('#recaptcha_response_field', qr.el).focus();
+ $('#dummy', qr.el).focus();
}
return;
}
diff --git a/script.coffee b/script.coffee
index 13c35d55d..3d0206baf 100644
--- a/script.coffee
+++ b/script.coffee
@@ -1001,29 +1001,27 @@ qr =
captchaNode: (e) ->
return unless qr.el
- {target} = e
- $('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=" + target.value
- $('#recaptcha_challenge_field', qr.el).value = target.value
+ val = e.target.value
+ $('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=" + val
+ qr.challenge = val
qr.captchaTime = Date.now()
captchaKeydown: (e) ->
return unless e.keyCode is 13 and @value #enter, captcha filled
- blank = !$('textarea', qr.el).value and !$('input[type=file]', qr.el).files.length
- return unless blank or cooldown.duration
-
- e.preventDefault()
-
captchas = $.get 'captchas', []
captchas.push
- challenge: $('#recaptcha_challenge_field', qr.el).value
+ challenge: qr.challenge
response: @value
time: qr.captchaTime
$.set 'captchas', captchas
- @nextSibling.textContent = captchas.length + ' captchas'
+ $('#captchas', qr.el).textContent = captchas.length + ' captchas'
Recaptcha.reload()
@value = ''
+ if !$('textarea', qr.el).value and !$('input[type=file]', qr.el).files.length
+ e.preventDefault()
+
close: ->
$.rm qr.el
qr.el = null
@@ -1038,7 +1036,7 @@ qr =
#FIXME inlined cross-thread quotes
THREAD_ID = g.THREAD_ID or $.x('ancestor::div[@class="thread"]/div', link).id
spoiler = if $('.postarea label') then '' else ''
- challenge = $('#recaptcha_challenge_field').value
+ qr.challenge = $('#recaptcha_challenge_field').value
html = "
X
@@ -1050,13 +1048,13 @@ qr =
@@ -1066,14 +1064,14 @@ qr =
"
qr.el = ui.dialog 'qr', top: '0px', left: '0px', html
- $.bind $('input[name=name]', qr.el), 'mousedown', (e) -> e.stopPropagation()
- $.bind $('input[name=upfile]', qr.el), 'change', qr.validateFileSize
- $.bind $('#close', qr.el), 'click', qr.close
- $.bind $('form', qr.el), 'submit', qr.submit
- $.bind $('#attach', qr.el), 'click', qr.attach
- $.bind $('img', qr.el), 'click', Recaptcha.reload
- $.bind $('#recaptcha_response_field', qr.el), 'keydown', Recaptcha.listener
- $.bind $('#recaptcha_response_field', qr.el), 'keydown', qr.captchaKeydown
+ $.bind $('input[name=name]', qr.el), 'mousedown', (e) -> e.stopPropagation()
+ $.bind $('input[name=upfile]', qr.el), 'change', qr.validateFileSize
+ $.bind $('#close', qr.el), 'click', qr.close
+ $.bind $('form', qr.el), 'submit', qr.submit
+ $.bind $('#attach', qr.el), 'click', qr.attach
+ $.bind $('img', qr.el), 'click', Recaptcha.reload
+ $.bind $('#dummy', qr.el), 'keydown', Recaptcha.listener
+ $.bind $('#dummy', qr.el), 'keydown', qr.captchaKeydown
$.append d.body, qr.el
@@ -1116,9 +1114,6 @@ qr =
content = $('textarea', qr.el).value or $('input[type=file]', qr.el).files.length
return 'Error: No text entered.' unless content
- responseField = $ '#recaptcha_response_field', qr.el
- return if responseField.value
-
###
captchas expire after 5 hours (couldn't find an official source, so
anonymous empirically verified). cutoff 5 minutes before then, b/c posting
@@ -1132,12 +1127,12 @@ qr =
break
$.set 'captchas', captchas
- responseField.nextSibling.textContent = captchas.length + ' captchas'
+ $('#captchas', qr.el).textContent = captchas.length + ' captchas'
return 'You forgot to type in the verification.' unless captcha
$('#recaptcha_challenge_field', qr.el).value = captcha.challenge
- responseField.value = captcha.response
+ $('#recaptcha_response_field', qr.el).value = captcha.response
false
@@ -1177,7 +1172,7 @@ qr =
e.preventDefault()
alert msg
if msg is 'You forgot to type in the verification.'
- $('#recaptcha_response_field', qr.el).focus()
+ $('#dummy', qr.el).focus()
return
if conf['Auto Watch Reply'] and conf['Thread Watcher']