diff --git a/4chan_x.user.js b/4chan_x.user.js
index 8c1e9f361..61b434104 100644
--- a/4chan_x.user.js
+++ b/4chan_x.user.js
@@ -1294,7 +1294,7 @@
QR.el = el = ui.dialog('qr', {
top: '0',
left: '0'
- }, " X
Quick Reply
");
+ }, " X Quick Reply
");
if (conf['Cooldown']) {
QR.cooldown;
}
@@ -1307,11 +1307,20 @@
ta.setSelectionRange(l, l);
return ta.focus();
},
+ hasContent: function() {
+ return $('textarea', QR.el).value || $('[type=file]', QR.el).files.length;
+ },
+ autoPost: function() {
+ if (!QR.hasContent()) {
+ return;
+ }
+ return QR.submit();
+ },
keydown: function(e) {
if (!(e.keyCode === 13 && this.value)) {
return;
}
- if ($('textarea', QR.el).value || $('[type=file]', QR.el).files.length) {
+ if (QR.hasContent()) {
return;
}
e.preventDefault();
@@ -1343,16 +1352,19 @@
n = Math.ceil((cooldown - now) / 1000);
b = $('button', QR.el);
if (n > 0) {
- setTimeout(QR.cooldown, 1000);
- return $.extend(b, {
+ $.extend(b, {
textContent: n,
disabled: true
});
+ return setTimeout(QR.cooldown, 1000);
} else {
- return $.extend(b, {
+ $.extend(b, {
textContent: 'Submit',
disabled: false
});
+ if ($('#auto', QR.el).checked) {
+ return QR.autoPost();
+ }
}
},
receive: function(e) {
@@ -1379,14 +1391,19 @@
}
if (!(captcha = QR.captchaShift())) {
alert('You forgot to type in the verification.');
- e.preventDefault();
+ if (e != null) {
+ e.preventDefault();
+ }
return;
}
challenge = captcha.challenge, response = captcha.response;
$('#challenge', QR.el).value = challenge;
$('#response', QR.el).value = response;
if (conf['Auto Hide QR']) {
- return $('#autohide', QR.el).checked = true;
+ $('#autohide', QR.el).checked = true;
+ }
+ if (!e) {
+ return $('#qr_form', QR.el).submit;
}
},
sys: function() {
diff --git a/script.coffee b/script.coffee
index c48814327..7f948754e 100644
--- a/script.coffee
+++ b/script.coffee
@@ -1015,7 +1015,7 @@ QR =
-
+
#{$.get('captchas', []).length} captchas
@@ -1033,9 +1033,14 @@ QR =
l = text.length
ta.setSelectionRange l, l
ta.focus()
+ hasContent: ->
+ $('textarea', QR.el).value or $('[type=file]', QR.el).files.length
+ autoPost: ->
+ return unless QR.hasContent()
+ QR.submit()
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
+ return if QR.hasContent()
e.preventDefault()
QR.captchaPush @
quote: (e) ->
@@ -1058,14 +1063,15 @@ QR =
n = Math.ceil (cooldown - now) / 1000
b = $ 'button', QR.el
if n > 0
- setTimeout QR.cooldown, 1000
$.extend b,
textContent: n
disabled: true
+ setTimeout QR.cooldown, 1000
else
$.extend b,
textContent: 'Submit'
disabled: false
+ QR.autoPost() if $('#auto', QR.el).checked
receive: (e) ->
{data} = e
if data
@@ -1077,17 +1083,19 @@ QR =
$.set "cooldown/#{g.BOARD}", cooldown
QR.cooldown()
submit: (e) ->
+ #XXX e is undefined if we're called from QR.autoPost
$('.error', qr.el).textContent = ''
if (el = $('#recaptcha_response_field', QR.el)).value
QR.captchaPush el
if not captcha = QR.captchaShift()
alert 'You forgot to type in the verification.'
- e.preventDefault()
+ e?.preventDefault()
return
{challenge, response} = captcha
$('#challenge', QR.el).value = challenge
$('#response', QR.el).value = response
$('#autohide', QR.el).checked = true if conf['Auto Hide QR']
+ $('#qr_form', QR.el).submit if not e
sys: ->
$.globalEval ->
if node = document.querySelector('table font b')?.firstChild