Fixes, better code(?)

This commit is contained in:
Kabir Sala 2014-02-13 18:28:09 +01:00
parent cff413769e
commit af2589d0e2
6 changed files with 39 additions and 26 deletions

View File

@ -1,5 +1,5 @@
/* /*
* 4chan X - Version 1.3.5 - 2014-02-12 * 4chan X - Version 1.3.5 - 2014-02-13
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE * https://github.com/Spittie/4chan-x/blob/master/LICENSE

View File

@ -23,7 +23,7 @@
// ==/UserScript== // ==/UserScript==
/* /*
* 4chan X - Version 1.3.5 - 2014-02-12 * 4chan X - Version 1.3.5 - 2014-02-13
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE * https://github.com/Spittie/4chan-x/blob/master/LICENSE
@ -5663,6 +5663,16 @@
QR.handleFiles(files); QR.handleFiles(files);
return $.addClass(QR.nodes.el, 'dump'); return $.addClass(QR.nodes.el, 'dump');
}, },
handleBlob: function(blob) {
var _ref;
if (blob.type === null) {
return QR.error("Unsupported file type.");
}
if (_ref = blob.type, __indexOf.call(QR.mimeTypes, _ref) < 0) {
return QR.error("Unsupported file type.");
}
return QR.handleFiles([blob]);
},
handleUrl: function() { handleUrl: function() {
var url; var url;
url = prompt("Insert an url:"); url = prompt("Insert an url:");
@ -5674,7 +5684,7 @@
url: url, url: url,
overrideMimeType: "text/plain; charset=x-user-defined", overrideMimeType: "text/plain; charset=x-user-defined",
onload: function(xhr) { onload: function(xhr) {
var data, end, header, i, mime, r, start, urlBlob, _ref; var data, end, header, i, mime, r, start, urlBlob;
r = xhr.responseText; r = xhr.responseText;
data = new Uint8Array(r.length); data = new Uint8Array(r.length);
i = 0; i = 0;
@ -5692,11 +5702,8 @@
urlBlob = new Blob([data], { urlBlob = new Blob([data], {
type: mime type: mime
}); });
if (_ref = urlBlob.type, __indexOf.call(QR.mimeTypes, _ref) < 0) {
QR.error("Unsupported file type.");
}
urlBlob.name = url.substr(url.lastIndexOf('/') + 1, url.length); urlBlob.name = url.substr(url.lastIndexOf('/') + 1, url.length);
QR.handleFiles([urlBlob]); QR.handleBlob(urlBlob);
return; return;
return { return {
onerror: function(xhr) { onerror: function(xhr) {
@ -6176,7 +6183,7 @@
placeholder: 'Focus to load reCAPTCHA', placeholder: 'Focus to load reCAPTCHA',
autocomplete: 'off', autocomplete: 'off',
spellcheck: false, spellcheck: false,
tabIndex: 55 tabIndex: 45
}); });
this.nodes = { this.nodes = {
img: imgContainer.firstChild, img: imgContainer.firstChild,

Binary file not shown.

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript // Generated by CoffeeScript
/* /*
* 4chan X - Version 1.3.5 - 2014-02-12 * 4chan X - Version 1.3.5 - 2014-02-13
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE * https://github.com/Spittie/4chan-x/blob/master/LICENSE
@ -5675,6 +5675,16 @@
QR.handleFiles(files); QR.handleFiles(files);
return $.addClass(QR.nodes.el, 'dump'); return $.addClass(QR.nodes.el, 'dump');
}, },
handleBlob: function(blob) {
var _ref;
if (blob.type === null) {
return QR.error("Unsupported file type.");
}
if (_ref = blob.type, __indexOf.call(QR.mimeTypes, _ref) < 0) {
return QR.error("Unsupported file type.");
}
return QR.handleFiles([blob]);
},
handleUrl: function() { handleUrl: function() {
var url, xhr; var url, xhr;
url = prompt("Insert an url:"); url = prompt("Insert an url:");
@ -5685,19 +5695,13 @@
xhr.open('GET', url, true); xhr.open('GET', url, true);
xhr.responseType = 'blob'; xhr.responseType = 'blob';
xhr.onload = function(e) { xhr.onload = function(e) {
var urlBlob, _ref; var urlBlob;
if (this.readyState === this.DONE && xhr.status === 200) { if (this.readyState === this.DONE && xhr.status === 200) {
urlBlob = new Blob([this.response], { urlBlob = new Blob([this.response], {
type: this.getResponseHeader('content-type') type: this.getResponseHeader('content-type')
}); });
if (urlBlob.type === null) {
return;
}
if (_ref = urlBlob.type, __indexOf.call(QR.mimeTypes, _ref) < 0) {
QR.error("Unsupported file type.");
}
urlBlob.name = url.substr(url.lastIndexOf('/') + 1, url.length); urlBlob.name = url.substr(url.lastIndexOf('/') + 1, url.length);
QR.handleFiles([urlBlob]); QR.handleBlob(urlBlob);
} else { } else {
QR.error("Can't load image."); QR.error("Can't load image.");
} }
@ -6166,7 +6170,7 @@
placeholder: 'Focus to load reCAPTCHA', placeholder: 'Focus to load reCAPTCHA',
autocomplete: 'off', autocomplete: 'off',
spellcheck: false, spellcheck: false,
tabIndex: 55 tabIndex: 45
}); });
this.nodes = { this.nodes = {
img: imgContainer.firstChild, img: imgContainer.firstChild,

View File

@ -17,7 +17,7 @@ QR.captcha =
placeholder: 'Focus to load reCAPTCHA' placeholder: 'Focus to load reCAPTCHA'
autocomplete: 'off' autocomplete: 'off'
spellcheck: false spellcheck: false
tabIndex: 55 tabIndex: 45
@nodes = @nodes =
img: imgContainer.firstChild img: imgContainer.firstChild
input: input input: input

View File

@ -267,6 +267,13 @@ QR =
QR.open() QR.open()
QR.handleFiles files QR.handleFiles files
$.addClass QR.nodes.el, 'dump' $.addClass QR.nodes.el, 'dump'
handleBlob: (blob) ->
return if blob.type is null
QR.error "Unsupported file type."
return unless blob.type in QR.mimeTypes
QR.error "Unsupported file type."
QR.handleFiles([blob])
handleUrl: -> handleUrl: ->
url = prompt("Insert an url:") url = prompt("Insert an url:")
@ -278,11 +285,8 @@ QR =
xhr.onload = (e) -> xhr.onload = (e) ->
if @readyState is @DONE && xhr.status is 200 if @readyState is @DONE && xhr.status is 200
urlBlob = new Blob([@response], {type : @getResponseHeader('content-type')}) urlBlob = new Blob([@response], {type : @getResponseHeader('content-type')})
return if urlBlob.type is null
unless urlBlob.type in QR.mimeTypes
QR.error "Unsupported file type."
urlBlob.name = url.substr(url.lastIndexOf('/')+1, url.length) urlBlob.name = url.substr(url.lastIndexOf('/')+1, url.length)
QR.handleFiles([urlBlob]) QR.handleBlob(urlBlob)
return return
else else
QR.error "Can't load image." QR.error "Can't load image."
@ -316,11 +320,9 @@ QR =
return if mime is null return if mime is null
urlBlob = new Blob([data], {type: mime}) urlBlob = new Blob([data], {type: mime})
unless urlBlob.type in QR.mimeTypes
QR.error "Unsupported file type."
urlBlob.name = url.substr(url.lastIndexOf('/')+1, url.length) urlBlob.name = url.substr(url.lastIndexOf('/')+1, url.length)
QR.handleFiles([urlBlob]) QR.handleBlob(urlBlob)
return return
onerror: (xhr) -> onerror: (xhr) ->