diff --git a/LICENSE b/LICENSE index 6a06ff8b3..f337df97e 100755 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.3.5 - 2014-02-11 +* 4chan X - Version 1.3.5 - 2014-02-12 * * Licensed under the MIT license. * https://github.com/Spittie/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index ccd46919f..0b2f59916 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -23,7 +23,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.3.5 - 2014-02-11 +* 4chan X - Version 1.3.5 - 2014-02-12 * * Licensed under the MIT license. * https://github.com/Spittie/4chan-x/blob/master/LICENSE @@ -5471,7 +5471,6 @@ QR.cleanNotifications(); d.activeElement.blur(); $.rmClass(QR.nodes.el, 'dump'); - $.rmClass(QR.nodes.el, 'url'); if (!Conf['Captcha Warning Notifications']) { if (QR.captcha.isEnabled) { $.rmClass(QR.captcha.nodes.input, 'error'); @@ -5664,7 +5663,48 @@ QR.handleFiles(files); return $.addClass(QR.nodes.el, 'dump'); }, - handleUrl: function() {}, + handleUrl: function() { + var url; + url = prompt("Insert an url:"); + if (url === null) { + return; + } + GM_xmlhttpRequest({ + method: "GET", + url: url, + overrideMimeType: "text/plain; charset=x-user-defined", + onload: function(xhr) { + var data, end, header, i, mime, r, start, urlBlob, _ref; + r = xhr.responseText; + data = new Uint8Array(r.length); + i = 0; + while (i < r.length) { + data[i] = r.charCodeAt(i); + i++; + } + header = xhr.responseHeaders; + start = header.indexOf("Content-Type: ") + 14; + end = header.substr(start, header.length).indexOf("\n") - 1; + mime = header.substr(start, end); + if (mime === null) { + return; + } + urlBlob = new Blob([data], { + type: mime + }); + if (_ref = urlBlob.type, __indexOf.call(QR.mimeTypes, _ref) < 0) { + QR.error("Unsupported file type."); + } + QR.handleFiles([urlBlob]); + return; + return { + onerror: function(xhr) { + return QR.error("Can't load image."); + } + }; + } + }); + }, handleFiles: function(files) { var file, isSingle, max, _i, _len; if (this !== QR) { diff --git a/builds/crx.crx b/builds/crx.crx index aef726bc1..b20e3cd0d 100644 Binary files a/builds/crx.crx and b/builds/crx.crx differ diff --git a/builds/crx/script.js b/builds/crx/script.js index 36379e723..46d0fd92e 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.3.5 - 2014-02-11 +* 4chan X - Version 1.3.5 - 2014-02-12 * * Licensed under the MIT license. * https://github.com/Spittie/4chan-x/blob/master/LICENSE @@ -5474,7 +5474,6 @@ QR.cleanNotifications(); d.activeElement.blur(); $.rmClass(QR.nodes.el, 'dump'); - $.rmClass(QR.nodes.el, 'url'); if (!Conf['Captcha Warning Notifications']) { if (QR.captcha.isEnabled) { $.rmClass(QR.captcha.nodes.input, 'error'); @@ -5691,7 +5690,6 @@ urlBlob = new Blob([this.response], { type: this.getResponseHeader('content-type') }); - console.log(urlBlob.type); if (urlBlob.type === null) { return; } diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index ca4d35918..fea23146e 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -269,18 +269,15 @@ QR = $.addClass QR.nodes.el, 'dump' handleUrl: -> - <% if (type === 'crx') { %> url = prompt("Insert an url:") return if url == null - + <% if (type === 'crx') { %> xhr = new XMLHttpRequest(); xhr.open('GET', url, true) xhr.responseType = 'blob' - xhr.onload = (e) -> if this.readyState == this.DONE && xhr.status == 200 urlBlob = new Blob([this.response], {type : this.getResponseHeader('content-type')}) - console.log(urlBlob.type) return if urlBlob.type == null unless urlBlob.type in QR.mimeTypes QR.error "Unsupported file type." @@ -289,23 +286,43 @@ QR = else QR.error "Can't load image." return - + xhr.onerror = (e) -> QR.error "Can't load image." return - + xhr.send() return <% } %> - <% if (type === 'currently-not-working-userscript') { %> + + <% if (type === 'userscript') { %> GM_xmlhttpRequest { method: "GET", url: url, - responseType: 'blob', + overrideMimeType: "text/plain; charset=x-user-defined", onload: (xhr) -> - urlBlob = new Blob([xhr.response], {type: 'image/png'}) + r = xhr.responseText + data = new Uint8Array(r.length) + i = 0 + while i < r.length + data[i] = r.charCodeAt(i) + i++ + #QUALITY coding at work + header = xhr.responseHeaders + start = header.indexOf("Content-Type: ") + 14 + end = header.substr(start, header.length).indexOf("\n") - 1 + mime = header.substr(start, end) + return if mime is null + + urlBlob = new Blob([data], {type: mime}) + unless urlBlob.type in QR.mimeTypes + QR.error "Unsupported file type." + QR.handleFiles([urlBlob]) return + + onerror: (xhr) -> + QR.error "Can't load image." } return <% } %>