async function copyToClipboard(text) {
if (navigator.clipboard?.writeText) {
return navigator.clipboard.writeText(text);
}
// Fallback
const el = Object.assign(document.createElement('textarea'), {
value: text,
style: 'position:fixed;opacity:0',
});
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
// Usage
button.addEventListener('click', async () => {
await copyToClipboard('Hello, world!');
button.textContent = 'Copied!';
setTimeout(() => (button.textContent = 'Copy'), 2000);
});
Create a free account and build your private vault. Share publicly whenever you want.