* 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)
| 480 | * @return {Promise<{}>} |
| 481 | */ |
| 482 | async 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] |
no test coverage detected