diff --git a/4chan_x.user.js b/4chan_x.user.js
index ff01a9cd1..ba0814b3c 100644
--- a/4chan_x.user.js
+++ b/4chan_x.user.js
@@ -1234,11 +1234,15 @@
QR.challengeNode({
target: holder.firstChild
});
- return $.bind(window, 'message', QR.receive);
+ $.bind(window, 'message', QR.receive);
+ return $('#recaptcha_response_field').id = '';
},
challengeNode: function(e) {
+ var c;
+ c = e.target.value;
+ $('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=" + c;
return QR.captcha = {
- challenge: e.target.value,
+ challenge: c,
time: Date.now()
};
},
@@ -1259,14 +1263,33 @@
qr.el = ui.dialog('qr', {
top: '0',
left: '0'
- }, " X
Quick Reply
");
+ }, " X Quick Reply
");
$.bind($('form', qr.el), 'submit', QR.submit);
+ $.bind($('#recaptcha_response_field', qr.el), 'keydown', QR.keydown);
$.append(d.body, qr.el);
ta = $('textarea', qr.el);
l = text.length;
ta.setSelectionRange(l, l);
return ta.focus();
},
+ keydown: function(e) {
+ var captcha, captchas;
+ if (!(e.keyCode === 13 && this.value)) {
+ return;
+ }
+ if ($('textarea', qr.el).value || $('[type=file]', qr.el).files.length) {
+ return;
+ }
+ e.preventDefault();
+ captcha = QR.captcha;
+ captcha.response = this.value;
+ captchas = $.get('captchas', []);
+ captchas.push(captcha);
+ $.set('captchas', captchas);
+ this.value = '';
+ Recaptcha.reload();
+ return this.nextSibling.textContent = captchas.length + ' captchas';
+ },
submit: function(e) {
$('#challenge', qr.el).value = QR.captcha.challenge;
return $('#response', qr.el).value = $('#recaptcha_response_field', qr.el).value;
diff --git a/script.coffee b/script.coffee
index 8b09bbd45..2c5d8fc0e 100644
--- a/script.coffee
+++ b/script.coffee
@@ -970,9 +970,13 @@ QR =
$.bind holder, 'DOMNodeInserted', QR.challengeNode
QR.challengeNode target: holder.firstChild
$.bind window, 'message', QR.receive
+ # nuke id so qr's field focuses on recaptcha reload, instead of normal form's
+ $('#recaptcha_response_field').id = ''
challengeNode: (e) ->
+ c = e.target.value
+ $('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=#{c}"
QR.captcha =
- challenge: e.target.value
+ challenge: c
time: Date.now()
node: (root) ->
quote = $ 'a.quotejs + a', root
@@ -993,18 +997,31 @@ QR =
-
+ #{$.get('captchas', []).length} captchas
"
$.bind $('form', qr.el), 'submit', QR.submit
+ $.bind $('#recaptcha_response_field', qr.el), 'keydown', QR.keydown
$.append d.body, qr.el
ta = $ 'textarea', qr.el
l = text.length
ta.setSelectionRange l, l
ta.focus()
+ keydown: (e) ->
+ return unless e.keyCode is 13 and @value #enter, captcha filled
+ return if $('textarea', qr.el).value or $('[type=file]', qr.el).files.length #not blank
+ e.preventDefault()
+ {captcha} = QR
+ captcha.response = @value
+ captchas = $.get 'captchas', []
+ captchas.push captcha
+ $.set 'captchas', captchas
+ @value = ''
+ Recaptcha.reload()
+ @nextSibling.textContent = captchas.length + ' captchas'
submit: (e) ->
$('#challenge', qr.el).value = QR.captcha.challenge
$('#response', qr.el).value = $('#recaptcha_response_field', qr.el).value
@@ -1015,7 +1032,6 @@ QR =
data = JSON.stringify {textContent, href}
parent.postMessage data, '*'
location = 'about:blank'
-
receive: (e) ->
{data} = e
if data