diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index ea02b7d72..d5fb8a0b2 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -6383,7 +6383,7 @@ if (/^text\//.test(file.type)) { if (isSingle) { post = QR.selected; - } else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).com) { + } else if ((post = QR.posts[QR.posts.length - 1]).com) { post = new QR.post(); } post.pasteText(file); @@ -6391,9 +6391,7 @@ } if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) < 0) { QR.error("" + file.name + ": Unsupported file type."); - if (!isSingle) { - return; - } + return; } max = QR.nodes.fileInput.max; if (/^video\//.test(file.type)) { @@ -6401,20 +6399,14 @@ } if (file.size > max) { QR.error("" + file.name + ": File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ")."); - if (!isSingle) { - return; - } + return; } if (isSingle) { post = QR.selected; - } else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).file) { + } else if ((post = QR.posts[QR.posts.length - 1]).file) { post = new QR.post(); } - if (/^text/.test(file.type)) { - return post.pasteText(file); - } else { - return post.setFile(file); - } + return post.setFile(file); }, openFileInput: function(e) { var _ref; @@ -7483,7 +7475,7 @@ } }; - _Class.prototype.setFile = function(file, el) { + _Class.prototype.setFile = function(file) { this.file = file; this.filename = file.name; this.filesize = $.bytesToString(file.size); @@ -7497,8 +7489,10 @@ this.updateFilename(); } if (!/^(image|video)\//.test(file.type)) { - return this.nodes.el.style.backgroundImage = null; + this.nodes.el.style.backgroundImage = null; + return; } + return this.setThumbnail(); }; _Class.prototype.setThumbnail = function(el) { @@ -7515,7 +7509,11 @@ QR.error(error); } _this.URL = fileURL; - return _this.rmFile(); + if ((QR.posts.length === 1) || (_this.com && _this.com.length)) { + return _this.rmFile(); + } else { + return _this.rm(); + } } s = 90 * 2 * window.devicePixelRatio; if (_this.file.type === 'image/gif') { diff --git a/builds/crx/script.js b/builds/crx/script.js index fe59eb8ae..56b8a44aa 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -6441,7 +6441,7 @@ if (/^text\//.test(file.type)) { if (isSingle) { post = QR.selected; - } else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).com) { + } else if ((post = QR.posts[QR.posts.length - 1]).com) { post = new QR.post(); } post.pasteText(file); @@ -6449,9 +6449,7 @@ } if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) < 0) { QR.error("" + file.name + ": Unsupported file type."); - if (!isSingle) { - return; - } + return; } max = QR.nodes.fileInput.max; if (/^video\//.test(file.type)) { @@ -6459,20 +6457,14 @@ } if (file.size > max) { QR.error("" + file.name + ": File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ")."); - if (!isSingle) { - return; - } + return; } if (isSingle) { post = QR.selected; - } else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).file) { + } else if ((post = QR.posts[QR.posts.length - 1]).file) { post = new QR.post(); } - if (/^text/.test(file.type)) { - return post.pasteText(file); - } else { - return post.setFile(file); - } + return post.setFile(file); }, openFileInput: function(e) { var _ref; @@ -7524,7 +7516,7 @@ } }; - _Class.prototype.setFile = function(file, el) { + _Class.prototype.setFile = function(file) { this.file = file; this.filename = file.name; this.filesize = $.bytesToString(file.size); @@ -7538,8 +7530,10 @@ this.updateFilename(); } if (!/^(image|video)\//.test(file.type)) { - return this.nodes.el.style.backgroundImage = null; + this.nodes.el.style.backgroundImage = null; + return; } + return this.setThumbnail(); }; _Class.prototype.setThumbnail = function(el) { @@ -7556,7 +7550,11 @@ QR.error(error); } _this.URL = fileURL; - return _this.rmFile(); + if ((QR.posts.length === 1) || (_this.com && _this.com.length)) { + return _this.rmFile(); + } else { + return _this.rm(); + } } s = 90 * 2 * window.devicePixelRatio; if (_this.file.type === 'image/gif') { diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 5c07fcfed..b79b875c0 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -360,26 +360,23 @@ QR = if /^text\//.test file.type if isSingle post = QR.selected - else if index isnt 0 or (post = QR.posts[QR.posts.length - 1]).com + else if (post = QR.posts[QR.posts.length - 1]).com post = new QR.post() post.pasteText file return unless file.type in QR.mimeTypes QR.error "#{file.name}: Unsupported file type." - return unless isSingle + return max = QR.nodes.fileInput.max max = Math.min(max, QR.max_size_video) if /^video\//.test file.type if file.size > max QR.error "#{file.name}: File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})." - return unless isSingle + return if isSingle post = QR.selected - else if index isnt 0 or (post = QR.posts[QR.posts.length - 1]).file + else if (post = QR.posts[QR.posts.length - 1]).file post = new QR.post() - if /^text/.test file.type - return post.pasteText file - else - post.setFile file + post.setFile file openFileInput: (e) -> e.stopPropagation() diff --git a/src/Posting/QR.post.coffee b/src/Posting/QR.post.coffee index e5bdfc13d..ad6c38cdc 100644 --- a/src/Posting/QR.post.coffee +++ b/src/Posting/QR.post.coffee @@ -82,6 +82,7 @@ QR.post = class (QR.posts[index-1] or QR.posts[index+1]).select() QR.posts.splice index, 1 QR.status() + delete: -> $.rm @nodes.el URL.revokeObjectURL @URL @@ -156,7 +157,7 @@ QR.post = class @save node return - setFile: (@file, el) -> + setFile: (@file) -> @filename = file.name @filesize = $.bytesToString file.size @nodes.label.hidden = false if QR.spoiler @@ -167,6 +168,8 @@ QR.post = class @updateFilename() unless /^(image|video)\//.test file.type @nodes.el.style.backgroundImage = null + return + @setThumbnail() setThumbnail: (el) -> # Create a redimensioned thumbnail. @@ -179,7 +182,7 @@ QR.post = class if errors.length QR.error error for error in errors @URL = fileURL # this.removeFile will revoke this proper. - return @rmFile() + return if (QR.posts.length is 1) or (@com and @com.length) then @rmFile() else @rm() # I wrote this while listening to MCR # Generate thumbnails only if they're really big. # Resized pictures through canvases look like ass,