mypastebin/cdn/cdn/js/copy-url.js
teraflops 17bb747542
cdn
2025-05-29 22:45:18 +02:00

20 lines
658 B
JavaScript

// static/js/copy-url.js
document.addEventListener('DOMContentLoaded', function() {
const copyUrlButton = document.getElementById('copy-url-button');
// Verifica si existe el botón en la página
if (!copyUrlButton) return;
copyUrlButton.addEventListener('click', function() {
navigator.clipboard.writeText(window.location.href)
.then(function() {
// Suponiendo que showToast está disponible globalmente
showToast('URL copied to clipboard!', 'bg-success');
})
.catch(function(err) {
console.error('Error copying URL:', err);
showToast('Failed to copy URL.', 'bg-danger');
});
});
});