MCPcopy
hub / github.com/hoothin/UserScripts / urlToBlobWithFetch

Function urlToBlobWithFetch

Picviewer CE+/dist.user.js:12401–12431  ·  view source on GitHub ↗
(urlString, cb)

Source from the content-addressed store, hash-verified

12399 img.src = dataurl;
12400 }
12401 function urlToBlobWithFetch(urlString, cb){
12402 fetch(urlString).then(response => response.blob()).then(blob => {
12403 let ext = extFromMimeAndUrl(blob.type, urlString);
12404 if (blob.type && blob.type.indexOf("text/html") === 0 && (blob.size || 0) < 1000) return cb(null, '');
12405 if (ext === "none") ext = "webp";
12406 let conversion = formatDict.get(ext);
12407 if (canvas && conversion) {
12408 var self = this;
12409 var a = new FileReader();
12410 a.readAsDataURL(blob);
12411 a.onload = function (e) {
12412 dataURLToCanvas(e.target.result, canvas => {
12413 canvas.toBlob(nblob => {
12414 if (!nblob) {
12415 cb(blob);
12416 } else {
12417 cb(nblob, conversion || "png");
12418 }
12419 }, "image/" + (conversion || "png"));
12420 });
12421 };
12422 a.onerror = function (e){
12423 cb(blob);
12424 }
12425 } else {
12426 cb(blob, ext);
12427 }
12428 }).catch(error => {
12429 cb(null);
12430 });
12431 }
12432 function loadVideoJsLibrary() {
12433 if (!window.videoJsStatus) {
12434 window.videoJsStatus = 'none';

Callers 3

urlToBlobFunction · 0.70
downloadImgFunction · 0.70
downloadOneFunction · 0.70

Calls 3

fetchFunction · 0.85
extFromMimeAndUrlFunction · 0.70
dataURLToCanvasFunction · 0.70

Tested by

no test coverage detected