-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathindex.html
More file actions
592 lines (539 loc) · 24 KB
/
index.html
File metadata and controls
592 lines (539 loc) · 24 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
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
<!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@11.1.9/dist/web/install-button.js?module"
></script>
<!-- <script type="module">import * as Module from "./js/tasmota_gh_helper.js"</script> -->
<script>
// Wait for ESP Web Tools to load and expose the CORS proxy function
async function corsProxyFetch(url, options) {
// Clean the URL first
url = url.trim();
// Wait for ESP Web Tools to be available
while (!window.espWebToolsCorsProxyFetch) {
await new Promise(resolve => setTimeout(resolve, 50));
}
return window.espWebToolsCorsProxyFetch(url, options);
}
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-C5","parts": [{ "path": "", "offset": 0 }]},
{ "chipFamily": "ESP32-C6","parts": [{ "path": "", "offset": 0 }]},
{ "chipFamily": "ESP32-C61","parts": [{ "path": "", "offset": 0 }]},
{ "chipFamily": "ESP32-P4","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").filter(line => line.length >= 10);
console.log(data);
// Remove duplicates while preserving original order information
var uniqueLines = [];
var seenLines = new Set();
lines.forEach((line, index) => {
if (!seenLines.has(line)) {
uniqueLines.push({ line: line, originalIndex: index });
seenLines.add(line);
}
});
// Sort by date (descending), then by original order (descending - later entries are newer)
uniqueLines.sort((a, b) => {
// Extract date from format: YYYY-MM-DD.{d|r}.commit
const dateA = a.line.split(".")[0];
const dateB = b.line.split(".")[0];
// Primary sort: by date descending (newest first)
const dateCompare = dateB.localeCompare(dateA);
if (dateCompare !== 0) {
return dateCompare;
}
// Secondary sort: if same date, by original index descending (later entries are newer)
return b.originalIndex - a.originalIndex;
});
// Extract just the line strings for further processing
uniqueLines = uniqueLines.map(item => item.line);
for (opt_group of uniqueLines){
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[1]=="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);
const years = Object.keys(date_filter).filter(year => year !== "").sort((a, b) => b - a);
for(const year of years){
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;
}
const months = Object.keys(date_filter[year]).sort((a, b) => a - b);
for(const month of months){
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;
}
const days = date_filter[year][month].sort((a, b) => a - b);
for(day of days){
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);
corsProxyFetch('https://raw.githubusercontent.com/tasmota/install/firmware/manifests.json')
.then(response => response.json())
.then(data => makeVariantSelector(data));
}
function getLatestTag(){
corsProxyFetch('https://raw.githubusercontent.com/tasmota/install/firmware/tag_latest.txt')
.then(x => x.text())
.then(t => testCORS(t.trim()));
}
async function testCORS(t){
// With CORS proxy, we don't need to test - just use it directly
console.log("Using CORS proxy for all requests");
initVariantSelector(t);
// Load both development and release tags
const devTagsPromise = corsProxyFetch('https://raw.githubusercontent.com/tasmota/install/firmware/tag.txt')
.then(x => x.text());
const releaseTagsPromise = corsProxyFetch('https://raw.githubusercontent.com/tasmota/install/firmware/tag_r.txt')
.then(x => x.text());
// Wait for both to load
Promise.all([devTagsPromise, releaseTagsPromise])
.then(([devTags, releaseTags]) => {
// Combine both tag lists
const combinedTags = devTags + '\n' + releaseTags;
makeReleaseSelector(combinedTags, "all");
makeDateSelector(combinedTags);
})
.catch(error => {
console.error("Error loading tags:", error);
// Fallback to just dev tags if release tags fail
corsProxyFetch('https://raw.githubusercontent.com/tasmota/install/firmware/tag.txt')
.then(x => x.text())
.then(t => {makeReleaseSelector(t,"all"); makeDateSelector(t);});
});
}
function initVariantSelector(tag){
// Clean the tag - remove whitespace and newlines
tag = tag.trim();
corsProxyFetch('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);
corsProxyFetch("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();
// Wait for ESP Web Tools module to load before making any fetch calls
function initializeApp() {
if (window.espWebToolsCorsProxyFetch) {
console.log("ESP Web Tools loaded successfully");
getLatestTag();
} else {
console.log("Waiting for ESP Web Tools to load...");
setTimeout(initializeApp, 50);
}
}
initializeApp();
// Baud rate selection
const baudRateSelect = document.getElementById('baudRate');
const installButton = document.querySelector('esp-web-install-button');
if (baudRateSelect && installButton) {
baudRateSelect.addEventListener('change', function() {
const selectedRate = this.value;
// Update install button
if (selectedRate === '') {
installButton.removeAttribute('baud-rate');
} else {
installButton.setAttribute('baud-rate', selectedRate);
}
});
}
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>
<p>Flash Speed:</p>
<select id="baudRate">
<option value="">115200 Baud (Default)</option>
<option value="230400">230400 Baud</option>
<option value="460800">460800 Baud</option>
<option value="921600">921600 Baud</option>
<option value="1500000">1500000 Baud</option>
<option value="2000000" selected>2000000 Baud (Recommended)</option>
</select>
<esp-web-install-button id="inst" style='text-align:center' baud-rate="2000000">
<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://jason2866.github.io/esp-web-tools/" target='_blank' style='color:#aaa;'>Tasmota Installer inspired by ESP Web Tools</a>
</div>
</div>
</body>
</html>