From b311d282ab4d6eb9cf7b4d29973c605f376c3e70 Mon Sep 17 00:00:00 2001 From: Sebastian Davids Date: Tue, 14 Jan 2025 14:05:22 +0100 Subject: [PATCH] refactor: introduce configureCopyButton Signed-off-by: Sebastian Davids --- hp/src/j/app.mjs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/hp/src/j/app.mjs b/hp/src/j/app.mjs index 4d15610..dceffab 100644 --- a/hp/src/j/app.mjs +++ b/hp/src/j/app.mjs @@ -44,16 +44,11 @@ const writeClipboardText = async (id) => { } }; -for (const id of [ - 'encrypt-age', - 'encrypt-gpg', - 'fingerprint-gpg', - 'import-gpg', -]) { +const configureCopyButton = (id) => { /** @type HTMLButtonElement */ const btn = document.getElementById(`${id}-btn`); if (btn === null) { - continue; + return; } if (window.isSecureContext && navigator.clipboard) { btn.addEventListener('click', () => writeClipboardText(id)); @@ -61,4 +56,13 @@ for (const id of [ btn.disabled = true; btn.classList.add('opacity-0'); } +}; + +for (const id of [ + 'encrypt-age', + 'encrypt-gpg', + 'fingerprint-gpg', + 'import-gpg', +]) { + configureCopyButton(id); }