-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathconfig.js
More file actions
70 lines (66 loc) · 1.98 KB
/
config.js
File metadata and controls
70 lines (66 loc) · 1.98 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
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
const rawConfig = {
"domainWhiteList": [
".ixigua.com",".appinn.com","bimiacg4.net",".dj92cc.net",
".gamersky.com","netflix.",".novipnoad.net",
".olevod.com",".youzhidy.com",".zhihu.com",".zhlhh.com"
],
"useJX": 999,
"jxUrls": [
{"name":"88看","url":"https://vip.sp-flv.com:8443/?url="},
{"name":"咸鱼","url":"https://jx.xyflv.com/?url="},
{"name":"虾米","url":"https://jx.xmflv.com/?url="}
],
"useShaka": false,
"buffSize": 80,
"hlsCache": false,
"autoWebFull": false,
"hostsDisableWF": [".yatu.tv","weixin.qq.com"],
"domainsCleanM3u": [],
"hostsGM": ["kimivod.org"]
};
function promisifyNoFail(thisArg, fnName, outFn = r => r) {
const fn = thisArg[fnName];
return function() {
return new Promise(resolve => {
fn.call(thisArg, ...arguments, function() {
if ( chrome.runtime.lastError instanceof Object ) {
void chrome.runtime.lastError.message;
}
resolve(outFn(...arguments));
});
});
};
}
function promisify(thisArg, fnName) {
const fn = thisArg[fnName];
return function() {
return new Promise((resolve, reject) => {
fn.call(thisArg, ...arguments, function() {
const lastError = chrome.runtime.lastError;
if ( lastError instanceof Object ) {
return reject(lastError.message);
}
resolve(...arguments);
});
});
};
}
const cfg = {
raw: rawConfig,
save: promisify(chrome.storage.sync, 'set'),
read: promisify(chrome.storage.sync, 'get'),
async init() {
const items = await this.read();
if (items?.hostsGM) this.value = items;
else {
// 安装或更新后补齐缺省设置
this.value = {...rawConfig, ...items};
this.save(this.value);
}
}
};
if (chrome.webNavigation) {
cfg.getFrame = promisify(chrome.webNavigation, 'getFrame');
cfg.getAllFrames = promisify(chrome.webNavigation, 'getAllFrames');
}
export default cfg;