-
Notifications
You must be signed in to change notification settings - Fork 0
/
whitelist.js
45 lines (39 loc) · 936 Bytes
/
whitelist.js
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
34
35
36
37
38
39
40
41
42
43
44
45
export class Whitelist {
constructor() {
this.sites = [];
}
async load() {
const data = await chrome.storage.local.get('whitelist');
this.sites = data.whitelist || [];
return this.sites;
}
async save() {
await chrome.storage.local.set({ whitelist: this.sites });
}
async add(site) {
site = this.normalizeSite(site);
if (!this.sites.includes(site)) {
this.sites.push(site);
await this.save();
return true;
}
return false;
}
async remove(site) {
site = this.normalizeSite(site);
const index = this.sites.indexOf(site);
if (index !== -1) {
this.sites.splice(index, 1);
await this.save();
return true;
}
return false;
}
normalizeSite(site) {
return site.replace(/^(https?:\/\/)?(www\.)?/, '').toLowerCase();
}
isWhitelisted(site) {
site = this.normalizeSite(site);
return this.sites.includes(site);
}
}