-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateicons.htm
130 lines (113 loc) · 3.81 KB
/
updateicons.htm
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Update Icon</title>
</head>
<body style="width:300px">
<h1>Update Icon</h1>
<table style="width: 300px;">
<tr>
<td style="width:60px"><img id="icon" /></td>
<td>
<select id="sel" style="width:10em">
<option selected disabled>select...</option>
</select>
<progress value=0 max=1 style="width:12em"></progress>
<div id='info'> </div>
</td>
</tr>
<tr>
<td colspan=2 style="text-align:right">
<button>Start</button>
</td>
</tr>
</table>
<hr>
<p style="text-align: right;"><a href="/microide.htm" style="float: right;text-decoration: none;">>>></a></p>
<script>
var repo = 'https://raw.githubusercontent.com/HomeDing/WebIcons/master/favicons/'; // /socket/favicon.svg';
var eStart = document.querySelector('button');
var eBar = document.querySelector('progress');
var eInfo = document.querySelector('#info');
var eImg = document.querySelector('#icon');
var work = { status: '0', list: null, files: 0, done: 0 };
var timer = 0;
var seed = "?" + new Date().valueOf();
var iname = '';
function log(t) {
eInfo.innerText = t;
} // log
function next() {
work.status = 'r';
} // next
var selObj = document.querySelector('#sel');
var list = 'and,bme680,bulb,button,config,default,dht,digitalin,digitalout,door,home,minus,ntptime,ota,plus,pms,power,radio,remote,rfsend,rotary,schedule,socket,ssdp,switch,time,timer,tool,value,water,wifi'.split(',');
list.forEach(function (e) {
var opt = document.createElement('option');
opt.value = opt.textContent = e;
selObj.appendChild(opt);
});
selObj.addEventListener('input', function (evt) {
iname = evt.srcElement.value;
eImg.src = repo + evt.srcElement.value + '/favicon.svg';
});
// list of files
function doStart() {
if (!iname) {
log('select an icon name...');
} else {
log('loading ' + iname + ' icons');
work.list = ['favicon.svg', 'favicon48.png', // 'favicon144.png', 'favicon180.png',
'favicon192.png', 'favicon270.png', 'favicon512.png'];
work.files = work.list.length;
work.status = 'r';
timer = window.setInterval(step, 200);
}
} // doStart()
// grab next file
function doFile() {
work.status = 'w'; // wait
var theItem = work.list.shift();
// set progress
work.done++;
eBar.max = work.files;
eBar.value = work.done;
eInfo.innerText = theItem; // log
if (theItem[0] == '-') {
// delete the file
fetch('/' + theItem.substring(1), { method: 'DELETE' })
.then(next).catch(next);
} else {
fetch(repo + iname + '/' + theItem + seed)
.catch(next)
.then(function (result) {
return result.arrayBuffer();
})
.then(function (buf) {
var formData = new FormData();
formData.append('file', new Blob([buf]), '/' + theItem);
fetch('/', { method: 'POST', body: formData }).then(next);
});
};
} // doFile()
function step() {
if (work.status == '0') {
} else if (work.status == 'r') { // run
if (work.list.length == 0)
work.status = 'e';
else
doFile();
} else if (work.status == 'e') { // end
if (timer) {
window.clearInterval(timer);
log('done');
}
timer = 0;
}
}
eStart.addEventListener('click', doStart);
</script>
</body>
</html>