From fc3861b4f0cece74b86545a26e07933fd39e807c Mon Sep 17 00:00:00 2001 From: Alessandro Pignotti Date: Tue, 30 May 2023 12:35:59 +0200 Subject: [PATCH] UI: Simplified approach to IP copying support --- index.html | 15 +++++++++------ network.js | 46 ++++++++++++++++------------------------------ 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/index.html b/index.html index e55656b..4206d4d 100644 --- a/index.html +++ b/index.html @@ -76,12 +76,15 @@ __ __ _ __ ____ __ HDD 🟢 - -
- Connect via Tailscale - -
-
+ +
+
+ Connect via Tailscale + +
+ +
+
Join Discord diff --git a/network.js b/network.js index 3a68d7e..426641a 100644 --- a/network.js +++ b/network.js @@ -12,6 +12,7 @@ function setupNetworkInterface() }); const loginElem = document.getElementById("loginLink"); const statusElem = document.getElementById("networkStatus"); + const ipCopiedElem = document.getElementById("ipCopied"); const loginUrlCb = (url) => { loginElem.href = url; loginElem.target = "_blank"; @@ -33,36 +34,21 @@ function setupNetworkInterface() const netmapUpdateCb = (map) => { const ip = map.self.addresses[0]; statusElem.innerText = "IP: "+ip; - loginElem.title = "Right click to copy the IP" - loginElem.draggable = false; - const rmb_to_copy = (event) => { - // To prevent the default contexmenu from showing up when right-clicking.. - event.preventDefault(); - // Copy the IP to the clipboard. - window.navigator.clipboard.writeText(ip) - .catch((msg) => { console.log("network.js: Copy ip to clipboard: Error: " + msg) }); - - // We add the tooltip to the DOM and create the div element. - const tooltip = document.createElement("div"); - statusElem.classList.add("clicked"); - tooltip.classList.add("tooltip"); - - // Show tooltip underneath mouse when copied to clipboard. - tooltip.style.fontSize = "13px" - tooltip.style.position = "absolute" - tooltip.style.left = `${event.clientX}px` - tooltip.style.top = `${event.clientY}px` - tooltip.style.fontWeight = "bold" - tooltip.innerText = "Copied to clipboard"; - statusElem.appendChild(tooltip); - - // To remove the tooltip again after some time passes. - setTimeout(() => { - tooltip.remove(); - statusElem.classList.remove("clicked"); - }, 1500); - }; - loginElem.addEventListener("contextmenu", rmb_to_copy); + loginElem.title = "Right click to copy" + const rmb_to_copy = (event) => { + // To prevent the default contexmenu from showing up when right-clicking.. + event.preventDefault(); + // Copy the IP to the clipboard. + window.navigator.clipboard.writeText(ip) + .catch((msg) => { console.log("network.js: Copy ip to clipboard: Error: " + msg) }); + statusElem.style.visibility = "hidden"; + ipCopiedElem.style.visibility = "unset"; + setTimeout(() => { + statusElem.style.visibility = "unset"; + ipCopiedElem.style.visibility = "hidden"; + }, 2000); + }; + loginElem.addEventListener("contextmenu", rmb_to_copy); }; loginElem.style.cursor = "pointer"; loginElem.title = "Connect to Tailscale";