From 657637c85b94dad55ff561a139b3390e76cd9cc9 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 27 Nov 2024 22:36:00 -0600 Subject: [PATCH] Smarter clipboard copies --- static/index.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/static/index.html b/static/index.html index d55c51b..b49d2db 100644 --- a/static/index.html +++ b/static/index.html @@ -100,6 +100,9 @@ function set(short, long) { params.set('short', short); params.set('long', long); + const oldShort = document.getElementById('short').value; + const oldLong = document.getElementById('long').value; + fetch(`./?${params.toString()}`, { method: 'POST', }).then(async (resp) => { @@ -113,9 +116,14 @@ function set(short, long) { setShortItem(newShort, 'check-square'); + // Only set the icons if we were actually setting from these inputs if (document.getElementById('short').value == short && document.getElementById('long').value == long) { document.getElementById('short-icon').setAttribute('name', 'check-square'); document.getElementById('long-icon').setAttribute('name', 'check-square'); + } + + // Only set the clipboard if the user didn't change the inputs + if (document.getElementById('short').value == oldShort && document.getElementById('long').value == oldLong) { await navigator.clipboard.writeText(`${window.location.origin}/${newShort}`); } });