document.addEventListener('DOMContentLoaded', function () { var btn = document.querySelector('.menu-toggle'); var sidebar = document.querySelector('.sidebar'); if (btn && sidebar) { btn.addEventListener('click', function () { sidebar.classList.toggle('open'); }); } document.querySelectorAll('.copy-btn').forEach(function (button) { button.addEventListener('click', function () { var block = button.closest('.code-block'); var code = block ? block.querySelector('pre code, pre') : null; if (!code) return; var text = code.textContent; function showCopied() { var original = button.textContent; button.textContent = 'Copiado!'; button.classList.add('copied'); setTimeout(function () { button.textContent = original; button.classList.remove('copied'); }, 1800); } if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(text).then(showCopied, function () { fallbackCopy(text, showCopied); }); } else { fallbackCopy(text, showCopied); } }); }); function fallbackCopy(text, done) { var ta = document.createElement('textarea'); ta.value = text; ta.style.position = 'fixed'; ta.style.opacity = '0'; document.body.appendChild(ta); ta.focus(); ta.select(); try { document.execCommand('copy'); } catch (e) { /* no-op */ } document.body.removeChild(ta); done(); } });