Hide copy to clipboard button if browser API is not available

This commit is contained in:
Glenn de Haan
2025-09-08 23:04:04 +02:00
parent 4b215541b2
commit 2fe4576c90

View File

@@ -508,18 +508,22 @@
spinnerCreate.style.display = ''; spinnerCreate.style.display = '';
}); });
shareButtons.forEach((el) => { shareButtons.forEach((el) => {
el.addEventListener('click', async () => { if(typeof navigator.clipboard !== 'undefined') {
try { el.addEventListener('click', async () => {
await navigator.clipboard.writeText(el.dataset.code); try {
copyNotification.style.display = ''; await navigator.clipboard.writeText(el.dataset.code);
copyNotification.style.display = '';
setTimeout(() => { setTimeout(() => {
copyNotification.style.display = 'none'; copyNotification.style.display = 'none';
}, 5000); }, 5000);
} catch (error) { } catch (error) {
console.error(error.message); console.error(error.message);
} }
}); });
} else {
el.classList.add('hidden');
}
}); });
removeButtons.forEach((el) => { removeButtons.forEach((el) => {
el.addEventListener('click', async () => { el.addEventListener('click', async () => {