Only use workaround for binary data in Greasemonkey versions < 3.2.
This commit is contained in:
parent
948cea6632
commit
d7913e1005
@ -293,6 +293,7 @@ module.exports = (grunt) ->
|
|||||||
GM_addValueChangeListener: true
|
GM_addValueChangeListener: true
|
||||||
GM_openInTab: true
|
GM_openInTab: true
|
||||||
GM_xmlhttpRequest: true
|
GM_xmlhttpRequest: true
|
||||||
|
GM_info: true
|
||||||
cloneInto: true
|
cloneInto: true
|
||||||
chrome: true
|
chrome: true
|
||||||
script: 'tmp-<%= pkg.type %>/*.js'
|
script: 'tmp-<%= pkg.type %>/*.js'
|
||||||
|
|||||||
@ -31,18 +31,22 @@ CrossOrigin = do ->
|
|||||||
cb new Uint8Array(response), contentType, contentDisposition
|
cb new Uint8Array(response), contentType, contentDisposition
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if (type === 'userscript') { %>
|
<% if (type === 'userscript') { %>
|
||||||
GM_xmlhttpRequest
|
# Use workaround for binary data in Greasemonkey versions < 3.2
|
||||||
|
workaround = !GM_info.scriptHandler and /^[12]\.|^3\.[01](?!\d)/.test(GM_info.version)
|
||||||
|
options =
|
||||||
method: "GET"
|
method: "GET"
|
||||||
url: url
|
url: url
|
||||||
headers: headers
|
headers: headers
|
||||||
overrideMimeType: "text/plain; charset=x-user-defined"
|
|
||||||
onload: (xhr) ->
|
onload: (xhr) ->
|
||||||
r = xhr.responseText
|
if workaround
|
||||||
data = new Uint8Array r.length
|
r = xhr.responseText
|
||||||
i = 0
|
data = new Uint8Array r.length
|
||||||
while i < r.length
|
i = 0
|
||||||
data[i] = r.charCodeAt i
|
while i < r.length
|
||||||
i++
|
data[i] = r.charCodeAt i
|
||||||
|
i++
|
||||||
|
else
|
||||||
|
data = new Uint8Array xhr.response
|
||||||
contentType = xhr.responseHeaders.match(/Content-Type:\s*(.*)/i)?[1]
|
contentType = xhr.responseHeaders.match(/Content-Type:\s*(.*)/i)?[1]
|
||||||
contentDisposition = xhr.responseHeaders.match(/Content-Disposition:\s*(.*)/i)?[1]
|
contentDisposition = xhr.responseHeaders.match(/Content-Disposition:\s*(.*)/i)?[1]
|
||||||
cb data, contentType, contentDisposition
|
cb data, contentType, contentDisposition
|
||||||
@ -50,6 +54,11 @@ CrossOrigin = do ->
|
|||||||
cb null
|
cb null
|
||||||
onabort: ->
|
onabort: ->
|
||||||
cb null
|
cb null
|
||||||
|
if workaround
|
||||||
|
options.overrideMimeType = 'text/plain; charset=x-user-defined'
|
||||||
|
else
|
||||||
|
options.responseType = 'arraybuffer'
|
||||||
|
GM_xmlhttpRequest options
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
file: (url, cb) ->
|
file: (url, cb) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user