From 8e85f0079a59282724ebab9c7cd2c6037424f6c6 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Mon, 11 Jul 2022 19:11:49 +0200 Subject: feat: Add copy to clipboard Add a new feature to copy to clipboard. Also add a bit o styling to make it nicer to the eyes. --- index.html | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'index.html') diff --git a/index.html b/index.html index 65ee3f8..54231b4 100644 --- a/index.html +++ b/index.html @@ -32,7 +32,7 @@ header { margin-bottom: 20px; background: #0062cc; padding: 10px; - max-width: 900px; + max-width: 960px; } nav { @@ -58,6 +58,11 @@ nav { cursor: pointer; color: #000; border-radius: 0; + text-decoration: none; +} + +.btn:hover { + background-color: #fff; } nav li { @@ -90,7 +95,7 @@ main { @@ -111,7 +116,8 @@ main {

- + +
@@ -119,9 +125,31 @@ main { const aInput = document.getElementById('a') const bInput = document.getElementById('b') const cInput = document.getElementById('c') +const copyInput = document.getElementById('copy') const resultadoInput = document.getElementById('resultado') const warningParagraph = document.getElementById('warning') + +function warn(text) { + warningParagraph.textContent = text + warningParagraph.style.visibility = 'visible'; + setTimeout(() => { + warningParagraph.style.visibility = 'hidden'; + }, 3000) +} + +function copy() { + if (resultadoInput.value === "") { + eval() + } + navigator.clipboard.writeText(resultadoInput.value) + .then(u => { + copyInput.value = "COPIADO ✓" + setTimeout(() => { copyInput.value = "COPIAR ⎘" }, 3000) + }) + .catch(e => warn(e)) +} + function cToP(v) { return v.replace(",", ".") } @@ -141,11 +169,7 @@ function eval() { const result = calculate(...values).toFixed(3).replace(/\.0+$/,'') resultadoInput.value = pToC(result) } catch (e) { - warningParagraph.textContent = e - warningParagraph.style.visibility = 'visible'; - setTimeout(() => { - warningParagraph.style.visibility = 'hidden'; - }, 3000) + warn(e) } } -- cgit v1.2.3