MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / getIconCache

Function getIconCache

src/background/utils/db.js:482–506  ·  view source on GitHub ↗

* Returns only own icon and the already cached icons. * The rest are prefetched in background and will be used by loadScriptIcon. * @param {VMScript[]} scripts * @return {Promise<{}>}

(scripts)

Source from the content-addressed store, hash-verified

480 * @return {Promise<{}>}
481 */
482async function getIconCache(scripts) {
483 // data uri for own icon to load it instantly in Chrome when there are many images
484 const toGet = [`${ICON_PREFIX}38.png`];
485 const toPrime = [];
486 const res = {};
487 for (let { custom, meta } of scripts) {
488 let icon = custom.icon || meta.icon;
489 if (isValidHttpUrl(icon)) {
490 icon = custom.pathMap[icon] || icon;
491 toGet.push(icon);
492 if (!storageCacheHas(S_CACHE_PRE + icon)) toPrime.push(icon);
493 }
494 }
495 if (toPrime.length) {
496 await storage[S_CACHE].getMulti(toPrime);
497 }
498 for (let i = 0, d, url; i < toGet.length; i++) {
499 url = toGet[i];
500 d = getImageData(url);
501 if (!isObject(d) || !i && (d = await d)) {
502 res[url] = d;
503 }
504 }
505 return res;
506}
507
508/**
509 * @param {number[]} [ids]

Callers 1

getDataFunction · 0.85

Calls 4

isValidHttpUrlFunction · 0.90
getImageDataFunction · 0.90
isObjectFunction · 0.85
getMultiMethod · 0.80

Tested by

no test coverage detected