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

Function loadScriptIcon

src/common/load-script-icon.js:14–39  ·  view source on GitHub ↗
(script, store, showDefault, target = script)

Source from the content-addressed store, hash-verified

12 * @param {object} [target]
13 */
14export async function loadScriptIcon(script, store, showDefault, target = script) {
15 let def;
16 let res = target[KEY];
17 const { icon: customIcon, pathMap } = script.custom || {};
18 const icon = customIcon || script.meta.icon;
19 const { cache = {}, isHiDPI } = store || {};
20 const url = pathMap?.[icon] || icon || showDefault && (
21 def = `${ICON_PREFIX}${isHiDPI && 128 || (script.config.removed ? 32 : 38)}.png`
22 );
23 if (!url || url !== res) {
24 // exposing scripts with no icon for user's CustomCSS
25 target[KEY_DEFAULT] = def ? '' : null;
26 // creates an observable property so Vue will see the change after `await`
27 if (!(KEY in target)) {
28 target[KEY] = null;
29 }
30 if (url) {
31 target[KEY] = res = cache[url]
32 || isDataUri(url) && url
33 || isHiDPI && def // Using our big icon directly as its data URI is rendered slower
34 || (def || isValidHttpUrl(url))
35 && (cache[url] = await sendCmdDirectly('GetImageData', url).catch(noop));
36 }
37 }
38 return res;
39}
40
41/**
42 * Sets script's safeIcon property after the image is successfully loaded

Callers 2

initScriptFunction · 0.90
setPopupFunction · 0.90

Calls 2

isValidHttpUrlFunction · 0.90
sendCmdDirectlyFunction · 0.90

Tested by

no test coverage detected