From: Ardis Lu Date: Thu, 15 Aug 2024 05:39:49 +0000 (-0700) Subject: Add button to delete all lines in the Solidity code that do not contain events X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=58233d9ccd2cdeab0af550ed96dbe6d7688fc283;p=event-hashes Add button to delete all lines in the Solidity code that do not contain events This button is useful for identifying the original event definitions and for making permalinks smaller. --- diff --git a/index.html b/index.html index 7ff7775..0a2f7db 100644 --- a/index.html +++ b/index.html @@ -204,6 +204,10 @@ cursor: help; } } + + #clear-code { + display: none; + } @@ -222,6 +226,15 @@ + @@ -275,8 +288,10 @@ check: '', permalink: '', download: '', - clipboard: '' + clipboard: '', + clear: '' } + const originalEvents = []; async function textToGzipBase64(text) { const stream = new Blob([text]).stream(); @@ -338,6 +353,7 @@ } function getEvents(code) { + originalEvents.length = 0; const events = []; let position = 0; let strict = false; @@ -362,6 +378,7 @@ const lookaheadLine = code.substring(start, end + 1).replaceAll('\n', ''); try { const normalizedEvent = normalizeEvent(lookaheadLine, strict); + originalEvents.push(lookaheadLine); events.push(normalizedEvent); } catch { } @@ -369,6 +386,7 @@ } try { const normalizedEvent = normalizeEvent(line, strict); + originalEvents.push(line); events.push(normalizedEvent); } catch { @@ -403,6 +421,12 @@ noEventsMessage.style.setProperty('display', 'revert'); return; } + if (textarea.value.length > originalEvents.join('\n').length) { + document.querySelector('#clear-code').style.display = 'unset'; + } + else { + document.querySelector('#clear-code').style.display = 'none'; + } for (const event of uniqueEvents) { const byteArray = keccak256(encoder.encode(event)); @@ -437,6 +461,13 @@ debounceButton(e.target, icons['permalink'], 'Copy permalink to clipboard'); }); + document.querySelector('#clear-code').addEventListener('click', e => { + textarea.select(); + // Using deprecated function is required to preserve undo/redo behavior + document.execCommand('insertText', false, originalEvents.join('\n').replaceAll(/\s{2,}/g, ' ')); // .replaceAll flattens multi-line definitions + e.target.style.display = 'none'; + }); + document.querySelector('#download-table').addEventListener('click', e => { const csv = '"' + table.innerText.replaceAll('"', '""').replaceAll('\t', '","').replaceAll('\n', '"\n"') + '"'; const file = new File([csv], `Event_Hashes_${Date.now()}`, { type: 'text/csv' });