Spaces:
Sleeping
Sleeping
| // Add copy buttons to code blocks and auto-scroll | |
| function addCopyButtons() { | |
| document.querySelectorAll('pre code').forEach((codeBlock) => { | |
| if (codeBlock.parentElement.querySelector('.copy-btn')) return; | |
| const btn = document.createElement('button'); | |
| btn.className = 'copy-btn'; | |
| btn.textContent = 'Copiar'; | |
| btn.addEventListener('click', () => { | |
| navigator.clipboard.writeText(codeBlock.innerText); | |
| btn.textContent = 'Copiado'; | |
| setTimeout(()=> btn.textContent = 'Copiar', 1500); | |
| }); | |
| codeBlock.parentElement.insertBefore(btn, codeBlock); | |
| }); | |
| } | |
| window.addEventListener('load', () => { | |
| setInterval(addCopyButtons, 800); | |
| }); | |