document.addEventListener('DOMContentLoaded', () => {
    const scrambleButtons = document.querySelectorAll('[data-scramble="true"]');

    scrambleButtons.forEach(button => {
        const wrapper = button.querySelector('.sifency-button-content-wrapper');
        if (!wrapper) return;

        const originalText = wrapper.innerText;
        const chars = '*?><[]&@#)(.%$-_:/;?!';
        let interval = null;

        button.addEventListener('mouseover', () => {
            let iteration = 0;

            clearInterval(interval);

            interval = setInterval(() => {
                wrapper.innerText = originalText
                    .split('')
                    .map((char, index) => {
                        if (index < iteration) {
                            return originalText[index];
                        }
                        return chars[Math.floor(Math.random() * chars.length)];
                    })
                    .join('');

                if (iteration >= originalText.length) {
                    clearInterval(interval);
                }

                iteration += 1 / 3;
            }, 50);
        });

        button.addEventListener('mouseout', () => {
            clearInterval(interval);
            wrapper.innerText = originalText;
        });
    });
});