fimfic2epub/extension/eventPage.js

28 lines
615 B
JavaScript
Raw Normal View History

2016-06-21 19:14:57 +12:00
/* global chrome */
'use strict'
2016-06-21 09:04:08 +12:00
2016-06-21 19:14:57 +12:00
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 () {
console.log(x.getResponseHeader('content-type'))
cb(URL.createObjectURL(x.response), x.getResponseHeader('content-type'))
}
x.onerror = function () {
console.error('error')
cb(null)
}
x.send()
2016-06-21 09:04:08 +12:00
}
2016-06-21 19:14:57 +12:00
chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {
fetch(request, sendResponse, 'blob')
return true
2016-06-21 09:04:08 +12:00
})