From c077a12a06044cb5d239a888ee869b144696e1ee Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 17 Jul 2024 21:17:10 -0700 Subject: [PATCH] Refactor to organize constants --- index.html | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index ffb3efd..5e5e07c 100644 --- a/index.html +++ b/index.html @@ -264,6 +264,19 @@ // From noble-hashes v1.4.0 import { keccak256 } from '/keccak256.js'; + const encoder = new TextEncoder(); + const textarea = document.querySelector('textarea'); + const noEventsMessage = document.querySelector('.no-events'); + const table = document.querySelector('table'); + const tableBody = document.querySelector('table tbody'); + const buttonContainer = document.querySelector('.button-container'); + const icons = { + check: '', + permalink: '', + download: '', + clipboard: '' + } + async function textToGzipBase64(text) { const stream = new Blob([text]).stream(); const compressed = stream.pipeThrough(new CompressionStream('gzip')); @@ -369,12 +382,6 @@ } } - const encoder = new TextEncoder(); - const textarea = document.querySelector('textarea'); - const noEventsMessage = document.querySelector('.no-events'); - const table = document.querySelector('table'); - const tableBody = document.querySelector('table tbody'); - const buttonContainer = document.querySelector('.button-container'); textarea.addEventListener('input', debounce(() => { noEventsMessage.style.setProperty('display', 'none'); table.style.setProperty('display', 'none'); @@ -404,16 +411,11 @@ }, 250)); // Set up buttons - const checkSVG = ''; - const permalinkSVG = ''; - const downloadSVG = ''; - const clipboardSVG = ''; - function debounceButton(button, icon, message) { button.setAttribute('aria-label', 'Copied!'); const svg = button.querySelector('svg'); svg.style.setProperty('stroke', 'green'); - svg.innerHTML = checkSVG; + svg.innerHTML = icons['check']; setTimeout(() => { svg.innerHTML = icon; svg.style.setProperty('stroke', 'currentColor'); @@ -425,7 +427,7 @@ const b64 = await textToGzipBase64(textarea.value); const url = `${location.origin}#${b64}`; navigator.clipboard.writeText(url); - debounceButton(e.target, permalinkSVG, 'Copy permalink to clipboard'); + debounceButton(e.target, icons['permalink'], 'Copy permalink to clipboard'); }); document.querySelector('#download-table').addEventListener('click', async e => { @@ -436,7 +438,7 @@ a.href = URL.createObjectURL(file); a.download = file.name; a.click(); - debounceButton(e.target, downloadSVG, 'Download table to CSV'); + debounceButton(e.target, icons['download'], 'Download table to CSV'); }); document.querySelector('#copy-table').addEventListener('click', async e => { @@ -451,7 +453,7 @@ })]; navigator.clipboard.write(data); } - debounceButton(e.target, clipboardSVG, 'Copy table to clipboard'); + debounceButton(e.target, icons['clipboard'], 'Copy table to clipboard'); }); if (location.hash !== '') { -- 2.47.3