From: Ardis Lu Date: Thu, 23 Feb 2023 04:05:13 +0000 (-0800) Subject: Refactor view logic into its own function X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=472b5e2ef4b43d0a79ee49eb27629cfd2dd3cf8f;p=static-encrypt Refactor view logic into its own function --- diff --git a/index.html b/index.html index 0a7f3c4..0b118ec 100644 --- a/index.html +++ b/index.html @@ -139,6 +139,11 @@ import encrypt from '/encrypt.js'; import decrypt from '/decrypt.js'; + function setOutput(ciphertext) { + document.querySelector('#output').style.display = 'block'; + document.querySelector('#ciphertext').textContent = ciphertext; + } + function downloadHtml(htmlString, fileName) { const encodedHtml = new TextEncoder().encode(htmlString); const file = new File([encodedHtml], fileName, { type: 'text/html' }); @@ -157,8 +162,7 @@ const password = data.get('password'); const encrypted = await encrypt(content, password); - document.querySelector('#output').style.display = 'block'; - document.querySelector('#ciphertext').textContent = encrypted; + setOutput(encrypted); }); document.querySelector('#download').addEventListener('click', e => {