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

Function watchStorage

src/background/utils/storage-cache.js:152–173  ·  view source on GitHub ↗
(fn, cfg, state = true)

Source from the content-addressed store, hash-verified

150});
151
152function watchStorage(fn, cfg, state = true) {
153 if (state && !valuesToWatch) {
154 valuesToWatch = {};
155 }
156 cfg::forEachEntry(([area, ids]) => {
157 const { prefix } = storage[area];
158 for (const id of ensureArray(ids)) {
159 const key = prefix + id;
160 const list = valuesToWatch[key] || state && (valuesToWatch[key] = []);
161 const i = list ? list.indexOf(fn) : -1;
162 if (i >= 0 && !state) {
163 list.splice(i, 1);
164 if (!list.length) delete valuesToWatch[key];
165 } else if (i < 0 && state) {
166 list.push(fn);
167 }
168 }
169 });
170 if (isEmpty(valuesToWatch)) {
171 valuesToWatch = null;
172 }
173}
174
175async function updateScriptSizeContributor(key, val) {
176 const area = sizesPrefixRe.exec(key);

Callers 1

storage-cache.jsFile · 0.85

Calls 2

ensureArrayFunction · 0.90
isEmptyFunction · 0.90

Tested by

no test coverage detected