* @param {UIScript} script * @param {number[]} sizes * @param {string} [code]
(script, sizes, code)
| 26 | * @param {string} [code] |
| 27 | */ |
| 28 | function 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 | |
| 63 | export function loadData() { |
| 64 | const id = +store.route.paths[1]; |
no test coverage detected