From 70b4195bf05a9c1ed1b242346287be462ce9e487 Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 19 Jul 2023 19:07:06 +0800 Subject: [PATCH] scan networks --- static/app.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/static/app.js b/static/app.js index 357c985..dbef308 100755 --- a/static/app.js +++ b/static/app.js @@ -3317,3 +3317,31 @@ function sendNetworkToSSID(element) { ssid_input.value = value; element.classList.add("active"); } + + +// scan nearby networks +function scanNetworks() { + var networksListReset = document.getElementById("networks-list"); + networksListReset.innerHTML = ""; + fetch("/scanNetworks", { + method: "PUT", + }) + .then(response => response.text()) + .then(data => { + // Parse the response data as JSON + var networks = JSON.parse(data); + + // Iterate over the networks object and create list items + for (var ssid in networks) { + var listItem = document.createElement("li"); + listItem.textContent = ssid; + listItem.onclick = function() { + sendNetworkToSSID(this); + }; + networksListReset.appendChild(listItem); + } + }) + .catch(error => console.log(error)); + +} +