diff --git a/4chan_x.user.js b/4chan_x.user.js index 41c3c3687..fa5d442c3 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1209,8 +1209,8 @@ submit.disabled = false; submit.value = 'Submit'; } - if (qr.el && $('#auto', qr.el).checked) { - return qr.autoPost(); + if (!qr.validatePost()) { + return qr.submit.call($('form', qr.el)); } } } @@ -1231,7 +1231,6 @@ }, attach: function() { var fileDiv; - $('#auto', qr.el).checked = true; fileDiv = $.el('div', { innerHTML: 'X' }); @@ -1248,17 +1247,21 @@ oldFile = $('#qr_form input[type=file]', qr.el); return $.replace(oldFile, file); }, - autoPost: function() { + validatePost: function() { + var captcha, captchas, content, cutoff, responseField; + 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 takes time. */ - var blank, captcha, captchas, cutoff, responseField; - blank = !$('textarea', qr.el).value && !$('input[type=file]', qr.el).files.length; - if (blank) { - return; - } cutoff = Date.now() - 5 * HOUR + 5 * MINUTE; captchas = $.get('captchas', []); while (captcha = captchas.shift()) { @@ -1267,16 +1270,13 @@ } } $.set('captchas', captchas); - responseField = $('#recaptcha_response_field', qr.el); responseField.nextSibling.textContent = captchas.length + ' captchas'; if (!captcha) { - alert('You forgot to type in the verification.'); - responseField.focus(); - return; + return 'You forgot to type in the verification.'; } $('#recaptcha_challenge_field', qr.el).value = captcha.challenge; responseField.value = captcha.response; - return qr.submit.call($('form', qr.el)); + return false; }, captchaNode: function(e) { var target; @@ -1297,11 +1297,7 @@ if (!(blank || cooldown.duration)) { return; } - e.stopPropagation(); - $('#auto', qr.el).checked = true; - if (conf['Auto Hide QR']) { - $('#autohide', qr.el).checked = true; - } + e.preventDefault(); captchas = $.get('captchas', []); captchas.push({ challenge: $('#recaptcha_challenge_field', qr.el).value, @@ -1324,7 +1320,7 @@ 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
" + spoiler + "
" + ($.get('captchas', []).length) + " captchas
attach another file
"; + html = " X
Quick Reply
" + spoiler + "
" + ($.get('captchas', []).length) + " captchas
attach another file
"; qr.el = ui.dialog('qr', { top: '0px', left: '0px' @@ -1409,20 +1405,21 @@ return ta.value += text; }, refresh: function() { - var auto, c, m; - auto = $('#auto', qr.el).checked; + var c, m; $('form', qr.el).reset(); - $('#auto', qr.el).checked = auto; c = d.cookie; $('input[name=name]', qr.el).value = (m = c.match(/4chan_name=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; $('input[name=email]', qr.el).value = (m = c.match(/4chan_email=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; return $('input[name=pwd]', qr.el).value = (m = c.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $('input[name=pwd]').value; }, submit: function(e) { - var id, isQR, op; - if ($('#recaptcha_response_field', qr.el).value === '') { + var id, msg, op; + if (msg = qr.validatePost()) { e.preventDefault(); - qr.autoPost(); + alert(msg); + if (msg === 'You forgot to type in the verification.') { + $('#recaptcha_response_field', qr.el).focus(); + } return; } if (conf['Auto Watch Reply'] && conf['Thread Watcher']) { @@ -1436,17 +1433,17 @@ } } } - isQR = this.id === 'qr_form'; - if (this.id === 'qr_form') { - if (!e) { - this.submit(); - } - $('#error', qr.el).textContent = ''; - if (conf['Auto Hide QR']) { - $('#autohide', qr.el).checked = true; - } - return qr.sage = /sage/i.test($('input[name=email]', this).value); + if (this.id !== 'qr_form') { + return; } + if (!e) { + this.submit(); + } + $('#error', qr.el).textContent = ''; + if (conf['Auto Hide QR']) { + $('#autohide', qr.el).checked = true; + } + return qr.sage = /sage/i.test($('input[name=email]', this).value); }, sys: function() { var c, duration, id, noko, recaptcha, sage, search, thread, url, watch, _, _ref; diff --git a/script.coffee b/script.coffee index 0f8232909..d8a2e7f1c 100644 --- a/script.coffee +++ b/script.coffee @@ -928,6 +928,7 @@ options = $('#timePreview').textContent = Time.funk Time cooldown = + #TODO merge into qr init: -> if match = location.search.match /cooldown=(\d+)/ [_, time] = match @@ -953,8 +954,8 @@ cooldown = for submit in submits submit.disabled = false submit.value = 'Submit' - if qr.el and $('#auto', qr.el).checked - qr.autoPost() + unless qr.validatePost() + qr.submit.call $ 'form', qr.el qr = # TODO @@ -977,7 +978,6 @@ qr = $('#recaptcha_response_field').id = '' attach: -> - $('#auto', qr.el).checked = true fileDiv = $.el 'div', innerHTML: 'X' $.bind fileDiv.firstChild, 'change', qr.validateFileSize $.bind fileDiv.lastChild, 'click', (-> $.rm @parentNode) @@ -989,16 +989,19 @@ qr = oldFile = $ '#qr_form input[type=file]', qr.el $.replace oldFile, file - autoPost: -> + validatePost: -> + 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 takes time. ### - blank = !$('textarea', qr.el).value and !$('input[type=file]', qr.el).files.length - return if blank - cutoff = Date.now() - 5*HOUR + 5*MINUTE captchas = $.get 'captchas', [] while captcha = captchas.shift() @@ -1006,17 +1009,14 @@ qr = break $.set 'captchas', captchas - responseField = $ '#recaptcha_response_field', qr.el responseField.nextSibling.textContent = captchas.length + ' captchas' - unless captcha - alert 'You forgot to type in the verification.' - responseField.focus() - return + return 'You forgot to type in the verification.' unless captcha $('#recaptcha_challenge_field', qr.el).value = captcha.challenge responseField.value = captcha.response - qr.submit.call $ 'form', qr.el + + false captchaNode: (e) -> return unless qr.el @@ -1031,10 +1031,7 @@ qr = blank = !$('textarea', qr.el).value and !$('input[type=file]', qr.el).files.length return unless blank or cooldown.duration - e.stopPropagation() - - $('#auto', qr.el).checked = true - $('#autohide', qr.el).checked = true if conf['Auto Hide QR'] + e.preventDefault() captchas = $.get 'captchas', [] captchas.push @@ -1069,7 +1066,7 @@ qr =
#{spoiler}
-
+
#{$.get('captchas', []).length} captchas
@@ -1153,18 +1150,18 @@ qr = ta.value += text refresh: -> - auto = $('#auto', qr.el).checked $('form', qr.el).reset() - $('#auto', qr.el).checked = auto c = d.cookie $('input[name=name]', qr.el).value = if m = c.match(/4chan_name=([^;]+)/) then decodeURIComponent m[1] else '' $('input[name=email]', qr.el).value = if m = c.match(/4chan_email=([^;]+)/) then decodeURIComponent m[1] else '' $('input[name=pwd]', qr.el).value = if m = c.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('input[name=pwd]').value submit: (e) -> - if $('#recaptcha_response_field', qr.el).value is '' + if msg = qr.validatePost() e.preventDefault() - qr.autoPost() + alert msg + if msg is 'You forgot to type in the verification.' + $('#recaptcha_response_field', qr.el).focus() return if conf['Auto Watch Reply'] and conf['Thread Watcher'] @@ -1176,13 +1173,12 @@ qr = if $('img.favicon', op).src is Favicon.empty watcher.watch op, id - isQR = @id is 'qr_form' + return unless @id is 'qr_form' - if @id is 'qr_form' - if !e then @submit() - $('#error', qr.el).textContent = '' - $('#autohide', qr.el).checked = true if conf['Auto Hide QR'] - qr.sage = /sage/i.test $('input[name=email]', @).value + if !e then @submit() + $('#error', qr.el).textContent = '' + $('#autohide', qr.el).checked = true if conf['Auto Hide QR'] + qr.sage = /sage/i.test $('input[name=email]', @).value sys: -> if recaptcha = $ '#recaptcha_response_field' #post reporting