async function ap_update() { const ssid = document.querySelector('#ap-ssid'); const pass = document.querySelector('#ap-password'); const response = await fetch("http://192.168.4.1/settings/ap_update", { method: "POST", headers: { 'Content-Type': 'application/json;charset=utf-8' }, body: JSON.stringify({ssid: ssid.value, pass: pass.value}) }); if (!response.ok) alert("Fail set AP settings"); } async function sta_update() { const ssid = document.querySelector('#sta-ssid'); const pass = document.querySelector('#sta-password'); const response = await fetch("http://192.168.4.1/settings/sta_update", { method: "POST", headers: { 'Content-Type': 'application/json;charset=utf-8' }, body: JSON.stringify({ssid: ssid.value, pass: pass.value}) }); if (!response.ok) alert("Fail set STA settings"); } async function admin_update() { const new_pass = document.getElementById('new-password'); const confirm_pass = document.getElementById('confirm-password'); if (new_pass.value !== confirm_pass.value) { alert("Пароли должны совпадать"); return; } const res = await fetch("http://192.168.4.1/settings/admin_update", { method: "POST", headers:{ 'Content-Type': 'application/json;charset=utf-8' }, body:JSON.stringify({new_pass: new_pass.value}) }); if (!res.ok) alert("Ошибка! Пароль не обновился"); } async function set_conn_out() { const checkbox = document.getElementById('connection-out'); const response = await fetch("http://192.168.4.1/settings/set_conn_out", { method: "POST", headers: { 'Content-Type': 'application/json;charset=utf-8' }, body: JSON.stringify({is_conn_out: checkbox.checked}) }); if (!response.ok) alert("Fail set CONN_TO_OUT settings"); } async function init() { try { const res = await fetch("http://192.168.4.1/settings/is_conn_out", { method: "GET" }); if (res.ok) { const data = await res.json(); const conn_out = document.getElementById('connection-out'); conn_out.checked = data.is_conn_out; } else { console.warn("Сервер вернул ошибку:", res.status); } } catch (error) { console.error("Ошибка при выполнении запроса:", error); } } init(); button = document.querySelector('#ap_update'); button.addEventListener('click', ap_update); button = document.querySelector('#sta_update'); button.addEventListener('click', sta_update); button = document.querySelector('#admin_update'); button.addEventListener('click', admin_update); const checkbox = document.getElementById('connection-out'); checkbox.addEventListener('change', set_conn_out);