(url, script)
| 184 | * with popular scripts that have lots of @match e.g. Handy Image. |
| 185 | */ |
| 186 | export 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 | |
| 210 | function testRules(url, script, ...list) { |
| 211 | if (curUrl !== url) setContext(url); |
no test coverage detected