forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.ts
More file actions
33 lines (30 loc) · 1.1 KB
/
processor.ts
File metadata and controls
33 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { EXCLUDING_PREFIX } from '@util/constant/remain-host'
import { compileAntPattern, judgeVirtualFast } from '@util/pattern'
export default class WhitelistProcessor {
private host: string[] = []
private virtual: RegExp[] = []
private exclude: RegExp[] = []
setWhitelist(whitelist: string[]) {
const host: string[] = []
const virtual: RegExp[] = []
const exclude: RegExp[] = []
whitelist.forEach(white => {
if (!white) return
if (white.startsWith(EXCLUDING_PREFIX)) {
const val = white.substring(1)
exclude.push(compileAntPattern(val))
} else if (judgeVirtualFast(white)) {
virtual.push(compileAntPattern(white))
} else {
host.push(white)
}
})
this.host = host
this.virtual = virtual
this.exclude = exclude
}
contains(host: string, url: string): boolean {
if (this.exclude.some(r => r.test(url))) return false
return this.host.includes(host) || this.virtual.some(r => r.test(url))
}
}