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

Function getResource

src/injected/web/gm-api.js:233–248  ·  view source on GitHub ↗

* @param {GMContext} context * @param name * @param isBlob * @param isBlobAuto

(context, name, isBlob, isBlobAuto)

Source from the content-addressed store, hash-verified

231 * @param isBlobAuto
232 */
233function getResource(context, name, isBlob, isBlobAuto) {
234 let res;
235 const { id, resCache, resources } = context;
236 const key = resources[name];
237 if (key) {
238 // data URIs aren't cached in bridge, so we'll send them
239 const isData = key::slice(0, 5) === 'data:';
240 const bucketKey = isBlob == null ? 0 : 1 + (isBlob = isBlobAuto ? !isData : isBlob);
241 res = isData && isBlob === false || ensureNestedProp(resCache, bucketKey, key, false);
242 if (!res) {
243 res = bridge.call('GetResource', { id, isBlob, key, raw: isData && key });
244 ensureNestedProp(resCache, bucketKey, key, res);
245 }
246 }
247 return resolveOrReturn(context, res === true ? key : res);
248}
249
250function findCommandIdByText(text, hub) {
251 for (const id in hub) {

Callers 2

GM_getResourceTextFunction · 0.85
gm-api.jsFile · 0.85

Calls 2

ensureNestedPropFunction · 0.85
resolveOrReturnFunction · 0.85

Tested by

no test coverage detected