(function() {
var nativeFetch = window.fetch;
if(nativeFetch) {
var a = document.createElement('a');
window.fetch = function(url) {
a.href = url;
var full_url = a.href;
if(full_url.indexOf('file:') === 0) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
resolve(new Response(xhr.responseText, {status: xhr.status}));
};
xhr.onerror = function(err) {
reject(new TypeError('Local request failed'));
};
xhr.open('GET', url);
xhr.send(null);
});
}
else {
return nativeFetch.call(this, Array.prototype.slice.apply(arguments));
}
};
}
})();