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

Function initScript

src/options/index.js:28–61  ·  view source on GitHub ↗

* @param {UIScript} script * @param {number[]} sizes * @param {string} [code]

(script, sizes, code)

Source from the content-addressed store, hash-verified

26 * @param {string} [code]
27 */
28function initScript(script, sizes, code) {
29 const $cache = script.$cache ??= {};
30 const { custom, meta } = script;
31 const localeName = getLocaleString(meta, kName);
32 const desc = [
33 meta[kName],
34 localeName,
35 meta[kDescription],
36 getLocaleString(meta, kDescription),
37 custom[kName],
38 custom[kDescription],
39 custom[kComment],
40 ]::trueJoin('\n');
41 const name = custom[kName] || localeName;
42 let total = 0;
43 let str = '';
44 sizes.forEach((val, i) => {
45 total += val;
46 if (val) str += `${SIZE_TITLES[i]}: ${formatByteLength(val)}\n`;
47 });
48 $cache.desc = desc;
49 $cache.name = name;
50 $cache.lowerName = name.toLocaleLowerCase();
51 $cache.size = formatByteLength(total, true).replace(' ', '');
52 $cache.sizes = formatSizesStr(str);
53 $cache.sizeNum = total;
54 $cache.sizesNum = sizes;
55 $cache[kStorageSize] = sizes[2];
56 $cache[kTag] = getUniqTags(script, custom, meta);
57 if (code) $cache.code = code;
58 script.$canUpdate = getScriptUpdateUrl(script)
59 && (script.config.shouldUpdate ? 1 : -1 /* manual */);
60 loadScriptIcon(script, store, true, $cache);
61}
62
63export function loadData() {
64 const id = +store.route.paths[1];

Callers 2

requestDataFunction · 0.85
UpdateScriptFunction · 0.85

Calls 6

getLocaleStringFunction · 0.90
formatByteLengthFunction · 0.90
formatSizesStrFunction · 0.90
getScriptUpdateUrlFunction · 0.90
loadScriptIconFunction · 0.90
getUniqTagsFunction · 0.85

Tested by

no test coverage detected