document.addEventListener("DOMContentLoaded", function() { // === Botón de contraste === const btnContraste = document.getElementById("ntgCambiaContraste"); if (btnContraste) { const html = document.documentElement; // referencia al const icono = btnContraste.querySelector("i"); btnContraste.addEventListener("click", function() { // Verifica el estado actual del tema const temaActual = html.getAttribute("data-bs-theme"); if (temaActual === "dark") { html.setAttribute("data-bs-theme", "auto"); icono.classList.remove("bi-square"); icono.classList.add("bi-square-half"); } else { html.setAttribute("data-bs-theme", "dark"); icono.classList.remove("bi-square-half"); icono.classList.add("bi-square"); } }); } // === Controles de tamaño de texto === const htmlTag = document.documentElement; const btnAumentar = document.querySelector(".ntg-agrandar-texto"); const btnDisminuir = document.querySelector(".ntg-achicar-texto"); if (btnAumentar && btnDisminuir) { const maxSize = 160; // máximo const minSize = 100; // mínimo const stepUp = 20; const stepDown = 20; const getCurrentSize = () => { return htmlTag.style.fontSize ? parseInt(htmlTag.style.fontSize) : 100; }; const updateButtons = (size) => { btnAumentar.disabled = size >= maxSize; btnDisminuir.disabled = size <= minSize; }; btnAumentar.addEventListener("click", () => { let size = getCurrentSize(); if (size < maxSize) { size += stepUp; if (size > maxSize) size = maxSize; htmlTag.style.fontSize = size + "%"; } updateButtons(size); }); btnDisminuir.addEventListener("click", () => { let size = getCurrentSize(); if (size > minSize) { size -= stepDown; if (size <= minSize) { size = minSize; htmlTag.removeAttribute("style"); } else { htmlTag.style.fontSize = size + "%"; } } updateButtons(size); }); updateButtons(getCurrentSize()); } });