-
Notifications
You must be signed in to change notification settings - Fork 3
/
whitelist.js
118 lines (92 loc) · 3.01 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const buildin_whitelist = [
"gitlab.com",
[ "taobao.com", "alipay.com", "tmall.com", "alibabagroup.com", "aliexpress.com", "alibaba.com", "1688.com", "alimama.com" ],
["apple.com", "cdn-apple.com", "itunes.com"],
["bing.com", "login.live.com", "login.microsoftonline.com"],
["cnki.net", "edu.cn", "szlib.org.cn", "zjlib.cn", "library.hb.cn", "gxlib.org.cn"],
["ixigua.com", "douyin.com", "toutiao.com"],
[
"jlc.com", "szlcsc.com", "lceda.cn", "jlcsmt.com", "oshwhub.com" , "jlc-3dp.cn", "sanweihou.com", "jlc-smt.com", "jlc-gw.com", "jlc-fpc.com", "jlc-bbs.com", "forface3d.com", "jlcfa.com", "jlc-cnc.com", "jlcsj.com", "jlccam.com", "jlcgroup.cn" ,
"jlcpcb.com", "easyeda.com", "jlc3dp.com", "jlcmc.com", "oshwlab.com",
],
];
let whitelist = [];
async function whitelist_init() {
async function get_settings_sync()
{
return ( await browser.storage.sync.get() ) ;
}
if ( ( await get_settings_sync() ) ['enBuildinWhitelist'] !== false)
{
whitelist = whitelist.concat(buildin_whitelist);
}
}
whitelist_init();
function is_whitelisted_single(host)
{
// console.debug("is_whitelisted_single()", host);
if (!host)
return;
for ( ele of whitelist )
{
if ( typeof(ele) === "string" )
{
const str = ele;
if ( host === str || host.endsWith('.'+str) )
{
return true;
}
}
else if ( Array.isArray(ele) )
{
const strArr = ele;
for (subEle of strArr)
{
const str = subEle;
if ( host === str || host.endsWith('.'+str) )
{
return true;
}
}
}
}
}
function is_whitelisted(originHost, targetHost)
{
// console.debug("is_whitelisted()", originHost, targetHost);
if (!originHost || !targetHost)
return;
for ( ele of whitelist )
{
if ( typeof(ele) === "string" )
{
const str = ele;
if (
( originHost === str || originHost.endsWith('.'+str) )
&& (targetHost === str || targetHost.endsWith('.'+str) )
)
{
return true;
}
}
else if ( Array.isArray(ele) )
{
const strArr = ele;
var originW = false;
var targetW = false;
for (str of strArr)
if ( originHost === str || originHost.endsWith('.'+str) )
{
originW = true;
break;
}
if (originW)
for (str of strArr)
if (targetHost === str || targetHost.endsWith('.'+str) )
{
targetW = true;
return true;
}
}
}
}