From 8a965fe9fce8e1c3d62d6bb0cd543be941e069c0 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 20 Aug 2012 00:18:39 +0200 Subject: [PATCH] Prevent upload if the subject is required. Close #660. --- 4chan_x.user.js | 17 +++++++++++++---- script.coffee | 15 +++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 9ac585538..31a87b407 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2354,7 +2354,7 @@ })); }, submit: function(e) { - var callbacks, captcha, captchas, challenge, err, m, opts, post, reply, response, threadID; + var callbacks, captcha, captchas, challenge, err, m, opts, post, reply, response, threadID, _ref; if (e != null) { e.preventDefault(); } @@ -2366,9 +2366,18 @@ QR.abort(); reply = QR.replies[0]; threadID = g.THREAD_ID || $('select', QR.el).value; - if (!(threadID === 'new' && reply.file || threadID !== 'new' && (reply.com || reply.file))) { - err = 'No file selected.'; - } else if (QR.captchaIsEnabled) { + if (threadID === 'new') { + if (((_ref = g.BOARD) === 'vg' || _ref === 'q') && !reply.sub) { + err = 'New threads require a subject.'; + } else if (!reply.file) { + err = 'No file selected.'; + } + } else { + if (!(reply.com || reply.file)) { + err = 'No file selected.'; + } + } + if (QR.captchaIsEnabled && !err) { captchas = $.get('captchas', []); while ((captcha = captchas[0]) && captcha.time < Date.now()) { captchas.shift(); diff --git a/script.coffee b/script.coffee index 57796ffc3..8b3973982 100644 --- a/script.coffee +++ b/script.coffee @@ -1824,14 +1824,21 @@ QR = QR.status() return QR.abort() - reply = QR.replies[0] + reply = QR.replies[0] threadID = g.THREAD_ID or $('select', QR.el).value # prevent errors - unless threadID is 'new' and reply.file or threadID isnt 'new' and (reply.com or reply.file) - err = 'No file selected.' - else if QR.captchaIsEnabled + if threadID is 'new' + if g.BOARD in ['vg', 'q'] and !reply.sub + err = 'New threads require a subject.' + else unless reply.file + err = 'No file selected.' + else + unless reply.com or reply.file + err = 'No file selected.' + + if QR.captchaIsEnabled and !err # get oldest valid captcha captchas = $.get 'captchas', [] # remove old captchas