TTGO-T-Beam-LoRa-APRS/data_embed/js.js
2021-02-18 17:59:18 +01:00

42 lines
1.3 KiB
JavaScript

/**/
function scanWifi() {
let scanBtn = document.getElementById('scan_wifi_btn');
let wifiListContainer = document.getElementById("wifi_list");
wifiListContainer.innerHTML = 'Scanning...';
scanBtn.disabled = true;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
scanBtn.disabled = false;
if (this.readyState == 4 && this.status == 200) {
wifiListContainer.innerHTML = this.responseText;
const networks_found_list = document.querySelector('#networks_found_list');
networks_found_list.addEventListener('change', event => {
document.getElementById('wifi_ssid').value = networks_found_list.value;
});
}
};
xhttp.open("GET", "/scan_wifi", true);
xhttp.send();
}
window.onload = function () {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
const response = JSON.parse(this.responseText);
for (const [key, value] of Object.entries(response)) {
let element = document.getElementById(key);
if (element){
if (element.type && element.type == "checkbox"){
element.checked = value;
} else {
element.value = value;
}
}
}
}
};
xhttp.open("GET", "/cfg", true);
xhttp.send();
};