MCPcopy Index your code
hub / github.com/hoothin/UserScripts / downloadImg

Function downloadImg

Picviewer CE+/dist.user.js:13398–13446  ·  view source on GitHub ↗
(url, name, type, over)

Source from the content-addressed store, hash-verified

13396 }
13397
13398 function downloadImg(url, name, type, over) {
13399 if (/^blob:/.test(url)) {
13400 const blob = getBlob(url);
13401 if (blob) {
13402 let ext = blob.type.replace(/.*image\/([\w\-]+).*/, "$1");
13403 if (ext === "none") ext = "png";
13404 try {
13405 saveAs(blob, (prefs.saveNameAddTitle ? document.title.replace(/[\*\/:<>\?\\\|]/g, "") + " - " : "") + getRightSaveName(url, name, type, ext));
13406 over && over();
13407 return;
13408 } catch (e) {
13409 _GM_download(url, name, type);
13410 over && over();
13411 return;
13412 }
13413 }
13414 }
13415 if(canvas && (/^data:/.test(url) || url.split("/")[2] == document.domain)){
13416 urlToBlobWithFetch(url, (blob, ext)=>{
13417 if(!blob){
13418 _GM_download(url, name, type);
13419 over && over();
13420 return;
13421 }
13422 try {
13423 saveAs(blob, (prefs.saveNameAddTitle ? document.title.replace(/[\*\/:<>\?\\\|]/g, "") + " - " : "") + getRightSaveName(url, name, type, ext));
13424 over && over();
13425 } catch(e) {
13426 _GM_download(url, name, type);
13427 over && over();
13428 }
13429 });
13430 } else {
13431 urlToBlob(url, (blob, ext) => {
13432 if(blob){
13433 try {
13434 saveAs(blob, (prefs.saveNameAddTitle ? document.title.replace(/[\*\/:<>\?\\\|]/g, "") + " - " : "") + getRightSaveName(url, name, type, ext));
13435 over && over();
13436 } catch(e) {
13437 _GM_download(url, name, type);
13438 over && over();
13439 }
13440 }else{
13441 _GM_download(url, name, type);
13442 over && over();
13443 }
13444 });
13445 }
13446 }
13447
13448 function getBlob(url) {
13449 return blobUrlMap.get(url) || null;

Callers 4

downloadMulTimesFunction · 0.70
defaultDlFunction · 0.70
initFunction · 0.70
handleMessageFunction · 0.70

Calls 5

overFunction · 0.85
getBlobFunction · 0.70
getRightSaveNameFunction · 0.70
urlToBlobWithFetchFunction · 0.70
urlToBlobFunction · 0.70

Tested by

no test coverage detected