From 2a74af9b3b7d8fab3098bc25e36e3577961829bb Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 6 Aug 2011 20:42:57 -0700 Subject: [PATCH] attach next file if dup detected --- 4chan_x.user.js | 34 ++++++++++++++++++++++------------ script.coffee | 29 ++++++++++++++++++----------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 2f319a5ad..18da7935f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1242,16 +1242,22 @@ return $('#recaptcha_response_field').id = ''; }, attach: function() { - var fileDiv, files; + var fileDiv; $('#auto', qr.el).checked = true; - files = $('#files', qr.el); fileDiv = $.el('div', { innerHTML: 'X' }); $.bind(fileDiv.lastChild, 'click', (function() { return $.rm(this.parentNode); })); - return $.prepend(files, file); + return $.prepend(qr.files, fileDiv); + }, + attachNext: function() { + var file, fileDiv, oldFile; + fileDiv = $.rm(qr.files.lastChild); + file = fileDiv.firstChild; + oldFile = $('#qr_form input[type=file]', qr.el); + return $.replace(oldFile, file); }, autoPost: function() { var captcha, responseField; @@ -1307,6 +1313,7 @@ top: '0px', left: '0px' }, html); + qr.files = $('#files', qr.el); qr.refresh(); $('textarea', qr.el).value = $('textarea').value; $.bind($('input[name=name]', qr.el), 'mousedown', function(e) { @@ -1321,7 +1328,7 @@ return $.append(d.body, qr.el); }, message: function(e) { - var data, duration, file, fileDiv, oldFile; + var data, duration; Recaptcha.reload(); $('iframe[name=iframe]').src = 'about:blank'; data = e.data; @@ -1331,19 +1338,22 @@ $('#recaptcha_response_field', qr.el).value = ''; $('#autohide', qr.el).checked = false; if (data.textContent === 'You seem to have mistyped the verification.') { - qr.autoPost(); + if (qr.captcha.length) { + qr.autoPost(); + } + } else if (data.textContent === 'Error: Duplicate file entry detected.' && qr.files.childElementCount) { + qr.attachNext(); + if (qr.captcha.length) { + qr.autoPost(); + } } return; } if (qr.el) { - fileDiv = $('#files div:last-child', qr.el); - if (g.REPLY && (conf['Persistent QR'] || fileDiv)) { + if (g.REPLY && (conf['Persistent QR'] || qr.files.childElementCount)) { qr.refresh(); - if (fileDiv) { - $.rm(fileDiv); - file = fileDiv.firstChild; - oldFile = $('#qr_form input[type=file]', qr.el); - $.replace(oldFile, file); + if (qr.files.childElementCount) { + qr.attachNext(); } } else { qr.close(); diff --git a/script.coffee b/script.coffee index 9c2ebb627..c59758f06 100644 --- a/script.coffee +++ b/script.coffee @@ -966,10 +966,10 @@ cooldown = qr.autoPost() qr = + # TODO # error handling # persistent captcha # rm Recaptcha - # group captcha # error too large error should happen on attach init: -> g.callbacks.push qr.node @@ -987,10 +987,15 @@ qr = attach: -> $('#auto', qr.el).checked = true - files = $ '#files', qr.el fileDiv = $.el 'div', innerHTML: 'X' $.bind fileDiv.lastChild, 'click', (-> $.rm @parentNode) - $.prepend files, file + $.prepend qr.files, fileDiv + + attachNext: -> + fileDiv = $.rm qr.files.lastChild + file = fileDiv.firstChild + oldFile = $ '#qr_form input[type=file]', qr.el + $.replace oldFile, file autoPost: -> responseField = $ '#recaptcha_response_field', qr.el @@ -1053,6 +1058,7 @@ qr = " qr.el = ui.dialog 'qr', top: '0px', left: '0px', html + qr.files = $ '#files', qr.el qr.refresh() $('textarea', qr.el).value = $('textarea').value @@ -1078,18 +1084,19 @@ qr = $('#recaptcha_response_field', qr.el).value = '' $('#autohide', qr.el).checked = false if data.textContent is 'You seem to have mistyped the verification.' - qr.autoPost() + if qr.captcha.length + qr.autoPost() + else if data.textContent is 'Error: Duplicate file entry detected.' and qr.files.childElementCount + qr.attachNext() + if qr.captcha.length + qr.autoPost() return if qr.el - fileDiv = $ '#files div:last-child', qr.el - if g.REPLY and (conf['Persistent QR'] or fileDiv) + if g.REPLY and (conf['Persistent QR'] or qr.files.childElementCount) qr.refresh() - if fileDiv - $.rm fileDiv - file = fileDiv.firstChild - oldFile = $ '#qr_form input[type=file]', qr.el - $.replace oldFile, file + if qr.files.childElementCount + qr.attachNext() else qr.close() if conf['Cooldown']