sinzmise-cetastories 2.0.0-1731114112124 → 2.0.0-1731114615672
Sign up to get free protection for your applications and to get access to all the features.
- package/404/index.html +1 -4033
- package/about/index.html +1 -4041
- package/album/index.html +1 -4050
- package/archives/2021/12/index.html +1 -3917
- package/archives/2021/index.html +1 -3917
- package/archives/2022/12/index.html +1 -3917
- package/archives/2022/index.html +1 -3917
- package/archives/2023/01/index.html +1 -4072
- package/archives/2023/02/index.html +1 -3917
- package/archives/2023/03/index.html +1 -4063
- package/archives/2023/04/index.html +1 -3992
- package/archives/2023/07/index.html +1 -4217
- package/archives/2023/08/index.html +1 -4067
- package/archives/2023/09/index.html +1 -3917
- package/archives/2023/10/index.html +1 -3917
- package/archives/2023/11/index.html +1 -3917
- package/archives/2023/12/index.html +1 -3918
- package/archives/2023/index.html +1 -4591
- package/archives/2023/page/2/index.html +1 -4572
- package/archives/2023/page/3/index.html +1 -3930
- package/archives/2024/01/index.html +1 -4142
- package/archives/2024/02/index.html +1 -3922
- package/archives/2024/03/index.html +1 -3916
- package/archives/2024/04/index.html +1 -3997
- package/archives/2024/05/index.html +1 -4065
- package/archives/2024/06/index.html +1 -3917
- package/archives/2024/07/index.html +1 -3917
- package/archives/2024/08/index.html +1 -3992
- package/archives/2024/09/index.html +1 -3917
- package/archives/2024/10/index.html +1 -3984
- package/archives/2024/index.html +1 -4576
- package/archives/2024/page/2/index.html +1 -4433
- package/archives/index.html +1 -4560
- package/archives/page/2/index.html +1 -4560
- package/archives/page/3/index.html +1 -4560
- package/archives/page/4/index.html +1 -4560
- package/archives/page/5/index.html +1 -4560
- package/assets/algolia/algoliasearch.js +3 -7182
- package/assets/algolia/algoliasearchLite.js +3 -4445
- package/atom.xml +31 -31
- package/bbs/bbs.html +1 -4012
- package/bbs/bbs.js +2 -12
- package/bbs/index.html +1 -4031
- package/categories/index.html +1 -4050
- package/categories//344/270/252/344/272/272/345/260/217/350/256/260/index.html +1 -4570
- package/categories//344/270/252/344/272/272/345/260/217/350/256/260/page/2/index.html +1 -4485
- package/categories//346/255/214/346/233/262/346/224/266/351/233/206/index.html +1 -3920
- package/categories//346/270/270/346/210/217/347/233/270/345/205/263/index.html +1 -4148
- package/categories//347/253/231/347/202/271/346/212/230/350/205/276/index.html +1 -4610
- package/categories//347/253/231/347/202/271/346/212/230/350/205/276/page/2/index.html +1 -4148
- package/categories//351/241/271/347/233/256/346/212/230/350/205/276/index.html +1 -4072
- package/charts/index.html +1 -4039
- package/comments/index.html +1 -4052
- package/css/custom2.css +2 -3
- package/css/first.css +2 -1868
- package/css/pace/big-counter.css +2 -39
- package/css/pace/corner-indicator.css +2 -72
- package/css/pace/flash.css +2 -76
- package/css/pace/mac-osx.css +2 -86
- package/css/pace/pace.css +2 -50
- package/css/plane.css +2 -59
- package/css/style.css +2 -8585
- package/css/tags.css +2 -3516
- package/essay/index.html +1 -4050
- package/fcircle/index.html +1 -4075
- package/games +2 -2
- package/index.html +1 -4717
- package/js/app.js +2 -1341
- package/js/autoload.js +2 -62
- package/js/ceta/fancybox.css +2 -2
- package/js/ceta/fancybox.umd.js +2 -2
- package/js/ceta/iconfontInkss.js +2 -1
- package/js/ceta/message.css +2 -6
- package/js/ceta/message.js +2 -6
- package/js/clock.js +2 -1
- package/js/kslink.js +2 -38
- package/js/newyear.js +2 -76
- package/js/plane.js +2 -2200
- package/js/plugins/aplayer.js +2 -186
- package/js/plugins/parallax.js +2 -191
- package/js/plugins/rightMenus.js +2 -623
- package/js/plugins/tags/contributors.js +2 -92
- package/js/plugins/tags/friends.js +2 -93
- package/js/plugins/tags/sites.js +2 -96
- package/js/search/algolia.js +2 -239
- package/js/search/hexo.js +2 -195
- package/js/search/meilisearch.js +2 -220
- package/js/txmap.js +2 -248
- package/link/index.html +1 -6180
- package/load.html +1 -294
- package/maps/assets/algolia/algoliasearch.js.map +1 -0
- package/maps/assets/algolia/algoliasearchLite.js.map +1 -0
- package/maps/bbs/bbs.js.map +1 -0
- package/maps/css/custom2.css.map +1 -0
- package/maps/css/first.css.map +1 -0
- package/maps/css/pace/big-counter.css.map +1 -0
- package/maps/css/pace/corner-indicator.css.map +1 -0
- package/maps/css/pace/flash.css.map +1 -0
- package/maps/css/pace/mac-osx.css.map +1 -0
- package/maps/css/pace/pace.css.map +1 -0
- package/maps/css/plane.css.map +1 -0
- package/maps/css/style.css.map +1 -0
- package/maps/css/tags.css.map +1 -0
- package/maps/js/app.js.map +1 -0
- package/maps/js/autoload.js.map +1 -0
- package/maps/js/ceta/fancybox.css.map +1 -0
- package/maps/js/ceta/fancybox.umd.js.map +1 -0
- package/maps/js/ceta/iconfontInkss.js.map +1 -0
- package/maps/js/ceta/message.css.map +1 -0
- package/maps/js/ceta/message.js.map +1 -0
- package/maps/js/clock.js.map +1 -0
- package/maps/js/kslink.js.map +1 -0
- package/maps/js/newyear.js.map +1 -0
- package/maps/js/plane.js.map +1 -0
- package/maps/js/plugins/aplayer.js.map +1 -0
- package/maps/js/plugins/parallax.js.map +1 -0
- package/maps/js/plugins/rightMenus.js.map +1 -0
- package/maps/js/plugins/tags/contributors.js.map +1 -0
- package/maps/js/plugins/tags/friends.js.map +1 -0
- package/maps/js/plugins/tags/sites.js.map +1 -0
- package/maps/js/search/algolia.js.map +1 -0
- package/maps/js/search/hexo.js.map +1 -0
- package/maps/js/search/meilisearch.js.map +1 -0
- package/maps/js/txmap.js.map +1 -0
- package/maps/sw.js.map +1 -0
- package/maps/weichuncai/css/style.css.map +1 -0
- package/maps/weichuncai/js/common.js.map +1 -0
- package/maps/weichuncai/js/jquery.js.map +1 -0
- package/maps/weichuncai/wcc-config.js.map +1 -0
- package/music/index.html +1 -4033
- package/package.json +1 -1
- package/page/2/index.html +1 -4578
- package/page/3/index.html +1 -4575
- package/page/4/index.html +1 -4572
- package/page/5/index.html +1 -3924
- package/posts/10021/index.html +5 -4130
- package/posts/10045/index.html +1 -4224
- package/posts/10733/index.html +1 -4125
- package/posts/10996/index.html +5 -4127
- package/posts/12779/index.html +1 -4134
- package/posts/13624/index.html +1 -4179
- package/posts/15688/index.html +1 -4133
- package/posts/15748/index.html +5 -4121
- package/posts/15799/index.html +1 -4130
- package/posts/15842/index.html +5 -4121
- package/posts/16107/index.html +1 -4111
- package/posts/18063/index.html +1 -4124
- package/posts/20412/index.html +1 -4134
- package/posts/21375/index.html +1 -4124
- package/posts/22945/index.html +4 -4169
- package/posts/23021/index.html +1 -4104
- package/posts/27531/index.html +5 -4121
- package/posts/28536/index.html +1 -4116
- package/posts/28733/index.html +1 -4168
- package/posts/29196/index.html +1 -4106
- package/posts/38917/index.html +1 -4144
- package/posts/38964/index.html +1 -4208
- package/posts/42487/index.html +1 -4135
- package/posts/42580/index.html +1 -4128
- package/posts/45875/index.html +1 -4118
- package/posts/46640/index.html +1 -4147
- package/posts/48762/index.html +1 -4109
- package/posts/50710/index.html +1 -4114
- package/posts/52677/index.html +1 -4125
- package/posts/53662/index.html +1 -4123
- package/posts/54386/index.html +1 -4116
- package/posts/54481/index.html +1 -4133
- package/posts/54787/index.html +5 -4124
- package/posts/56467/index.html +1 -4121
- package/posts/57692/index.html +1 -4143
- package/posts/58203/index.html +1 -4116
- package/posts/61417/index.html +1 -4117
- package/posts/61712/index.html +1 -4113
- package/posts/646/index.html +1 -4106
- package/posts/64856/index.html +1 -4120
- package/posts/64935/index.html +1 -4120
- package/search.xml +95 -95
- package/seas/index.html +1 -4050
- package/sw.js +2 -798
- package/tags/Flash/347/233/270/345/205/263/index.html +1 -3924
- package/tags/Steam/346/270/270/346/210/217/index.html +1 -3924
- package/tags/Windows/350/275/257/344/273/266/index.html +1 -3997
- package/tags/index.html +1 -4033
- package/tags//344/270/252/344/272/272/345/260/217/350/256/260/index.html +1 -4570
- package/tags//344/270/252/344/272/272/345/260/217/350/256/260/page/2/index.html +1 -4485
- package/tags//345/205/266/345/256/203/346/270/270/346/210/217/index.html +1 -4073
- package/tags//345/212/240/350/275/275/345/212/250/347/224/273/index.html +1 -3924
- package/tags//346/202/254/346/265/256/345/256/240/347/211/251-/347/234/213/346/235/277/345/250/230/index.html +1 -3925
- package/tags//346/255/214/346/233/262/346/224/266/351/233/206/index.html +1 -3920
- package/tags//346/270/270/346/210/217/347/233/270/345/205/263/index.html +1 -4148
- package/tags//347/253/231/347/202/271/345/272/225/351/203/250/351/255/224/346/224/271/index.html +1 -3924
- package/tags//347/253/231/347/202/271/346/212/230/350/205/276/index.html +1 -4610
- package/tags//347/253/231/347/202/271/346/212/230/350/205/276/page/2/index.html +1 -4148
- package/tags//350/207/252/345/273/272/351/203/250/347/275/262/index.html +1 -4224
- package/tags//351/241/265/351/235/242/351/255/224/346/224/271/index.html +1 -4075
- package/tags//351/241/271/347/233/256/346/212/230/350/205/276/index.html +1 -4072
- package/update/index.html +1 -4112
- package/weichuncai/css/style.css +2 -25
- package/weichuncai/js/common.js +2 -449
- package/weichuncai/js/jquery.js +2 -139
- package/weichuncai/wcc-config.js +2 -17
package/sw.js
CHANGED
@@ -1,798 +1,2 @@
|
|
1
|
-
// 全站打包上传 npm,sw 并发请求 cdn
|
2
|
-
|
3
|
-
const cacheSuffixVersion = '00000018-0.5481051434706005';
|
4
|
-
const CACHE_NAME = prefix + '-v' + cacheSuffixVersion;
|
5
|
-
const PreCachlist = [
|
6
|
-
"/css/style.css",
|
7
|
-
"/js/app.js",
|
8
|
-
"/js/search/hexo.js",
|
9
|
-
];
|
10
|
-
let NPMMirror = true;
|
11
|
-
const NPMPackage = "sinzmise-cetastories";
|
12
|
-
let NPMPackageVersion = "latest";
|
13
|
-
let debug = true;
|
14
|
-
// location.hostname == 'localhost' && (debug = true) && (NPMMirror = false);
|
15
|
-
const handleFetch = async (event) => {
|
16
|
-
const url = event.request.url;
|
17
|
-
if (/nocache/.test(url)) {
|
18
|
-
return NetworkOnly(event)
|
19
|
-
} else if (/@latest/.test(url)) {
|
20
|
-
return CacheFirst(event)
|
21
|
-
} else if (/cdnjs\.cloudflare\.com/.test(url)) {
|
22
|
-
return CacheAlways(event)
|
23
|
-
} else if (/music\.126\.net/.test(url)) {
|
24
|
-
return CacheAlways(event)
|
25
|
-
} else if (/qqmusic\.qq\.com/.test(url)) {
|
26
|
-
return CacheAlways(event)
|
27
|
-
} else if (/jsdelivr\.net/.test(url)) {
|
28
|
-
return CacheAlways(event)
|
29
|
-
} else if (/npm\.elemecdn\.com/.test(url)) {
|
30
|
-
return CacheAlways(event)
|
31
|
-
} else if (/unpkg\.com/.test(url)) {
|
32
|
-
return CacheAlways(event)
|
33
|
-
} else if (/.*\.(?:png|jpg|jpeg|svg|gif|webp|ico|eot|ttf|woff|woff2|mp3)$/.test(url)) {
|
34
|
-
return CacheAlways(event)
|
35
|
-
} else if (/.*\.(css|js)$/.test(url)) {
|
36
|
-
return CacheAlways(event)
|
37
|
-
} else {
|
38
|
-
return CacheFirst(event)
|
39
|
-
}
|
40
|
-
}
|
41
|
-
const cdn = {
|
42
|
-
gh: {
|
43
|
-
jsdelivr: 'https://kkgithub.com/extdomains/cdn.jsdelivr.net/gh',
|
44
|
-
fastly: 'https://fastly.jsdelivr.net/gh',
|
45
|
-
gcore: 'https://gcore.jsdelivr.net/gh',
|
46
|
-
testingcf: 'https://testingcf.jsdelivr.net/gh',
|
47
|
-
test1: 'https://test1.jsdelivr.net/gh',
|
48
|
-
},
|
49
|
-
combine: {
|
50
|
-
jsdelivr: 'https://kkgithub.com/extdomains/cdn.jsdelivr.net/combine',
|
51
|
-
fastly: 'https://fastly.jsdelivr.net/combine',
|
52
|
-
gcore: 'https://gcore.jsdelivr.net/combine',
|
53
|
-
testingcf: 'https://testingcf.jsdelivr.net/combine',
|
54
|
-
test1: 'https://test1.jsdelivr.net/combine',
|
55
|
-
},
|
56
|
-
npm: {
|
57
|
-
jsdelivr: 'https://kkgithub.com/extdomains/cdn.jsdelivr.net/npm',
|
58
|
-
fastly: 'https://fastly.jsdelivr.net/npm',
|
59
|
-
gcore: 'https://gcore.jsdelivr.net/npm',
|
60
|
-
testingcf: 'https://testingcf.jsdelivr.net/npm',
|
61
|
-
test1: 'https://test1.jsdelivr.net/npm',
|
62
|
-
unpkg: 'https://unpkg.com',
|
63
|
-
eleme: 'https://npm.elemecdn.com',
|
64
|
-
storisinz: 'https://jsd.cdn.storisinz.site/npm',
|
65
|
-
webcache: 'https://npm.webcache.cn',
|
66
|
-
},
|
67
|
-
cdnjs: {
|
68
|
-
cdnjs: 'https://kkgithub.com/extdomains/cdnjs.cloudflare.com/ajax/libs',
|
69
|
-
baomitu: 'https://lib.baomitu.com',
|
70
|
-
bootcdn: 'https://cdn.bootcdn.net/ajax/libs',
|
71
|
-
bytedance: 'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M',
|
72
|
-
sustech: 'https://mirrors.sustech.edu.cn/cdnjs/ajax/libs',
|
73
|
-
}
|
74
|
-
}
|
75
|
-
const cdn_match_list = []
|
76
|
-
for (const type in cdn) {
|
77
|
-
for (const key in cdn[type]) {
|
78
|
-
cdn_match_list.push({ type: type, key: cdn[type][key] })
|
79
|
-
}
|
80
|
-
}
|
81
|
-
const _console = console;
|
82
|
-
const color = {
|
83
|
-
black: '#000000',
|
84
|
-
red: '#FF0000',
|
85
|
-
green: '#008000',
|
86
|
-
yellow: '#FFFF00',
|
87
|
-
blue: '#0000FF',
|
88
|
-
magenta: '#FF00FF',
|
89
|
-
cyan: '#00FFFF',
|
90
|
-
white: '#FFFFFF',
|
91
|
-
};
|
92
|
-
const add = (...arr) => {
|
93
|
-
let fi = [
|
94
|
-
[]
|
95
|
-
];
|
96
|
-
for (let key = 0; key < arr.length; key++) {
|
97
|
-
const [first, ...other] = arr[key];
|
98
|
-
fi[0] += first;
|
99
|
-
fi = fi.concat(other);
|
100
|
-
}
|
101
|
-
return fi;
|
102
|
-
};
|
103
|
-
const createlog = (util) => (...args) => {
|
104
|
-
// const fun = _console[util] ? _console[util] : _console.log;
|
105
|
-
const fun = util == "error" ? _console[util] : _console.log;
|
106
|
-
fun.apply(void 0, args);
|
107
|
-
};
|
108
|
-
const creategroup = (util) => (...args) => {
|
109
|
-
const fun = _console.groupCollapsed;
|
110
|
-
fun.apply(void 0, args);
|
111
|
-
};
|
112
|
-
const colorUtils = {
|
113
|
-
bold: (str) => {
|
114
|
-
if (typeof str === 'string' || typeof str === 'number') {
|
115
|
-
return `${str};font-weight: bold;`;
|
116
|
-
}
|
117
|
-
for (let key = 1; key < str.length; key++) {
|
118
|
-
str[key] += `;font-weight: bold;`;
|
119
|
-
}
|
120
|
-
return str;
|
121
|
-
}
|
122
|
-
};
|
123
|
-
const colorHash = {
|
124
|
-
log: 'black',
|
125
|
-
wait: 'cyan',
|
126
|
-
error: 'red',
|
127
|
-
warn: 'yellow',
|
128
|
-
ready: 'green',
|
129
|
-
info: 'blue',
|
130
|
-
event: 'magenta',
|
131
|
-
};
|
132
|
-
const createChalk = (name) => (...str) => {
|
133
|
-
if (typeof str[0] === 'object') {
|
134
|
-
createlog(name)(...add(colorUtils.bold(colorUtils[colorHash[name]](`[${firstToUpperCase(name)}] `)), ...str));
|
135
|
-
return;
|
136
|
-
}
|
137
|
-
let strArr = str;
|
138
|
-
if (typeof str === 'string' || typeof str === 'number') {
|
139
|
-
strArr = colorUtils[colorHash[name]](str);
|
140
|
-
}
|
141
|
-
createlog(name)(...add(colorUtils.bold(colorUtils[colorHash[name]](`[${firstToUpperCase(name)}] `)), strArr));
|
142
|
-
};
|
143
|
-
const createChalkBg = (name) => (...str) => {
|
144
|
-
if (typeof str[0] === 'object') {
|
145
|
-
createlog(name)(...add(colorUtils.bold(colorUtils[`bg${firstToUpperCase(colorHash[name])}`](`[${firstToUpperCase(name)}] `)), ...str));
|
146
|
-
return;
|
147
|
-
}
|
148
|
-
let strArr = str;
|
149
|
-
if (typeof str === 'string' || typeof str === 'number') {
|
150
|
-
strArr = colorUtils[colorHash[name]](str);
|
151
|
-
}
|
152
|
-
createlog(name)(...add(colorUtils.bold(colorUtils[`bg${firstToUpperCase(colorHash[name])}`](`[${firstToUpperCase(name)}] `)), strArr));
|
153
|
-
};
|
154
|
-
const createChalkGroup = (name) => (...str) => {
|
155
|
-
if (typeof str[0] === 'object') {
|
156
|
-
creategroup(name)(...add(colorUtils.bold(colorUtils[colorHash[name]](`[${firstToUpperCase(name)}] `)), ...str));
|
157
|
-
return;
|
158
|
-
}
|
159
|
-
let strArr = str;
|
160
|
-
if (typeof str === 'string' || typeof str === 'number') {
|
161
|
-
strArr = colorUtils[colorHash[name]](str);
|
162
|
-
}
|
163
|
-
creategroup(name)(...add(colorUtils.bold(colorUtils[colorHash[name]](`[${firstToUpperCase(name)}] `)), strArr));
|
164
|
-
};
|
165
|
-
const chalk = {
|
166
|
-
group: {
|
167
|
-
end: _console.groupEnd
|
168
|
-
},
|
169
|
-
bg: {}
|
170
|
-
};
|
171
|
-
Object.keys(colorHash).forEach(key => {
|
172
|
-
chalk[key] = createChalk(key);
|
173
|
-
chalk.group[key] = createChalkGroup(key);
|
174
|
-
chalk.bg[key] = createChalkBg(key);
|
175
|
-
});
|
176
|
-
const firstToUpperCase = (str) => str.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase());
|
177
|
-
Object.keys(color).forEach(key => {
|
178
|
-
colorUtils[key] = (str) => {
|
179
|
-
if (typeof str === 'string' || typeof str === 'number') {
|
180
|
-
return [`%c${str}`, `color:${color[key]}`];
|
181
|
-
}
|
182
|
-
for (let i = 1; i < str.length; i++) {
|
183
|
-
str[i] += `;color:${color[key]}`;
|
184
|
-
}
|
185
|
-
return str;
|
186
|
-
};
|
187
|
-
colorUtils[`bg${firstToUpperCase(key)}`] = (str) => {
|
188
|
-
if (typeof str === 'string' || typeof str === 'number') {
|
189
|
-
return [`%c${str}`, `padding: 2px 4px; border-radius: 3px; color: ${key === 'white' ? '#000' : '#fff'}; font-weight: bold; background:${color[key]};`];
|
190
|
-
}
|
191
|
-
for (let i = 1; i < str.length; i++) {
|
192
|
-
str[i] += `;padding: 2px 4px; border-radius: 3px; font-weight: bold; background:${color[key]};`;
|
193
|
-
}
|
194
|
-
return str;
|
195
|
-
};
|
196
|
-
});
|
197
|
-
self.logger = {
|
198
|
-
add,
|
199
|
-
...chalk,
|
200
|
-
...colorUtils,
|
201
|
-
};
|
202
|
-
|
203
|
-
if (!debug) {
|
204
|
-
logger = {
|
205
|
-
log: () => { },
|
206
|
-
wait: () => { },
|
207
|
-
error: () => { },
|
208
|
-
warn: () => { },
|
209
|
-
ready: () => { },
|
210
|
-
info: () => { },
|
211
|
-
event: () => { },
|
212
|
-
group: {
|
213
|
-
log: () => { },
|
214
|
-
wait: () => { },
|
215
|
-
error: () => { },
|
216
|
-
warn: () => { },
|
217
|
-
ready: () => { },
|
218
|
-
info: () => { },
|
219
|
-
event: () => { },
|
220
|
-
end: () => { },
|
221
|
-
},
|
222
|
-
bg: {
|
223
|
-
log: () => { },
|
224
|
-
wait: () => { },
|
225
|
-
error: () => { },
|
226
|
-
warn: () => { },
|
227
|
-
ready: () => { },
|
228
|
-
info: () => { },
|
229
|
-
event: () => { },
|
230
|
-
}
|
231
|
-
};
|
232
|
-
console.log = () => { };
|
233
|
-
}
|
234
|
-
|
235
|
-
const generate_uuid = () => {
|
236
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
237
|
-
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
238
|
-
return v.toString(16);
|
239
|
-
});
|
240
|
-
}
|
241
|
-
self.db = {
|
242
|
-
read: (key, config) => {
|
243
|
-
if (!config) { config = { type: "text" } }
|
244
|
-
return new Promise((resolve, reject) => {
|
245
|
-
caches.open(CACHE_NAME).then(cache => {
|
246
|
-
cache.match(new Request(`https://LOCALCACHE/${encodeURIComponent(key)}`)).then(function (res) {
|
247
|
-
if (!res) resolve(null)
|
248
|
-
res.text().then(text => resolve(text))
|
249
|
-
}).catch(() => {
|
250
|
-
resolve(null)
|
251
|
-
})
|
252
|
-
})
|
253
|
-
})
|
254
|
-
},
|
255
|
-
write: (key, value) => {
|
256
|
-
return new Promise((resolve, reject) => {
|
257
|
-
caches.open(CACHE_NAME).then(function (cache) {
|
258
|
-
cache.put(new Request(`https://LOCALCACHE/${encodeURIComponent(key)}`), new Response(value));
|
259
|
-
resolve()
|
260
|
-
}).catch(() => {
|
261
|
-
reject()
|
262
|
-
})
|
263
|
-
})
|
264
|
-
}
|
265
|
-
}
|
266
|
-
const compareVersion = (a, b) => {
|
267
|
-
let v1 = a.split('.');
|
268
|
-
let v2 = b.split('.');
|
269
|
-
const len = Math.max(v1.length, v2.length);
|
270
|
-
while (v1.length < len) {
|
271
|
-
v1.push('0');
|
272
|
-
}
|
273
|
-
while (v2.length < len) {
|
274
|
-
v2.push('0');
|
275
|
-
}
|
276
|
-
for (let i = 0; i < len; i++) {
|
277
|
-
const num1 = parseInt(v1[i]);
|
278
|
-
const num2 = parseInt(v2[i]);
|
279
|
-
if (num1 > num2) {
|
280
|
-
return a;
|
281
|
-
} else if (num1 < num2) {
|
282
|
-
return b;
|
283
|
-
}
|
284
|
-
}
|
285
|
-
return a;
|
286
|
-
}
|
287
|
-
|
288
|
-
const mirrors = [
|
289
|
-
`https://registry.npmjs.org/${NPMPackage}/latest`,
|
290
|
-
`https://registry.npmmirror.com/${NPMPackage}/latest`,
|
291
|
-
`https://mirrors.cloud.tencent.com/npm/${NPMPackage}/latest`
|
292
|
-
]
|
293
|
-
const getLocalVersion = async () => {
|
294
|
-
NPMPackageVersion = await db.read('blog_version') || NPMPackageVersion
|
295
|
-
logger.bg.info(`Local Version: ${NPMPackage}@${NPMPackageVersion}`)
|
296
|
-
}
|
297
|
-
let mirror_time = 0;
|
298
|
-
const setNewestVersion = async () => {
|
299
|
-
if (!NPMMirror) {
|
300
|
-
return
|
301
|
-
}
|
302
|
-
let f = null;
|
303
|
-
if (!(mirror_time % (mirrors.length + 1))) {
|
304
|
-
f = FetchEngine(mirrors);
|
305
|
-
} else {
|
306
|
-
f = fetch(mirrors[(mirror_time % (mirrors.length + 1)) - 1]);
|
307
|
-
}
|
308
|
-
mirror_time++;
|
309
|
-
return f
|
310
|
-
.then(res => res.json())
|
311
|
-
.then(async res => {
|
312
|
-
if (!res.version) throw ('No Version Found!')
|
313
|
-
NPMPackageVersion = compareVersion(res.version, await db.read('blog_version') || NPMPackageVersion)
|
314
|
-
logger.bg.ready(`${NPMPackage}@${NPMPackageVersion}`)
|
315
|
-
await db.write('blog_version', NPMPackageVersion)
|
316
|
-
})
|
317
|
-
.catch(error => {
|
318
|
-
logger.error('[Set Newest Version] ' + (error.stack || error))
|
319
|
-
})
|
320
|
-
}
|
321
|
-
setInterval(async () => {
|
322
|
-
await setNewestVersion()
|
323
|
-
}, 60 * 1000);
|
324
|
-
setTimeout(async () => {
|
325
|
-
await setNewestVersion()
|
326
|
-
}, 5000)
|
327
|
-
const installFunction = async () => {
|
328
|
-
await getLocalVersion();
|
329
|
-
return caches.open(CACHE_NAME + "-precache")
|
330
|
-
.then(async function (cache) {
|
331
|
-
if (!await db.read('uuid')) {
|
332
|
-
await db.write('uuid', generate_uuid())
|
333
|
-
}
|
334
|
-
if (PreCachlist.length) {
|
335
|
-
logger.group.event(`Precaching ${PreCachlist.length} files.`);
|
336
|
-
let index = 0;
|
337
|
-
PreCachlist.forEach(function (url) {
|
338
|
-
cache.match(new Request(url)).then(function (response) {
|
339
|
-
if (response) {
|
340
|
-
logger.ready(`Precaching ${url}`);
|
341
|
-
} else {
|
342
|
-
logger.wait(`Precaching ${url}`);
|
343
|
-
cache.add(new Request(url));
|
344
|
-
}
|
345
|
-
index++;
|
346
|
-
if (index === PreCachlist.length) {
|
347
|
-
logger.ready(`Precached ${PreCachlist.length} files.`);
|
348
|
-
logger.group.end();
|
349
|
-
}
|
350
|
-
})
|
351
|
-
})
|
352
|
-
}
|
353
|
-
}).catch((error) => {
|
354
|
-
logger.error('[install] ' + (error.stack || error));
|
355
|
-
})
|
356
|
-
}
|
357
|
-
self.addEventListener('install', async function (event) {
|
358
|
-
logger.bg.event("service worker install event listening");
|
359
|
-
try {
|
360
|
-
self.skipWaiting();
|
361
|
-
event.waitUntil(installFunction());
|
362
|
-
logger.bg.ready('service worker install sucess!');
|
363
|
-
} catch (error) {
|
364
|
-
logger.error('[install] ' + (error.stack || error));
|
365
|
-
}
|
366
|
-
});
|
367
|
-
self.addEventListener('activate', async event => {
|
368
|
-
logger.bg.event("service worker activate event listening");
|
369
|
-
try {
|
370
|
-
event.waitUntil(
|
371
|
-
caches.keys().then((keys) => {
|
372
|
-
return Promise.all(keys.map((key) => {
|
373
|
-
if (!key.includes(cacheSuffixVersion)) {
|
374
|
-
caches.delete(key);
|
375
|
-
logger.bg.ready('Deleted Outdated Cache: ' + key);
|
376
|
-
}
|
377
|
-
}));
|
378
|
-
}).catch((error) => {
|
379
|
-
logger.error('[activate] ' + (error.stack || error));
|
380
|
-
})
|
381
|
-
);
|
382
|
-
await self.clients.claim()
|
383
|
-
logger.bg.ready('service worker activate sucess!');
|
384
|
-
} catch (error) {
|
385
|
-
logger.error('[activate] ' + (error.stack || error));
|
386
|
-
}
|
387
|
-
})
|
388
|
-
self.addEventListener('fetch', async event => {
|
389
|
-
event.respondWith(
|
390
|
-
handleFetch(event).catch((error) => {
|
391
|
-
logger.error('[fetch] ' + event.request.url + '\n[error] ' + (error.stack || error));
|
392
|
-
})
|
393
|
-
)
|
394
|
-
});
|
395
|
-
|
396
|
-
|
397
|
-
const NetworkOnly = async (event) => {
|
398
|
-
logger.group.info('NetworkOnly: ' + new URL(event.request.url).pathname);
|
399
|
-
logger.wait('service worker fetch: ' + event.request.url)
|
400
|
-
logger.group.end();
|
401
|
-
return fetch(event.request)
|
402
|
-
}
|
403
|
-
const CacheFirst = async (event) => {
|
404
|
-
return caches.match(event.request).then(function (resp) {
|
405
|
-
logger.group.info('CacheFirst: ' + new URL(event.request.url).pathname);
|
406
|
-
logger.wait('service worker fetch: ' + event.request.url)
|
407
|
-
if (resp) {
|
408
|
-
logger.group.ready(`Cache Hit`);
|
409
|
-
console.log(resp)
|
410
|
-
logger.group.end();
|
411
|
-
logger.group.end();
|
412
|
-
event.waitUntil(CacheRuntime(event.request))
|
413
|
-
return resp;
|
414
|
-
} else {
|
415
|
-
logger.warn(`Cache Miss`);
|
416
|
-
logger.group.end();
|
417
|
-
return CacheRuntime(event.request)
|
418
|
-
}
|
419
|
-
})
|
420
|
-
}
|
421
|
-
const CacheAlways = async (event) => {
|
422
|
-
return caches.match(event.request).then(function (resp) {
|
423
|
-
logger.group.info('CacheAlways: ' + new URL(event.request.url).pathname);
|
424
|
-
logger.wait('service worker fetch: ' + event.request.url)
|
425
|
-
if (resp) {
|
426
|
-
logger.group.ready(`Cache Hit`);
|
427
|
-
console.log(resp)
|
428
|
-
logger.group.end();
|
429
|
-
logger.group.end();
|
430
|
-
return resp;
|
431
|
-
} else {
|
432
|
-
logger.warn(`Cache Miss`);
|
433
|
-
logger.group.end();
|
434
|
-
return CacheRuntime(event.request)
|
435
|
-
}
|
436
|
-
})
|
437
|
-
}
|
438
|
-
|
439
|
-
const matchCache = async (event) => {
|
440
|
-
return caches.match(event.request).then(function (resp) {
|
441
|
-
logger.group.info('service worker fetch: ' + event.request.url)
|
442
|
-
if (resp) {
|
443
|
-
logger.group.ready(`Cache Hit`);
|
444
|
-
console.log(resp)
|
445
|
-
logger.group.end();
|
446
|
-
logger.group.end();
|
447
|
-
return resp;
|
448
|
-
} else {
|
449
|
-
logger.warn(`Cache Miss`);
|
450
|
-
logger.group.end();
|
451
|
-
return CacheRuntime(event.request)
|
452
|
-
}
|
453
|
-
})
|
454
|
-
}
|
455
|
-
async function CacheRuntime(request) {
|
456
|
-
const url = new URL(request.url);
|
457
|
-
let response = await matchCDN(request);
|
458
|
-
if (!response) {
|
459
|
-
response = await fetch(request).catch(() => null)
|
460
|
-
}
|
461
|
-
logger.group.event(`Cache Runtime ${url.pathname}`);
|
462
|
-
logger.wait(`Caching url: ${request.url}`);
|
463
|
-
console.log(response);
|
464
|
-
|
465
|
-
if (request.method === "GET" && (url.protocol == "https:")) {
|
466
|
-
const cache = await caches.open(CACHE_NAME + "-runtime");
|
467
|
-
cache.put(request, response.clone()).catch(error => {
|
468
|
-
logger.error('[Cache Runtime] ' + (error.stack || error));
|
469
|
-
if (error.name === 'QuotaExceededError') {
|
470
|
-
caches.delete(CACHE_NAME + "-runtime");
|
471
|
-
logger.ready("deleted cache")
|
472
|
-
}
|
473
|
-
})
|
474
|
-
logger.ready(`Cached url: ${request.url}`);
|
475
|
-
} else {
|
476
|
-
logger.warn(`Not Cached url: ${request.url}`);
|
477
|
-
}
|
478
|
-
logger.group.end();
|
479
|
-
return response;
|
480
|
-
}
|
481
|
-
|
482
|
-
const matchCDN = async (req) => {
|
483
|
-
const nav = navigator
|
484
|
-
const { saveData, effectiveType } = nav.connection || nav.mozConnection || nav.webkitConnection || {}
|
485
|
-
if (saveData || /2g/.test(effectiveType)) {
|
486
|
-
logger.warn("Slow Network: Transparent Proxy");
|
487
|
-
return fetch(req);
|
488
|
-
}
|
489
|
-
const urls = []
|
490
|
-
let urlObj = new URL(req.url)
|
491
|
-
let pathType = urlObj.pathname.split('/')[1]
|
492
|
-
let pathTestRes = "";
|
493
|
-
|
494
|
-
if (NPMMirror && new RegExp(location.origin).test(req.url)) {
|
495
|
-
logger.group.ready(`Match NPM Mirror: ` + req.url);
|
496
|
-
for (const key in cdn.npm) {
|
497
|
-
let url = cdn.npm[key] + "/" + NPMPackage + "@" + NPMPackageVersion + req.url.replace(location.origin, '')
|
498
|
-
url = fullPath(fullPath(url))
|
499
|
-
console.log(url);
|
500
|
-
urls.push(url)
|
501
|
-
}
|
502
|
-
logger.group.end()
|
503
|
-
}
|
504
|
-
if (!urls.length) {
|
505
|
-
for (const item of cdn_match_list) {
|
506
|
-
if (new RegExp(item.key).test(req.url)) {
|
507
|
-
pathType = item.type
|
508
|
-
pathTestRes = new RegExp(item.key).exec(req.url)[0]
|
509
|
-
break;
|
510
|
-
}
|
511
|
-
}
|
512
|
-
for (const type in cdn) {
|
513
|
-
if (type === pathType) {
|
514
|
-
logger.group.ready(`Match CDN ${pathType}: ` + req.url);
|
515
|
-
for (const key in cdn[type]) {
|
516
|
-
const url = cdn[type][key] + req.url.replace(pathTestRes, '')
|
517
|
-
console.log(url);
|
518
|
-
urls.push(url)
|
519
|
-
}
|
520
|
-
logger.group.end()
|
521
|
-
}
|
522
|
-
}
|
523
|
-
}
|
524
|
-
|
525
|
-
let res;
|
526
|
-
if (urls.length)
|
527
|
-
res = FetchEngine(urls)
|
528
|
-
else
|
529
|
-
res = fetch(req)
|
530
|
-
if (res && NPMMirror && new RegExp(location.origin).test(req.url)) {
|
531
|
-
const ext = fullPath(fullPath(req.url)).split('.').pop()
|
532
|
-
const contentType = getContentType(ext)
|
533
|
-
res = res
|
534
|
-
.then(res => res.arrayBuffer())
|
535
|
-
.then(buffer => new Response(buffer, {
|
536
|
-
headers: {
|
537
|
-
"Content-Type": contentType
|
538
|
-
}
|
539
|
-
}))
|
540
|
-
.catch(() => null)
|
541
|
-
}
|
542
|
-
return res
|
543
|
-
}
|
544
|
-
|
545
|
-
const fullPath = (url) => {
|
546
|
-
url = url.split('?')[0].split('#')[0]
|
547
|
-
if (url.endsWith('/')) {
|
548
|
-
url += 'index.html'
|
549
|
-
} else {
|
550
|
-
const list = url.split('/')
|
551
|
-
const last = list[list.length - 1]
|
552
|
-
if (last.indexOf('.') === -1) {
|
553
|
-
url += '.html'
|
554
|
-
}
|
555
|
-
}
|
556
|
-
return url
|
557
|
-
}
|
558
|
-
async function progress(res) {
|
559
|
-
return new Response(await res.arrayBuffer(), {
|
560
|
-
status: res.status,
|
561
|
-
headers: res.headers
|
562
|
-
})
|
563
|
-
}
|
564
|
-
|
565
|
-
function createPromiseAny() {
|
566
|
-
Promise.any = function (promises) {
|
567
|
-
return new Promise((resolve, reject) => {
|
568
|
-
promises = Array.isArray(promises) ? promises : []
|
569
|
-
let len = promises.length
|
570
|
-
let errs = []
|
571
|
-
if (len === 0) return reject(new AggregateError('All promises were rejected'))
|
572
|
-
promises.forEach((p) => {
|
573
|
-
if (p instanceof Promise) {
|
574
|
-
p.then(
|
575
|
-
(res) => resolve(res),
|
576
|
-
(err) => {
|
577
|
-
len--
|
578
|
-
errs.push(err)
|
579
|
-
if (len === 0) reject(new AggregateError(errs))
|
580
|
-
}
|
581
|
-
)
|
582
|
-
} else {
|
583
|
-
reject(p)
|
584
|
-
}
|
585
|
-
})
|
586
|
-
})
|
587
|
-
}
|
588
|
-
}
|
589
|
-
|
590
|
-
function fetchAny(reqs) {
|
591
|
-
const controller = new AbortController()
|
592
|
-
|
593
|
-
return reqs.map(req => {
|
594
|
-
return new Promise((resolve, reject) => {
|
595
|
-
fetch(req, {
|
596
|
-
signal: controller.signal
|
597
|
-
})
|
598
|
-
.then(progress)
|
599
|
-
.then(res => {
|
600
|
-
controller.abort()
|
601
|
-
if (res.status !== 200)
|
602
|
-
reject(null)
|
603
|
-
else
|
604
|
-
resolve(res)
|
605
|
-
})
|
606
|
-
.catch(() => reject(null))
|
607
|
-
})
|
608
|
-
})
|
609
|
-
}
|
610
|
-
|
611
|
-
function fetchParallel(reqs) {
|
612
|
-
const abortEvent = new Event("abortOtherInstance")
|
613
|
-
const eventTarget = new EventTarget();
|
614
|
-
|
615
|
-
return reqs.map(async req => {
|
616
|
-
const controller = new AbortController();
|
617
|
-
let tagged = false;
|
618
|
-
eventTarget.addEventListener(abortEvent.type, () => {
|
619
|
-
if (!tagged) controller.abort();
|
620
|
-
})
|
621
|
-
return new Promise((resolve, reject) => {
|
622
|
-
fetch(req, {
|
623
|
-
signal: controller.signal,
|
624
|
-
}).then(res => {
|
625
|
-
tagged = true;
|
626
|
-
eventTarget.dispatchEvent(abortEvent)
|
627
|
-
if (res.status !== 200)
|
628
|
-
reject(null)
|
629
|
-
else
|
630
|
-
resolve(res)
|
631
|
-
}).catch(() => reject(null))
|
632
|
-
})
|
633
|
-
});
|
634
|
-
}
|
635
|
-
|
636
|
-
const FetchEngine = (reqs) => {
|
637
|
-
if (!Promise.any) createPromiseAny();
|
638
|
-
return Promise.any(fetchParallel(reqs)).then(res => res)
|
639
|
-
.catch((e) => {
|
640
|
-
if (e == "AggregateError: All promises were rejected") {
|
641
|
-
return Promise.any(fetchAny(reqs))
|
642
|
-
.then((res) => res)
|
643
|
-
.catch(() => null);
|
644
|
-
}
|
645
|
-
return null;
|
646
|
-
});
|
647
|
-
};
|
648
|
-
|
649
|
-
const getContentType = (ext) => {
|
650
|
-
switch (ext) {
|
651
|
-
case 'js':
|
652
|
-
return 'text/javascript'
|
653
|
-
case 'html':
|
654
|
-
return 'text/html'
|
655
|
-
case 'css':
|
656
|
-
return 'text/css'
|
657
|
-
case 'json':
|
658
|
-
return 'application/json'
|
659
|
-
case 'webp':
|
660
|
-
return 'image/webp'
|
661
|
-
case 'jpg':
|
662
|
-
return 'image/jpg'
|
663
|
-
case 'jpeg':
|
664
|
-
return 'image/jpeg'
|
665
|
-
case 'png':
|
666
|
-
return 'image/png'
|
667
|
-
case 'gif':
|
668
|
-
return 'image/gif'
|
669
|
-
case 'xml':
|
670
|
-
return 'text/xml'
|
671
|
-
case 'xsl':
|
672
|
-
return 'text/xml'
|
673
|
-
case 'webmanifest':
|
674
|
-
return 'text/webmanifest'
|
675
|
-
case 'map':
|
676
|
-
return 'application/json'
|
677
|
-
case 'bcmap':
|
678
|
-
return 'image/vnd.wap.wbmp'
|
679
|
-
case 'wbmp':
|
680
|
-
return 'image/vnd.wap.wbmp'
|
681
|
-
case 'bmp':
|
682
|
-
return 'image/bmp'
|
683
|
-
case 'ico':
|
684
|
-
return 'image/vnd.microsoft.icon'
|
685
|
-
case 'tiff':
|
686
|
-
return 'image/tiff'
|
687
|
-
case 'tif':
|
688
|
-
return 'image/tiff'
|
689
|
-
case 'svg':
|
690
|
-
return 'image/svg+xml'
|
691
|
-
case 'svgz':
|
692
|
-
return 'image/svg+xml'
|
693
|
-
case 'woff':
|
694
|
-
return 'application/font-woff'
|
695
|
-
case 'woff2':
|
696
|
-
return 'application/font-woff2'
|
697
|
-
case 'ttf':
|
698
|
-
return 'application/font-ttf'
|
699
|
-
case 'otf':
|
700
|
-
return 'application/font-otf'
|
701
|
-
case 'eot':
|
702
|
-
return 'application/vnd.ms-fontobject'
|
703
|
-
case 'zip':
|
704
|
-
return 'application/zip'
|
705
|
-
case 'tar':
|
706
|
-
return 'application/x-tar'
|
707
|
-
case 'gz':
|
708
|
-
return 'application/gzip'
|
709
|
-
case 'bz2':
|
710
|
-
return 'application/x-bzip2'
|
711
|
-
case 'rar':
|
712
|
-
return 'application/x-rar-compressed'
|
713
|
-
case '7z':
|
714
|
-
return 'application/x-7z-compressed'
|
715
|
-
case 'doc':
|
716
|
-
return 'application/msword'
|
717
|
-
case 'docx':
|
718
|
-
return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
719
|
-
case 'xls':
|
720
|
-
return 'application/vnd.ms-excel'
|
721
|
-
case 'xlsx':
|
722
|
-
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
723
|
-
case 'ppt':
|
724
|
-
return 'application/vnd.ms-powerpoint'
|
725
|
-
case 'pptx':
|
726
|
-
return 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
727
|
-
case 'pdf':
|
728
|
-
return 'application/pdf'
|
729
|
-
case 'txt':
|
730
|
-
return 'text/plain'
|
731
|
-
case 'rtf':
|
732
|
-
return 'application/rtf'
|
733
|
-
case 'mp3':
|
734
|
-
return 'audio/mpeg'
|
735
|
-
case 'wav':
|
736
|
-
return 'audio/x-wav'
|
737
|
-
case 'ogg':
|
738
|
-
return 'audio/ogg'
|
739
|
-
case 'mp4':
|
740
|
-
return 'video/mp4'
|
741
|
-
case 'm4v':
|
742
|
-
return 'video/x-m4v'
|
743
|
-
case 'mov':
|
744
|
-
return 'video/quicktime'
|
745
|
-
case 'avi':
|
746
|
-
return 'video/x-msvideo'
|
747
|
-
case 'wmv':
|
748
|
-
return 'video/x-ms-wmv'
|
749
|
-
case 'flv':
|
750
|
-
return 'video/x-flv'
|
751
|
-
case 'swf':
|
752
|
-
return 'application/x-shockwave-flash'
|
753
|
-
case 'mpg':
|
754
|
-
return 'video/mpeg'
|
755
|
-
case 'mpeg':
|
756
|
-
return 'video/mpeg'
|
757
|
-
case 'mpe':
|
758
|
-
return 'video/mpeg'
|
759
|
-
case 'mpv':
|
760
|
-
return 'video/mpeg'
|
761
|
-
case 'm2v':
|
762
|
-
return 'video/mpeg'
|
763
|
-
case 'm4a':
|
764
|
-
return 'audio/mp4'
|
765
|
-
case 'aac':
|
766
|
-
return 'audio/aac'
|
767
|
-
case 'm3u':
|
768
|
-
return 'audio/x-mpegurl'
|
769
|
-
case 'm3u8':
|
770
|
-
return 'application/vnd.apple.mpegurl'
|
771
|
-
case 'pls':
|
772
|
-
return 'audio/x-scpls'
|
773
|
-
case 'cue':
|
774
|
-
return 'application/x-cue'
|
775
|
-
case 'wma':
|
776
|
-
return 'audio/x-ms-wma'
|
777
|
-
case 'flac':
|
778
|
-
return 'audio/flac'
|
779
|
-
case 'aif':
|
780
|
-
return 'audio/x-aiff'
|
781
|
-
case 'aiff':
|
782
|
-
return 'audio/x-aiff'
|
783
|
-
case 'aifc':
|
784
|
-
return 'audio/x-aiff'
|
785
|
-
case 'au':
|
786
|
-
return 'audio/basic'
|
787
|
-
case 'snd':
|
788
|
-
return 'audio/basic'
|
789
|
-
case 'mid':
|
790
|
-
return 'audio/midi'
|
791
|
-
case 'midi':
|
792
|
-
return 'audio/midi'
|
793
|
-
case 'kar':
|
794
|
-
return 'audio/midi'
|
795
|
-
default:
|
796
|
-
return 'text/plain'
|
797
|
-
}
|
798
|
-
}
|
1
|
+
const prefix="sinzmise-cetastories",cacheSuffixVersion="00000018-0.03037530881575412",CACHE_NAME=prefix+"-v"+cacheSuffixVersion,PreCachlist=["/css/style.css","/js/app.js","/js/search/hexo.js"];let NPMMirror=!0;const NPMPackage="sinzmise-cetastories";let NPMPackageVersion="latest",debug=!0;const handleFetch=async e=>{const t=e.request.url;return/nocache/.test(t)?NetworkOnly(e):/@latest/.test(t)?CacheFirst(e):/cdnjs\.cloudflare\.com/.test(t)||/music\.126\.net/.test(t)||/qqmusic\.qq\.com/.test(t)||/jsdelivr\.net/.test(t)||/npm\.elemecdn\.com/.test(t)||/unpkg\.com/.test(t)||/.*\.(?:png|jpg|jpeg|svg|gif|webp|ico|eot|ttf|woff|woff2|mp3)$/.test(t)||/.*\.(css|js)$/.test(t)?CacheAlways(e):CacheFirst(e)},cdn={gh:{jsdelivr:"https://kkgithub.com/extdomains/cdn.jsdelivr.net/gh",fastly:"https://fastly.jsdelivr.net/gh",gcore:"https://gcore.jsdelivr.net/gh",testingcf:"https://testingcf.jsdelivr.net/gh",test1:"https://test1.jsdelivr.net/gh"},combine:{jsdelivr:"https://kkgithub.com/extdomains/cdn.jsdelivr.net/combine",fastly:"https://fastly.jsdelivr.net/combine",gcore:"https://gcore.jsdelivr.net/combine",testingcf:"https://testingcf.jsdelivr.net/combine",test1:"https://test1.jsdelivr.net/combine"},npm:{jsdelivr:"https://kkgithub.com/extdomains/cdn.jsdelivr.net/npm",fastly:"https://fastly.jsdelivr.net/npm",gcore:"https://gcore.jsdelivr.net/npm",testingcf:"https://testingcf.jsdelivr.net/npm",test1:"https://test1.jsdelivr.net/npm",unpkg:"https://unpkg.com",eleme:"https://npm.elemecdn.com",storisinz:"https://jsd.cdn.storisinz.site/npm",webcache:"https://npm.webcache.cn"},cdnjs:{cdnjs:"https://kkgithub.com/extdomains/cdnjs.cloudflare.com/ajax/libs",baomitu:"https://lib.baomitu.com",bootcdn:"https://cdn.bootcdn.net/ajax/libs",bytedance:"https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M",sustech:"https://mirrors.sustech.edu.cn/cdnjs/ajax/libs"}},cdn_match_list=[];for(const e in cdn)for(const t in cdn[e])cdn_match_list.push({type:e,key:cdn[e][t]});const _console=console,color={black:"#000000",red:"#FF0000",green:"#008000",yellow:"#FFFF00",blue:"#0000FF",magenta:"#FF00FF",cyan:"#00FFFF",white:"#FFFFFF"},add=(...e)=>{let t=[[]];for(let r=0;r<e.length;r++){const[o,...n]=e[r];t[0]+=o,t=t.concat(n)}return t},createlog=e=>(...t)=>{("error"==e?_console[e]:_console.log).apply(void 0,t)},creategroup=e=>(...e)=>{_console.groupCollapsed.apply(void 0,e)},colorUtils={bold:e=>{if("string"==typeof e||"number"==typeof e)return`${e};font-weight: bold;`;for(let t=1;t<e.length;t++)e[t]+=";font-weight: bold;";return e}},colorHash={log:"black",wait:"cyan",error:"red",warn:"yellow",ready:"green",info:"blue",event:"magenta"},createChalk=e=>(...t)=>{if("object"==typeof t[0])return void createlog(e)(...add(colorUtils.bold(colorUtils[colorHash[e]](`[${firstToUpperCase(e)}] `)),...t));let r=t;"string"!=typeof t&&"number"!=typeof t||(r=colorUtils[colorHash[e]](t)),createlog(e)(...add(colorUtils.bold(colorUtils[colorHash[e]](`[${firstToUpperCase(e)}] `)),r))},createChalkBg=e=>(...t)=>{if("object"==typeof t[0])return void createlog(e)(...add(colorUtils.bold(colorUtils[`bg${firstToUpperCase(colorHash[e])}`](`[${firstToUpperCase(e)}] `)),...t));let r=t;"string"!=typeof t&&"number"!=typeof t||(r=colorUtils[colorHash[e]](t)),createlog(e)(...add(colorUtils.bold(colorUtils[`bg${firstToUpperCase(colorHash[e])}`](`[${firstToUpperCase(e)}] `)),r))},createChalkGroup=e=>(...t)=>{if("object"==typeof t[0])return void creategroup()(...add(colorUtils.bold(colorUtils[colorHash[e]](`[${firstToUpperCase(e)}] `)),...t));let r=t;"string"!=typeof t&&"number"!=typeof t||(r=colorUtils[colorHash[e]](t)),creategroup()(...add(colorUtils.bold(colorUtils[colorHash[e]](`[${firstToUpperCase(e)}] `)),r))},chalk={group:{end:_console.groupEnd},bg:{}};Object.keys(colorHash).forEach((e=>{chalk[e]=createChalk(e),chalk.group[e]=createChalkGroup(e),chalk.bg[e]=createChalkBg(e)}));const firstToUpperCase=e=>e.toLowerCase().replace(/( |^)[a-z]/g,(e=>e.toUpperCase()));Object.keys(color).forEach((e=>{colorUtils[e]=t=>{if("string"==typeof t||"number"==typeof t)return[`%c${t}`,`color:${color[e]}`];for(let r=1;r<t.length;r++)t[r]+=`;color:${color[e]}`;return t},colorUtils[`bg${firstToUpperCase(e)}`]=t=>{if("string"==typeof t||"number"==typeof t)return[`%c${t}`,`padding: 2px 4px; border-radius: 3px; color: ${"white"===e?"#000":"#fff"}; font-weight: bold; background:${color[e]};`];for(let r=1;r<t.length;r++)t[r]+=`;padding: 2px 4px; border-radius: 3px; font-weight: bold; background:${color[e]};`;return t}})),self.logger={add:add,...chalk,...colorUtils},debug||(logger={log:()=>{},wait:()=>{},error:()=>{},warn:()=>{},ready:()=>{},info:()=>{},event:()=>{},group:{log:()=>{},wait:()=>{},error:()=>{},warn:()=>{},ready:()=>{},info:()=>{},event:()=>{},end:()=>{}},bg:{log:()=>{},wait:()=>{},error:()=>{},warn:()=>{},ready:()=>{},info:()=>{},event:()=>{}}},console.log=()=>{});const generate_uuid=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}));self.db={read:(e,t)=>(t||(t={type:"text"}),new Promise(((t,r)=>{caches.open(CACHE_NAME).then((r=>{r.match(new Request(`https://LOCALCACHE/${encodeURIComponent(e)}`)).then((function(e){e||t(null),e.text().then((e=>t(e)))})).catch((()=>{t(null)}))}))}))),write:(e,t)=>new Promise(((r,o)=>{caches.open(CACHE_NAME).then((function(o){o.put(new Request(`https://LOCALCACHE/${encodeURIComponent(e)}`),new Response(t)),r()})).catch((()=>{o()}))}))};const compareVersion=(e,t)=>{let r=e.split("."),o=t.split(".");const n=Math.max(r.length,o.length);for(;r.length<n;)r.push("0");for(;o.length<n;)o.push("0");for(let a=0;a<n;a++){const n=parseInt(r[a]),s=parseInt(o[a]);if(n>s)return e;if(n<s)return t}return e},mirrors=[`https://registry.npmjs.org/${NPMPackage}/latest`,`https://registry.npmmirror.com/${NPMPackage}/latest`,`https://mirrors.cloud.tencent.com/npm/${NPMPackage}/latest`],getLocalVersion=async()=>{NPMPackageVersion=await db.read("blog_version")||NPMPackageVersion,logger.bg.info(`Local Version: ${NPMPackage}@${NPMPackageVersion}`)};let mirror_time=0;const setNewestVersion=async()=>{if(!NPMMirror)return;let e=null;return e=mirror_time%(mirrors.length+1)?fetch(mirrors[mirror_time%(mirrors.length+1)-1]):FetchEngine(mirrors),mirror_time++,e.then((e=>e.json())).then((async e=>{if(!e.version)throw"No Version Found!";NPMPackageVersion=compareVersion(e.version,await db.read("blog_version")||NPMPackageVersion),logger.bg.ready(`${NPMPackage}@${NPMPackageVersion}`),await db.write("blog_version",NPMPackageVersion)})).catch((e=>{logger.error("[Set Newest Version] "+(e.stack||e))}))};setInterval((async()=>{await setNewestVersion()}),6e4),setTimeout((async()=>{await setNewestVersion()}),5e3);const installFunction=async()=>(await getLocalVersion(),caches.open(CACHE_NAME+"-precache").then((async function(e){if(await db.read("uuid")||await db.write("uuid",generate_uuid()),PreCachlist.length){logger.group.event(`Precaching ${PreCachlist.length} files.`);let t=0;PreCachlist.forEach((function(r){e.match(new Request(r)).then((function(o){o?logger.ready(`Precaching ${r}`):(logger.wait(`Precaching ${r}`),e.add(new Request(r))),t++,t===PreCachlist.length&&(logger.ready(`Precached ${PreCachlist.length} files.`),logger.group.end())}))}))}})).catch((e=>{logger.error("[install] "+(e.stack||e))})));self.addEventListener("install",(async function(e){logger.bg.event("service worker install event listening");try{self.skipWaiting(),e.waitUntil(installFunction()),logger.bg.ready("service worker install sucess!")}catch(e){logger.error("[install] "+(e.stack||e))}})),self.addEventListener("activate",(async e=>{logger.bg.event("service worker activate event listening");try{e.waitUntil(caches.keys().then((e=>Promise.all(e.map((e=>{e.includes(cacheSuffixVersion)||(caches.delete(e),logger.bg.ready("Deleted Outdated Cache: "+e))}))))).catch((e=>{logger.error("[activate] "+(e.stack||e))}))),await self.clients.claim(),logger.bg.ready("service worker activate sucess!")}catch(e){logger.error("[activate] "+(e.stack||e))}})),self.addEventListener("fetch",(async e=>{e.respondWith(handleFetch(e).catch((t=>{logger.error("[fetch] "+e.request.url+"\n[error] "+(t.stack||t))})))}));const NetworkOnly=async e=>(logger.group.info("NetworkOnly: "+new URL(e.request.url).pathname),logger.wait("service worker fetch: "+e.request.url),logger.group.end(),fetch(e.request)),CacheFirst=async e=>caches.match(e.request).then((function(t){return logger.group.info("CacheFirst: "+new URL(e.request.url).pathname),logger.wait("service worker fetch: "+e.request.url),t?(logger.group.ready("Cache Hit"),console.log(t),logger.group.end(),logger.group.end(),e.waitUntil(CacheRuntime(e.request)),t):(logger.warn("Cache Miss"),logger.group.end(),CacheRuntime(e.request))})),CacheAlways=async e=>caches.match(e.request).then((function(t){return logger.group.info("CacheAlways: "+new URL(e.request.url).pathname),logger.wait("service worker fetch: "+e.request.url),t?(logger.group.ready("Cache Hit"),console.log(t),logger.group.end(),logger.group.end(),t):(logger.warn("Cache Miss"),logger.group.end(),CacheRuntime(e.request))})),matchCache=async e=>caches.match(e.request).then((function(t){return logger.group.info("service worker fetch: "+e.request.url),t?(logger.group.ready("Cache Hit"),console.log(t),logger.group.end(),logger.group.end(),t):(logger.warn("Cache Miss"),logger.group.end(),CacheRuntime(e.request))}));async function CacheRuntime(e){const t=new URL(e.url);let r=await matchCDN(e);if(r||(r=await fetch(e).catch((()=>null))),logger.group.event(`Cache Runtime ${t.pathname}`),logger.wait(`Caching url: ${e.url}`),console.log(r),"GET"===e.method&&"https:"==t.protocol){(await caches.open(CACHE_NAME+"-runtime")).put(e,r.clone()).catch((e=>{logger.error("[Cache Runtime] "+(e.stack||e)),"QuotaExceededError"===e.name&&(caches.delete(CACHE_NAME+"-runtime"),logger.ready("deleted cache"))})),logger.ready(`Cached url: ${e.url}`)}else logger.warn(`Not Cached url: ${e.url}`);return logger.group.end(),r}const matchCDN=async e=>{const t=navigator,{saveData:r,effectiveType:o}=t.connection||t.mozConnection||t.webkitConnection||{};if(r||/2g/.test(o))return logger.warn("Slow Network: Transparent Proxy"),fetch(e);const n=[];let a,s=new URL(e.url).pathname.split("/")[1],c="";if(NPMMirror&&new RegExp(location.origin).test(e.url)){logger.group.ready("Match NPM Mirror: "+e.url);for(const t in cdn.npm){let r=cdn.npm[t]+"/"+NPMPackage+"@"+NPMPackageVersion+e.url.replace(location.origin,"");r=fullPath(fullPath(r)),console.log(r),n.push(r)}logger.group.end()}if(!n.length){for(const t of cdn_match_list)if(new RegExp(t.key).test(e.url)){s=t.type,c=new RegExp(t.key).exec(e.url)[0];break}for(const t in cdn)if(t===s){logger.group.ready(`Match CDN ${s}: `+e.url);for(const r in cdn[t]){const o=cdn[t][r]+e.url.replace(c,"");console.log(o),n.push(o)}logger.group.end()}}if(a=n.length?FetchEngine(n):fetch(e),a&&NPMMirror&&new RegExp(location.origin).test(e.url)){const t=fullPath(fullPath(e.url)).split(".").pop(),r=getContentType(t);a=a.then((e=>e.arrayBuffer())).then((e=>new Response(e,{headers:{"Content-Type":r}}))).catch((()=>null))}return a},fullPath=e=>{if((e=e.split("?")[0].split("#")[0]).endsWith("/"))e+="index.html";else{const t=e.split("/");-1===t[t.length-1].indexOf(".")&&(e+=".html")}return e};async function progress(e){return new Response(await e.arrayBuffer(),{status:e.status,headers:e.headers})}function createPromiseAny(){Promise.any=function(e){return new Promise(((t,r)=>{let o=(e=Array.isArray(e)?e:[]).length,n=[];if(0===o)return r(new AggregateError("All promises were rejected"));e.forEach((e=>{e instanceof Promise?e.then((e=>t(e)),(e=>{o--,n.push(e),0===o&&r(new AggregateError(n))})):r(e)}))}))}}function fetchAny(e){const t=new AbortController;return e.map((e=>new Promise(((r,o)=>{fetch(e,{signal:t.signal}).then(progress).then((e=>{t.abort(),200!==e.status?o(null):r(e)})).catch((()=>o(null)))}))))}function fetchParallel(e){const t=new Event("abortOtherInstance"),r=new EventTarget;return e.map((async e=>{const o=new AbortController;let n=!1;return r.addEventListener(t.type,(()=>{n||o.abort()})),new Promise(((a,s)=>{fetch(e,{signal:o.signal}).then((e=>{n=!0,r.dispatchEvent(t),200!==e.status?s(null):a(e)})).catch((()=>s(null)))}))}))}const FetchEngine=e=>(Promise.any||createPromiseAny(),Promise.any(fetchParallel(e)).then((e=>e)).catch((t=>"AggregateError: All promises were rejected"==t?Promise.any(fetchAny(e)).then((e=>e)).catch((()=>null)):null))),getContentType=e=>{switch(e){case"js":return"text/javascript";case"html":return"text/html";case"css":return"text/css";case"json":case"map":return"application/json";case"webp":return"image/webp";case"jpg":return"image/jpg";case"jpeg":return"image/jpeg";case"png":return"image/png";case"gif":return"image/gif";case"xml":case"xsl":return"text/xml";case"webmanifest":return"text/webmanifest";case"bcmap":case"wbmp":return"image/vnd.wap.wbmp";case"bmp":return"image/bmp";case"ico":return"image/vnd.microsoft.icon";case"tiff":case"tif":return"image/tiff";case"svg":case"svgz":return"image/svg+xml";case"woff":return"application/font-woff";case"woff2":return"application/font-woff2";case"ttf":return"application/font-ttf";case"otf":return"application/font-otf";case"eot":return"application/vnd.ms-fontobject";case"zip":return"application/zip";case"tar":return"application/x-tar";case"gz":return"application/gzip";case"bz2":return"application/x-bzip2";case"rar":return"application/x-rar-compressed";case"7z":return"application/x-7z-compressed";case"doc":return"application/msword";case"docx":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";case"xls":return"application/vnd.ms-excel";case"xlsx":return"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";case"ppt":return"application/vnd.ms-powerpoint";case"pptx":return"application/vnd.openxmlformats-officedocument.presentationml.presentation";case"pdf":return"application/pdf";case"txt":default:return"text/plain";case"rtf":return"application/rtf";case"mp3":return"audio/mpeg";case"wav":return"audio/x-wav";case"ogg":return"audio/ogg";case"mp4":return"video/mp4";case"m4v":return"video/x-m4v";case"mov":return"video/quicktime";case"avi":return"video/x-msvideo";case"wmv":return"video/x-ms-wmv";case"flv":return"video/x-flv";case"swf":return"application/x-shockwave-flash";case"mpg":case"mpeg":case"mpe":case"mpv":case"m2v":return"video/mpeg";case"m4a":return"audio/mp4";case"aac":return"audio/aac";case"m3u":return"audio/x-mpegurl";case"m3u8":return"application/vnd.apple.mpegurl";case"pls":return"audio/x-scpls";case"cue":return"application/x-cue";case"wma":return"audio/x-ms-wma";case"flac":return"audio/flac";case"aif":case"aiff":case"aifc":return"audio/x-aiff";case"au":case"snd":return"audio/basic";case"mid":case"midi":case"kar":return"audio/midi"}};
|
2
|
+
//# sourceMappingURL=maps/sw.js.map
|