Spaces:
Sleeping
Sleeping
File size: 672 Bytes
8b024f2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// 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);
});
|