diff --git a/static/index.html b/static/index.html index c1fc02f..19790f1 100644 --- a/static/index.html +++ b/static/index.html @@ -93,7 +93,10 @@ function error(err1, err2) { document.getElementById('err').show(); } -async function setFromInputs() { +async function setFromInputs(copy = null) { + if (copy == null) { + copy = async (v) => await navigator.clipboard.writeText(v); + } const short = document.getElementById('short').value; const long = document.getElementById('long').value; @@ -105,10 +108,10 @@ async function setFromInputs() { document.getElementById('short-icon').setAttribute('name', 'check-square-fill'); document.getElementById('long-icon').setAttribute('name', 'check-square-fill'); - await set(short, long); + await set(short, long, copy); } -async function set(short, long) { +async function set(short, long, copy) { if (short != '') { setShortItem(short, 'check-square-fill'); } @@ -128,7 +131,7 @@ async function set(short, long) { }); } catch (err) { console.log(err); - setTimeout(async () => await set(short, long), 5000); + setTimeout(async () => await set(short, long, copy), 5000); return; } @@ -151,7 +154,7 @@ async function set(short, long) { // Only set the clipboard if the user didn't change the inputs if (document.getElementById('short').value == oldShort && document.getElementById('long').value == oldLong) { try { - await navigator.clipboard.writeText(`${window.location.origin}/${newShort}`); + await copy(`${window.location.origin}/${newShort}`); } catch (err) { console.log(err); } @@ -237,7 +240,8 @@ document.addEventListener('DOMContentLoaded', async () => { document.getElementById('short').addEventListener('paste', async () => { if (document.getElementById('long').value != '') { - setTimeout(async () => await setFromInputs(), 0); + const copy = async (v) => await navigator.clipboard.writeText(v); + setTimeout(async () => await setFromInputs(copy), 0); } }); @@ -261,7 +265,8 @@ document.addEventListener('DOMContentLoaded', async () => { document.getElementById('long').addEventListener('paste', () => { if (document.getElementById('short').value != '') { - setTimeout(async () => await setFromInputs(), 0); + const copy = async (v) => await navigator.clipboard.writeText(v); + setTimeout(async () => await setFromInputs(copy), 0); } });