From 58233d9ccd2cdeab0af550ed96dbe6d7688fc283 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 14 Aug 2024 22:39:49 -0700 Subject: [PATCH] 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. --- index.html | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) 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' }); -- 2.47.3