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

Function testScript

src/background/utils/tester.js:186–208  ·  view source on GitHub ↗
(url, script)

Source from the content-addressed store, hash-verified

184 * with popular scripts that have lots of @match e.g. Handy Image.
185 */
186export function testScript(url, script) {
187 let matex1; // main @match / @exclude-match
188 let matex2; // custom @match / @exclude-match
189 let inex1; // main @include / @exclude
190 let inex2; // custom @include / @exclude
191 const { custom, meta } = script;
192 const len = (matex1 = custom.origMatch && meta.match || '').length
193 + (matex2 = custom.match || '').length
194 + (inex1 = custom.origInclude && meta.include || '').length
195 + (inex2 = custom.include || '').length;
196 const ok = (
197 // Ok if lists are empty or @match + @include apply
198 !len || testRules(url, script, matex1, matex2, inex1, inex2)
199 ) && !(
200 // and no excludes apply
201 ((matex1 = custom.origExcludeMatch && meta.excludeMatch || '').length
202 + (matex2 = custom.excludeMatch || '').length
203 + (inex1 = custom.origExclude && meta.exclude || '').length
204 + (inex2 = custom.exclude || '').length
205 ) && testRules(url, script, matex1, matex2, inex1, inex2)
206 );
207 return ok;
208}
209
210function testRules(url, script, ...list) {
211 if (curUrl !== url) setContext(url);

Callers 5

tester.test.jsFile · 0.90
getScriptsByURLFunction · 0.90
parseMetaWithErrorsFunction · 0.90
reloadTabForScriptFunction · 0.90
checkCookieOptsFunction · 0.90

Calls 1

testRulesFunction · 0.85

Tested by

no test coverage detected