-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
500 lines (465 loc) · 19.7 KB
/
index.html
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<!DOCTYPE html>
<html lang="en" class="">
<head>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/>
<title>Install Tasmota</title>
<style>
div,fieldset,input,select{padding:5px;font-size:1em;}
fieldset{background:#4f4f4f;}
p{margin:0.5em 0;}
input{width:100%;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;background:#dddddd;color:#000000;}
input[type=checkbox],input[type=radio]{width:1em;margin-right:6px;vertical-align:-1px;}
input[type=range]{width:99%;}
select{width:100%;background:#dddddd;color:#000000;}
textarea{resize:vertical;width:98%;height:318px;padding:5px;overflow:auto;background:#1f1f1f;color:#65c115;}
body{text-align:center;font-family:verdana,sans-serif;background:#252525;}
td{padding:0px;}
button{border:0;border-radius:0.3rem;background:#1fa3ec;color:#faffff;line-height:2.4rem;font-size:1.2rem;width:100%;-webkit-transition-duration:0.4s;transition-duration:0.4s;cursor:pointer;}
button:hover{background:#0e70a4;}
.bred{background:#d43535;}
.bred:hover{background:#931f1f;}
.bgrn{background:#47c266;}
.bgrn:hover{background:#5aaf6f;}
a{color:#1fa3ec;text-decoration:none;}
.p{float:left;text-align:left;}
.q{float:right;text-align:right;}
.r{border-radius:0.3em;padding:2px;margin:6px 2px;}
.pick-variant{margin-bottom:16px;}
.date_pick{display:inline-block;width: 33%;}
#drop-area {
border: 2px dashed #ccc;
border-radius: 20px;
width: 480px;
margin: auto;
padding: 20px;
}
#drop-area.highlight {
border-color: #1fa3ec;
}
</style>
<script
type="module"
src="https://unpkg.com/tasmota-esp-web-tools@8.1.4/dist/web/install-button.js?module"
></script>
<!-- <script type="module">import * as Module from "./js/tasmota_gh_helper.js"</script> -->
<script>
var releases = null;
var date_filter = null;
var build_filter = ["d","r"];
var local_file = null
var virtual_manifest = {"name": "","version": "","new_install_prompt_erase": true,"builds": [
{ "chipFamily": "ESP32","parts": [{ "path": "", "offset": 0 }]},
{ "chipFamily": "ESP32-C2","parts": [{ "path": "", "offset": 0 }]},
{ "chipFamily": "ESP32-C3","parts": [{ "path": "", "offset": 0 }]},
{ "chipFamily": "ESP32-C6","parts": [{ "path": "", "offset": 0 }]},
{ "chipFamily": "ESP32-S2","parts": [{ "path": "", "offset": 0 }]},
{ "chipFamily": "ESP32-S3","parts": [{ "path": "", "offset": 0 }]},
{ "chipFamily": "ESP8266","parts": [{ "path": "", "offset": 0 }]}
]};
function DateIsNotSelected(date){
let year = document.querySelector("#pick-year-selector").value;
let month = document.querySelector("#pick-month-selector").value;
let day = document.querySelector("#pick-day-selector").value;
let data = date.split("-");
if(year != "all" && year != data[0])
{
return true;
}
if(month != "all" && month != data[1])
{
return true;
}
if(day != "all" && day != data[2])
{
return true;
}
return false;
}
function BuildTypeNotSelected(type){
if(build_filter.includes(type)){
return false;
}
return true;
}
function makeReleaseSelector(data){
let sel=document.querySelector("#pick-release-selector");
while(sel.childElementCount!=0){
sel.removeChild(sel.childNodes[0]);
}
let lines = data.split("\n").reverse();
console.log(data);
var duplicates = [];
for (opt_group of lines){
if (opt_group.length < 10) continue;
if(duplicates.includes(opt_group)){
continue;
}
duplicates.push(opt_group);
var og=document.createElement('option');
const tag_data = opt_group.split(".");
if(DateIsNotSelected(tag_data[0])){
continue;
}
if(BuildTypeNotSelected(tag_data[1])){
continue;
}
og.label = tag_data[0] + " (commit:" + tag_data[2].substring(0,8) + "...)";
og.value = opt_group;
var build = "Pre-release:\n"
if(tag_data=="r"){
build = "Release:\n"
}
og.title = build;
og.title += "Build date: " + tag_data[0] + "\n";
og.title += "Commit: " + tag_data[2] + "\n";
sel.appendChild(og);
// console.log(opt_group,opt_group.length,data[opt_group]);
}
sel.addEventListener("change", () => {
initVariantSelector(sel.value);
});
}
function makeDateFilter(data){
let lines = data.split("\n");
date_filter = {};
for(line of lines){
let date = (line.split(".")[0]).split("-");
let year = date[0];
let month = date[1];
let day = date[2];
if(year in date_filter == false){
date_filter[year] = {};
}
if(month in date_filter[year] == false){
date_filter[year][month] = [];
}
if(date_filter[year][month].includes(day) == false){
date_filter[year][month].push(day);
}
}
}
function makeYearSelector(){
let first=document.createElement('option');
first.label = "all";
first.value = "all";
let sel=document.querySelector("#pick-year-selector");
while(sel.childElementCount!=0){
sel.removeChild(sel.childNodes[0]);
}
sel.appendChild(first);
for(const [year,v] of Object.entries(date_filter)){
if(year == ""){
continue;
}
var o=document.createElement('option');
o.label = year;
o.value = year;
sel.appendChild(o);
}
sel.addEventListener("change", () => {
makeMonthSelector(sel.value);
let month = document.querySelector("#pick-month-selector");
makeDaySelector(sel.value,month.value);
makeReleaseSelector(releases);
});
}
function makeMonthSelector(year){
let first=document.createElement('option');
first.label = "all";
first.value = "all";
let sel=document.querySelector("#pick-month-selector");
while(sel.childElementCount!=0){
sel.removeChild(sel.childNodes[0]);
}
sel.appendChild(first);
if(year == null || year == "all" ){
return;
}
for(const [month,v] of Object.entries(date_filter[year])){
var o=document.createElement('option');
o.label = month;
o.value = month;
sel.appendChild(o);
}
sel.addEventListener("change", () => {
let year = document.querySelector("#pick-year-selector");
makeDaySelector(year.value,sel.value);
makeReleaseSelector(releases);
});
}
function makeDaySelector(year,month){
let first=document.createElement('option');
first.label = "all";
first.value = "all";
let sel=document.querySelector("#pick-day-selector");
while(sel.childElementCount!=0){
sel.removeChild(sel.childNodes[0]);
}
sel.appendChild(first);
if(year == null || month == null || year == "all" || month == "all"){
return;
}
for(day of date_filter[year][month]){
var o=document.createElement('option');
o.label = day;
o.value = day;
sel.appendChild(o);
}
sel.addEventListener("change", () => {
makeReleaseSelector(releases);
});
}
function makeDateSelector(data){
if(releases == null){
releases = data;
}
if(date_filter == null){
makeDateFilter(data);
}
makeYearSelector();
makeMonthSelector();
makeDaySelector();
let radio = document.getElementsByClassName("build_type_select");
console.log(radio);
for(el of radio){
console.log(el);
el.addEventListener("click", () => {
let btn = document.querySelector('input[name="build_type"]:checked')
build_filter = [btn.value];
if(btn.value == "a"){
build_filter = ["r","d"];
}
makeReleaseSelector(releases);
});
}
makeReleaseSelector(data);
}
function filterByYear(year){
makeDateSelector(releases);
}
function useFallback(){
let els = document.getElementsByClassName("needs_cors");
for(el of els){
console.log(el);
el.setAttribute("style","visibility: collapse;");
}
let sel=document.querySelector("#pick-release-selector");
console.log(sel)
var el = document.createElement('p');
el.innerHTML = "To access our GitHub releases page and directly flash firmware binaries<br>from there including older versions<br>you have to turn off CORS in your browser.<br>(i.e. with browser extension: CORS unblock)";
sel.replaceWith(el);
fetch('https://raw.githubusercontent.com/tasmota/install/firmware/manifests.json')
.then(response => response.json())
.then(data => makeVariantSelector(data));
}
function getLatestTag(){
fetch('https://raw.githubusercontent.com/tasmota/install/firmware/tag_latest.txt')
.then(x => x.text())
.then(t =>testCORS(t));
}
async function testCORS(t){
try{
const resp = await fetch('https://github.com/tasmota/install/releases/download/'+ t + '/manifests_release.json', {mode:"cors"
});
console.log(resp);
}
catch(error){
console.log("CORS is blocking");
useFallback();
return;
}
console.log("CORS is not blocking");
initVariantSelector(t);
fetch('https://raw.githubusercontent.com/tasmota/install/firmware/tag.txt')
.then(x => x.text())
.then(t => {makeReleaseSelector(t,"all"); makeDateSelector(t);})
}
function initVariantSelector(tag){
fetch('https://github.com/tasmota/install/releases/download/'+ tag + '/manifests_release.json')
.then(response => response.json())
.then(data => makeVariantSelector(data));
getFirmwareVersion(tag);
}
function makeVariantSelector(data){
if(data.length == 0){
console.log(data);
return false;
}
const sel=document.querySelector("#pick-variant-selector");
while (sel.firstChild) {
sel.removeChild(sel.firstChild);
}
console.log(data);
for (opt_group in data){
var og=document.createElement('optgroup');
og.label = opt_group;
sel.appendChild(og);
console.log(opt_group,data[opt_group]);
let firmware_label = document.querySelector("#firmware-version");
for (fw of data[opt_group]){
// console.log(data[opt_group][fw]);
var opt=document.createElement('option');
opt.label = fw['name'];
let version = fw['version'];
if(version == undefined){
//firmware_label.innerHTML = " ";
}
else{
firmware_label.innerText = version;
}
opt.value = fw['path'];
opt.title = "Supported chipfamilies:\n"
for (chipFamily of fw['chipFamilies']){
opt.title += chipFamily + "\n";
}
console.log( opt.value);
og.appendChild(opt);
}
}
return true;
}
function getFirmwareVersion(tag){
let commit = tag.split(".")[2];
console.log("Commit:____________",commit);
fetch("https://raw.githubusercontent.com/arendst/Tasmota/"+commit+"/tasmota/include/tasmota_version.h").then(x=>x.text()).then(t=>printFirmwareVersion(t))
}
function printFirmwareVersion(text_data){
for(line of text_data.split("\n")){
if(line.includes("const uint32_t VERSION =")){
console.log("Line:____________",line);
let fw_name = line.split("//")[1];
let firmware_label = document.querySelector("#firmware-version");
firmware_label.innerHTML = fw_name.trim();
}
}
}
function openFileDialog(){
let input = document.createElement('input');
input.type = 'file';
input.onchange = _ => {
handleFiles(input.files);
};
input.click();
}
function preventDefaults (e) {
e.preventDefault();
e.stopPropagation();
}
function highlight(e) {
dropArea.classList.add('highlight');
}
function unhighlight(e) {
dropArea.classList.remove('active');
}
function handleDrop(e) {
var dt = e.dataTransfer;
var files = dt.files;
handleFiles(files);
}
function handleFiles(files) {
files = [...files];
console.log(files);
document.getElementById("URL_based_input").style.display = "none";
document.getElementById("file_upload_infotext").innerHTML = "You can flash your provided factory firmware at offset 0 by clicking the CONNECT button above.";
document.getElementById("dropped_firmware").innerText = files[0].name;
const button = document.querySelector("esp-web-install-button");
virtual_manifest.name = files[0].name;
button.manifest = JSON.stringify(virtual_manifest);
button.firmwareFile = files[0];
}
function prepareDropZone(){
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false);
});
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false);
});
dropArea.addEventListener('drop', handleDrop, false);
}
window.addEventListener("load", function(event) {
window.dropArea = document.getElementById("drop-area");
prepareDropZone();
getLatestTag();
try{
const button = document.querySelector("esp-web-install-button");
button.overrides = {
checkSameFirmware(manifest, improvInfo) {
const manifestFirmware = manifest.name.toLowerCase();
const deviceFirmware = improvInfo.firmware.toLowerCase();
return manifestFirmware.includes(deviceFirmware);
}
};
console.log(button.shadowRoot.firstChild.name);
if(button.shadowRoot.firstChild.name == 'activate'){
//success: add the select picker and some info
const selectEl = document.querySelector("#pick-variant-selector");
button.manifest = "https://tasmota.github.io/install/manifest_ext/release.tasmota.manifest.json";
selectEl.addEventListener("change", () => {
button.manifest = selectEl.value;
console.log(button.manifest);
});
}
}
catch(e){
console.log(e);
}
},{ once: true });
</script>
</head>
<body>
<div style='display:inline-block;color:#eaeaea;min-width:340px;'>
<h1>Install Tasmota</h1>
<div class='pick-variant'>
<ol style='text-align:left'>
<li>Connect the ESP device to your computer</br>using USB or serial-to-USB adapter</li></br>
<li>Select the firmware variant suitable for</br>your device</li></br>
<li>Hit "Install" and select the correct port</br>or find help if <a href="https://tasmota.github.io/docs/Getting-Started/" target='_blank' style='color:#aaa;'>no device found</a></li>
</ol>
</br>
</br>
<div id="URL_based_input" class="collapsible">
<select id="pick-variant-selector"></select>
<p id="firmware-version"></p>
<select id="pick-release-selector"></select>
</br></br>
<p class = "needs_cors">Filter by date:</p>
<span><select class = "date_pick needs_cors" id="pick-year-selector"></select><select class = "date_pick needs_cors" id="pick-month-selector"></select><select class = "date_pick needs_cors" id="pick-day-selector"></select></span>
<p>
<p class = "needs_cors"><br>Filter by type:<br>
<input type="radio" name="build_type" value="r" id="check1" class="build_type_select">
<label for="check1">Release</label>
<input type="radio" name="build_type" value="d" id="check2" class="build_type_select">
<label for="check2">Development</label>
<input type="radio" name="build_type" value="a" id="check3" class="build_type_select" checked>
<label for="check3">All</label></p>
</div>
</br>
<esp-web-install-button id="inst" style='text-align:center'>
<i slot="unsupported">
Your browser does not support Web Serial.</br>Open this page in Google Chrome or</br>Microsoft Edge instead
<span class="not-supported-i hidden">(but not on your iOS device)</span>.
</i>
</esp-web-install-button>
</p>
</div>
<div id="drop-area">
<form class="my-form">
<p id="file_upload_infotext">Upload factory firmware with the file dialog or by dragging and dropping onto the dashed region</p>
<!-- <input type="file" id="fileElem" accept=".bin" onchange="handleFiles(this.files)" class="button"> -->
<p id="dropped_firmware"></p>
</form>
</div>
<h1>↑</h1>
<button id="fileElem" accept=".bin" onclick="openFileDialog()">Upload factory.bin</button>
<div style='text-align:right;font-size:11px;'>
<hr/>
<a href="https://esphome.github.io/esp-web-tools/" target='_blank' style='color:#aaa;'>Tasmota Installer inspired by ESP Web Tools</a>
</div>
</div>
</body>
</html>