mirror of
https://github.com/daniel-j/fimfic2epub.git
synced 2024-06-02 10:34:32 +12:00
20 lines
384 B
JavaScript
20 lines
384 B
JavaScript
|
|
export default function fetch (url, cb, type) {
|
|
if (url.indexOf('//') === 0) {
|
|
url = 'http:' + url
|
|
}
|
|
let x = new XMLHttpRequest()
|
|
x.open('get', url, true)
|
|
if (type) {
|
|
x.responseType = type
|
|
}
|
|
x.onload = function () {
|
|
cb(x.response, x.getResponseHeader('content-type'))
|
|
}
|
|
x.onerror = function () {
|
|
console.error('error')
|
|
cb(null)
|
|
}
|
|
x.send()
|
|
}
|