Update site/src/components/CopyButton.astro

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Samuel Berthe 2026-04-10 20:57:59 +02:00 committed by GitHub
parent e056652504
commit 96731e7ee2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -43,8 +43,12 @@ const btnId = `copy-btn-${targetId}`;
</button> </button>
)} )}
<script> <script define:vars={{ btnId }}>
document.querySelectorAll<HTMLButtonElement>('.copy-btn').forEach((btn) => { const btn = document.getElementById(btnId);
if (!(btn instanceof HTMLButtonElement)) return;
if (btn.dataset.copyBound === 'true') return;
btn.dataset.copyBound = 'true';
btn.addEventListener('click', async () => { btn.addEventListener('click', async () => {
const targetId = btn.dataset.copyTarget; const targetId = btn.dataset.copyTarget;
if (!targetId) return; if (!targetId) return;
@ -83,5 +87,4 @@ const btnId = `copy-btn-${targetId}`;
copiedLabel?.classList.add('hidden'); copiedLabel?.classList.add('hidden');
}, 2000); }, 2000);
}); });
});
</script> </script>