document.addEventListener('DOMContentLoaded', function () {
    const copyButtons = document.querySelectorAll('.copyButton');
    const successMessage = document.getElementById('successMessage');

    copyButtons.forEach(button => {
        button.addEventListener('click', function () {
            const copyInput = button.querySelector('.copyInput');

            copyInput.select();
            copyInput.setSelectionRange(0, 99999); // For mobile devices

            navigator.clipboard.writeText(copyInput.value).then(function () {
                successMessage.textContent = "Copied Link: " + copyInput.value;
                successMessage.classList.add('show-message');
                successMessage.classList.remove('hide-message');

                setTimeout(function () {
                    successMessage.classList.remove('show-message');
                    successMessage.classList.add('hide-message');
                }, 10000);
            }, function (err) {
                console.error('Async: Could not copy text: ', err);
            });
        });
    });
});
