From 4f6c79a3710ec643f7744a7be3286c118ed8cb8a Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 2 Sep 2011 23:00:20 -0700 Subject: [PATCH] handle dup files --- 4chan_x.user.js | 45 ++++++++++++++++++++++++++------------------- script.coffee | 31 ++++++++++++++++++------------- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a1cbbaf1b..03e69e634 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1265,6 +1265,15 @@ $.append($('#files', QR.el), div); return file.click(); }, + attachNext: function(file) { + var oldFile; + oldFile = $('[type=file]', QR.el); + file || (file = $.el('input', { + type: 'file', + name: 'upfile' + })); + return $.replace(oldFile, file); + }, autoPost: function() { if (!QR.hasContent()) { return; @@ -1387,32 +1396,30 @@ return ta.focus(); }, receive: function(e) { - var data, file; + var data, file, tc; data = e.data; if (data) { - return $.extend($('a.error', QR.el), JSON.parse(data)); + $.extend($('a.error', QR.el), JSON.parse(data)); + tc = data.textContent; + if (tc === 'Error: Duplicate file entry detected.') { + QR.attachNext(); + } + return; + } + if (((file = $('#files input', QR.el)) && file.files.length) || conf['Persistent QR']) { + QR.reset(file); } else { - if (((file = $('#files input', QR.el)) && file.files.length) || conf['Persistent QR']) { - QR.reset(file); - } else { - QR.close(); - } - if (conf['Cooldown']) { - cooldown = Date.now() + 30 * SECOND; - $.set("cooldown/" + g.BOARD, cooldown); - return QR.cooldown(); - } + QR.close(); + } + if (conf['Cooldown']) { + cooldown = Date.now() + 30 * SECOND; + $.set("cooldown/" + g.BOARD, cooldown); + return QR.cooldown(); } }, reset: function(file) { - var oldFile; $('textarea', QR.el).value = ''; - oldFile = $('[type=file]', QR.el); - file || (file = $.el('input', { - type: 'file', - name: 'upfile' - })); - return $.replace(oldFile, file); + return QR.attachNext(file); }, submit: function(e) { var captcha, challenge, el, response; diff --git a/script.coffee b/script.coffee index 078cf5bb3..cdb84f3fd 100644 --- a/script.coffee +++ b/script.coffee @@ -988,6 +988,12 @@ QR = $.bind $('a', div), 'click', -> $.rm @parentNode $.append $('#files', QR.el), div file.click() + attachNext: (file) -> + oldFile = $ '[type=file]', QR.el + file or= $.el 'input', + type: 'file' + name: 'upfile' + $.replace oldFile, file autoPost: -> return unless QR.hasContent() QR.submit() @@ -1089,22 +1095,21 @@ QR = {data} = e if data $.extend $('a.error', QR.el), JSON.parse data + tc = data.textContent + 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 else - if ((file = $('#files input', QR.el)) and file.files.length) or conf['Persistent QR'] - QR.reset file - else - QR.close() - if conf['Cooldown'] - cooldown = Date.now() + 30*SECOND - $.set "cooldown/#{g.BOARD}", cooldown - QR.cooldown() + QR.close() + if conf['Cooldown'] + cooldown = Date.now() + 30*SECOND + $.set "cooldown/#{g.BOARD}", cooldown + QR.cooldown() reset: (file) -> $('textarea', QR.el).value = '' - oldFile = $ '[type=file]', QR.el - file or= $.el 'input', - type: 'file' - name: 'upfile' - $.replace oldFile, file + QR.attachNext file submit: (e) -> #XXX e is undefined if we're called from QR.autoPost $('.error', qr.el).textContent = ''