16 lines
538 B
JavaScript
16 lines
538 B
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
const copyButtons = document.querySelectorAll('[data-copy]');
|
|
copyButtons.forEach((btn) => {
|
|
btn.addEventListener('click', () => {
|
|
const value = btn.getAttribute('data-copy');
|
|
if (!value) return;
|
|
navigator.clipboard.writeText(value).then(() => {
|
|
btn.innerText = btn.getAttribute('data-copied') || 'Copied';
|
|
setTimeout(() => {
|
|
btn.innerText = btn.getAttribute('data-default') || 'Copy';
|
|
}, 1800);
|
|
});
|
|
});
|
|
});
|
|
});
|