diff --git a/index.html b/index.html index 90480e5..d71b42b 100644 --- a/index.html +++ b/index.html @@ -43,12 +43,12 @@ let loginPromise = new Promise((f,r) => { resolveLogin = f; }); + const loginElem = document.getElementById("loginLink"); + const statusElem = document.getElementById("networkStatus"); const loginUrlCb = (url) => { - const a = document.getElementById("loginLink"); - a.href = url; - a.target = "_blank"; - const status = document.getElementById("networkStatus"); - status.innerHTML = "Tailscale Login"; + loginElem.href = url; + loginElem.target = "_blank"; + statusElem.innerHTML = "Tailscale Login"; resolveLogin(url); }; const stateUpdateCb = (state) => { @@ -60,8 +60,7 @@ } case State.Running: { - const a = document.getElementById("loginLink"); - a.href = "https://login.tailscale.com/admin/machines"; + loginElem.href = "https://login.tailscale.com/admin/machines"; break; } case State.Starting: @@ -80,8 +79,7 @@ }; const netmapUpdateCb = (map) => { const ip = map.self.addresses[0]; - const status = document.getElementById("networkStatus"); - status.innerHTML = "IP: "+ip; + statusElem.innerHTML = "IP: "+ip; }; const { listen, connect, bind, up } = await autoConf({ loginUrlCb, @@ -91,15 +89,15 @@ window.networkInterface.bind = bind; window.networkInterface.connect = connect; window.networkInterface.listen = listen; - window.startTailscaleAndGetLogin = async () => { - const a = document.getElementById("loginLink"); - a.onclick = null; - const status = document.getElementById("networkStatus"); - status.innerHTML = "Downloading network code..."; + loginElem.style.cursor = "pointer"; + statusElem.style.color = "white"; + loginElem.onclick = async () => { + loginElem.onclick = null; + statusElem.innerHTML = "Downloading network code..."; const w = window.open("login.html", "_blank"); await up(); w.document.body.innerHTML = "Starting login..."; - status.innerHTML = "Starting login..."; + statusElem.innerHTML = "Starting login..."; const url = await loginPromise; w.location.href = url; }; @@ -138,8 +136,8 @@