(s: string)
| 25 | // 检查 @match @include @exclude 是否按照MV3的 match pattern |
| 26 | // export 只用于测试,不要在外部直接引用 checkUrlMatch |
| 27 | export const checkUrlMatch = (s: string): string[] | null => { |
| 28 | s = s.trim(); |
| 29 | |
| 30 | const idx1 = s.indexOf("://"); |
| 31 | let idx2 = -1; |
| 32 | if (idx1 > 0) { |
| 33 | idx2 = s.indexOf("/", idx1 + 3); |
| 34 | } |
| 35 | let extMatch: string[] | null = null; |
| 36 | // 存在://和/才进行处理 |
| 37 | if (idx1 > 0 && idx2 > 0) { |
| 38 | const scheme = s.substring(0, idx1); |
| 39 | // 检查scheme |
| 40 | if (/^(\*|[-a-z]+)$/.test(scheme)) { |
| 41 | let host = s.substring(idx1 + 3, idx2); |
| 42 | if (host.length === 0 && scheme !== "file") { |
| 43 | // host is optional only if the scheme is "file". |
| 44 | } else if (!host.includes(":") && host.charAt(0) !== "." && !host.includes("?")) { |
| 45 | // *.<host> |
| 46 | if (/^(\*|\*\..+)$/.test(host)) { |
| 47 | host = host.substring(1); |
| 48 | } |
| 49 | if (!host.includes("*")) { |
| 50 | const pathPattern = s.substring(idx2 + 1); |
| 51 | extMatch = [scheme, host, pathPattern]; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | return extMatch; |
| 57 | }; |
| 58 | |
| 59 | const globSplit = (text: string): string[] => { |
| 60 | const split = text.split(/([*?]{2,})/g); |
no outgoing calls
no test coverage detected