forked from yuameshi/PhiCommunity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (50 loc) · 1.49 KB
/
index.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
window.addEventListener('DOMContentLoaded', () => {
document
.querySelector('#delAllCache')
.addEventListener('click', delAllCache);
const container = document.querySelector('div#container');
caches.open('phi-charts-cache').then(function (cache) {
cache.keys().then(function (keys) {
keys.forEach(function (request, index, array) {
window.cacheList = array;
const item = document.createElement('div');
item.classList.add('item');
item.setAttribute('data-url', request.url);
item.setAttribute(
'data-file-name',
new URL(request.url).pathname.split('/')[
new URL(request.url).pathname.split('/').length - 1
]
);
const delBtn = document.createElement('button');
delBtn.classList.add('deleteBtn');
delBtn.innerText = '删除';
delBtn.addEventListener('click', delCache);
delBtn.setAttribute('data-index', index);
container.appendChild(item);
item.appendChild(delBtn);
// console.log(request);
});
});
});
});
function delCache(e) {
const index = parseInt(e.target.getAttribute('data-index'));
caches.open('phi-charts-cache').then(function (cache) {
cache.delete(window.cacheList[index]).then(function () {
document
.querySelector('div#container')
.children[index + 1].remove();
});
});
}
function delAllCache() {
caches.open('phi-charts-cache').then(function (cache) {
cache.keys().then(function (keys) {
keys.forEach(function (request) {
cache.delete(request);
});
location.reload();
});
});
}