diff --git a/4chan_x.user.js b/4chan_x.user.js index a80aa0d9b..839c523c4 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1231,6 +1231,16 @@ $.bind(window, 'message', qr.message); $.bind($('#recaptcha_challenge_field_holder'), 'DOMNodeInserted', qr.captchaNode); qr.captchaTime = Date.now(); + qr.acceptFiles = $('.rules').textContent.match(/:(.+)/)[1].replace(/[A-Z]{3}/g, function(type) { + switch (type) { + case 'JPG': + return 'image/JPEG'; + case 'PDF': + return 'application/' + type; + default: + return 'image/' + type; + } + }); iframe = $.el('iframe', { name: 'iframe', hidden: true @@ -1241,7 +1251,7 @@ attach: function() { var fileDiv; fileDiv = $.el('div', { - innerHTML: 'X' + innerHTML: "X" }); $.bind(fileDiv.firstChild, 'change', qr.validateFileSize); $.bind(fileDiv.lastChild, 'click', (function() { @@ -1304,7 +1314,7 @@ THREAD_ID = g.THREAD_ID || $.x('ancestor::div[@class="thread"]/div', link).id; spoiler = $('.postarea label') ? '' : ''; qr.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' @@ -1428,7 +1438,8 @@ oldFile = $('[type=file]', qr.el); newFile = $.el('input', { type: 'file', - name: 'upfile' + name: 'upfile', + accept: qr.acceptFiles }); return $.replace(oldFile, newFile); }, @@ -1526,7 +1537,8 @@ } file = $.el('input', { type: 'file', - name: 'upfile' + name: 'upfile', + accept: qr.acceptFiles }); $.bind(file, 'change', qr.validateFileSize); $.replace(this, file); diff --git a/changelog b/changelog index be3f03858..2f2709020 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ GitHub - mayhem: bring back auto posting don't start the cooldown on thread creation + limit the file upload dialog to the accepted file types (qr) - aeosynth: show linebreaks as spaces in title & watcher auto posting fixes diff --git a/script.coffee b/script.coffee index 90b0c93af..26c6682f9 100644 --- a/script.coffee +++ b/script.coffee @@ -975,6 +975,15 @@ qr = $.bind $('#recaptcha_challenge_field_holder'), 'DOMNodeInserted', qr.captchaNode qr.captchaTime = Date.now() + qr.acceptFiles = $('.rules').textContent.match(/:(.+)/)[1].replace /[A-Z]{3}/g, (type) -> + switch type + when 'JPG' + 'image/JPEG' + when 'PDF' + 'application/' + type + else + 'image/' + type + iframe = $.el 'iframe', name: 'iframe' hidden: true @@ -984,7 +993,7 @@ qr = $('#recaptcha_response_field').id = '' attach: -> - fileDiv = $.el 'div', innerHTML: 'X' + fileDiv = $.el 'div', innerHTML: "X" $.bind fileDiv.firstChild, 'change', qr.validateFileSize $.bind fileDiv.lastChild, 'click', (-> $.rm @parentNode) $.append $('#files', qr.el), fileDiv @@ -1055,7 +1064,7 @@ qr =
#{$.get('captchas', []).length} captchas
-
+
attach another file
@@ -1169,7 +1178,7 @@ qr = $('[name=recaptcha_response_field]', qr.el).value = '' # XXX opera doesn't allow resetting file inputs w/ file.value = '' oldFile = $ '[type=file]', qr.el - newFile = $.el 'input', type: 'file', name: 'upfile' + newFile = $.el 'input', type: 'file', name: 'upfile', accept: qr.acceptFiles $.replace oldFile, newFile submit: (e) -> @@ -1247,7 +1256,7 @@ qr = validateFileSize: (e) -> return unless @files[0].size > $('input[name=MAX_FILE_SIZE]').value - file = $.el 'input', type: 'file', name: 'upfile' + file = $.el 'input', type: 'file', name: 'upfile', accept: qr.acceptFiles $.bind file, 'change', qr.validateFileSize $.replace @, file