Skip to content

Commit

Permalink
refactor: introduce configureCopyButton
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Davids <[email protected]>
  • Loading branch information
sdavids committed Jan 14, 2025
1 parent 6dc87f3 commit b311d28
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions hp/src/j/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,25 @@ 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));
} else {
btn.disabled = true;
btn.classList.add('opacity-0');
}
};

for (const id of [
'encrypt-age',
'encrypt-gpg',
'fingerprint-gpg',
'import-gpg',
]) {
configureCopyButton(id);
}

0 comments on commit b311d28

Please sign in to comment.