`;
showToast("No fue posible obtener los datos de 13C.");
}
function setStatus(msg, state) {}
function showToast(msg) {
toastEl.textContent = msg;
toastEl.style.display = "block";
setTimeout(() => {
toastEl.style.display = "none";
}, 3500);
}
// Renderizado de la lista
function renderPlaylist() {
playlistContainer.innerHTML = "";
if (playlist.length === 0) {
playlistContainer.innerHTML = `
No se encontraron videos disponibles.
`;
return;
}
playlist.forEach((item, index) => {
const card = document.createElement("article");
card.className = `playlist-card ${index === currentIndex ? "is-active" : ""}`;
card.dataset.index = index;
card.innerHTML = `
▶
`;
//card.querySelector(".item-category").textContent = item.categoria;
card.querySelector(".item-title").textContent = item.titulo;
card.addEventListener("click", () => {
selectVideo(index, true);
});
playlistContainer.appendChild(card);
});
}
// Cambio de video e inicio del loader
function selectVideo(index, autoplay = true) {
if (!playlist[index]) return;
currentIndex = index;
const item = playlist[index];
// 1. Mostrar pantalla de carga
showLoading();
// 2. Actualizar textos decodificados y el atributo title del iframe
currentCategoryEl.textContent = item.programa || item.categoria || "";
currentTitleEl.textContent = item.titulo || "";
currentDescEl.textContent = item.descripcion || "";
videoIframe.title = item.programa || item.categoria || "Reproductor de Video";
// 3. Marcar tarjeta activa
const allCards = playlistContainer.querySelectorAll(".playlist-card");
allCards.forEach((card, idx) => {
if (idx === index) {
card.classList.add("is-active");
//card.scrollIntoView({ behavior: "smooth", block: "nearest" });
} else {
card.classList.remove("is-active");
}
});
// 4. Asignar nuevo enlace al iframe
let targetEmbed = item.embedUrl;
if (!autoplay) {
targetEmbed = targetEmbed.replace("autoplay=1", "autoplay=0").replace("autoplay=true", "autoplay=false");
}
if (videoIframe.src !== targetEmbed) {
videoIframe.src = targetEmbed;
} else {
hideLoading();
if (item.source === "rudo") {
try {
if (videoIframe && videoIframe.contentWindow) {
console.log('Enviando postMessage "play" a Rudo Video:', item.titulo);
videoIframe.contentWindow.postMessage("play", "*");
}
} catch (e) {}
}
}
}
function escapeHtml(str) {
if (!str) return "";
return str
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
// Inicializar al cargar el DOM
window.addEventListener("DOMContentLoaded", () => {
fetchPlaylist();
});