MCPcopy Index your code
hub / github.com/violentmonkey/violentmonkey / getScriptsByURL

Function getScriptsByURL

src/background/utils/db.js:301–392  ·  view source on GitHub ↗
(url, isTop, errors, prevIds)

Source from the content-addressed store, hash-verified

299 * @return {VMInjection.EnvStart | VMInjection.EnvDelayed | Object | void }
300 */
301export function getScriptsByURL(url, isTop, errors, prevIds) {
302 if (testBlacklist(url)) return;
303 const allIds = {};
304 const isDelayed = !errors;
305 /** @type {VMInjection.EnvStart} */
306 let envStart;
307 /** @type {VMInjection.EnvDelayed} */
308 let envDelayed;
309 let clipboardChecked = isDelayed || !IS_FIREFOX;
310 testerBatch(errors || true);
311 for (const script of aliveScripts) {
312 const {
313 config: { enabled },
314 custom,
315 meta,
316 props: { id },
317 } = script;
318 if ((prevIds ? id in prevIds : !enabled)
319 || !((isTop || !(custom.noframes ?? meta.noframes)) && testScript(url, script))) {
320 continue;
321 }
322 if (prevIds) {
323 allIds[id] = enabled ? MORE : 0;
324 continue;
325 }
326 allIds[id] = 1;
327 if (!envStart) {
328 envStart = makeEnv();
329 envDelayed = makeEnv();
330 for (const [areaName, listName] of STORAGE_ROUTES_ENTRIES) {
331 envStart[areaName] = {}; envDelayed[areaName] = {};
332 envStart[listName] = []; envDelayed[listName] = [];
333 }
334 }
335 const { pathMap = buildPathMap(script) } = custom;
336 const runAt = getScriptRunAt(script);
337 const env = runAt === 'start' || runAt === 'body' ? envStart : envDelayed;
338 const { depsMap } = env;
339 env[IDS].push(id);
340 env[RUN_AT][id] = runAt;
341 if (meta.grant.some(GMVALUES_RE.test, GMVALUES_RE)) {
342 env[VALUE_IDS].push(id);
343 }
344 if (!clipboardChecked) {
345 for (const g of meta.grant) {
346 if (!clipboardChecked && (g === 'GM_setClipboard' || g === 'GM.setClipboard')) {
347 clipboardChecked = envStart.clipFF = true;
348 }
349 }
350 }
351 for (const [list, name, dataUriDecoder] of [
352 [meta.require, S_REQUIRE, dataUri2text],
353 [Object.values(meta.resources), S_CACHE],
354 ]) {
355 const listName = STORAGE_ROUTES[name];
356 const envCheck = name === S_CACHE ? envStart : env; // envStart cache is reused in injected
357 // eslint-disable-next-line no-shadow
358 for (let url of list) {

Callers 4

augmentSetPopupFunction · 0.90
InjectionFeedbackFunction · 0.90
prepareFunction · 0.90
GetMoreIdsFunction · 0.85

Calls 7

testerBatchFunction · 0.90
testScriptFunction · 0.90
getScriptRunAtFunction · 0.90
makePauseFunction · 0.90
makeEnvFunction · 0.85
buildPathMapFunction · 0.85
readEnvironmentDataFunction · 0.85

Tested by

no test coverage detected