diff --git a/4chan_x.user.js b/4chan_x.user.js index 03e69e634..3a0a57c7b 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1265,13 +1265,17 @@ $.append($('#files', QR.el), div); return file.click(); }, - attachNext: function(file) { - var oldFile; + attachNext: function() { + var file, oldFile; oldFile = $('[type=file]', QR.el); - file || (file = $.el('input', { - type: 'file', - name: 'upfile' - })); + if (file = $('#files input', QR.el)) { + $.rm(file.parentNode); + } else { + file = $.el('input', { + type: 'file', + name: 'upfile' + }); + } return $.replace(oldFile, file); }, autoPost: function() { @@ -1396,7 +1400,7 @@ return ta.focus(); }, receive: function(e) { - var data, file, tc; + var data, tc, _ref; data = e.data; if (data) { $.extend($('a.error', QR.el), JSON.parse(data)); @@ -1406,8 +1410,8 @@ } return; } - if (((file = $('#files input', QR.el)) && file.files.length) || conf['Persistent QR']) { - QR.reset(file); + if (conf['Persistent QR'] || ((_ref = $('#files input', QR.el)) != null ? _ref.files.length : void 0)) { + QR.reset(); } else { QR.close(); } @@ -1417,9 +1421,9 @@ return QR.cooldown(); } }, - reset: function(file) { + reset: function() { $('textarea', QR.el).value = ''; - return QR.attachNext(file); + return QR.attachNext(); }, submit: function(e) { var captcha, challenge, el, response; diff --git a/script.coffee b/script.coffee index cdb84f3fd..0fce5e2bc 100644 --- a/script.coffee +++ b/script.coffee @@ -988,11 +988,14 @@ QR = $.bind $('a', div), 'click', -> $.rm @parentNode $.append $('#files', QR.el), div file.click() - attachNext: (file) -> + attachNext: -> oldFile = $ '[type=file]', QR.el - file or= $.el 'input', - type: 'file' - name: 'upfile' + if file = $ '#files input', QR.el + $.rm file.parentNode + else + file = $.el 'input', + type: 'file' + name: 'upfile' $.replace oldFile, file autoPost: -> return unless QR.hasContent() @@ -1099,17 +1102,17 @@ QR = if tc is 'Error: Duplicate file entry detected.' QR.attachNext() return - if ((file = $('#files input', QR.el)) and file.files.length) or conf['Persistent QR'] - QR.reset file + if conf['Persistent QR'] or $('#files input', QR.el)?.files.length + QR.reset() else QR.close() if conf['Cooldown'] cooldown = Date.now() + 30*SECOND $.set "cooldown/#{g.BOARD}", cooldown QR.cooldown() - reset: (file) -> + reset: -> $('textarea', QR.el).value = '' - QR.attachNext file + QR.attachNext() submit: (e) -> #XXX e is undefined if we're called from QR.autoPost $('.error', qr.el).textContent = ''