Para ver perfiles o subir videos, necesitas una cuenta.
${descriptionConLinks}
${c.text}
Sé el primero en comentar...
"; } } catch (e) { list.innerHTML = "Error de conexión
"; } }; // --- ESTA ES LA QUE FALTA --- window.closeComments = function() { const modal = document.getElementById('commentModal'); if (modal) { modal.classList.remove('active'); document.body.style.overflow = 'auto'; // Rehabilitar el scroll de la página } }; // Bonus: Cerrar al hacer clic en el fondo oscuro window.addEventListener('click', (e) => { const modal = document.getElementById('commentModal'); if (e.target === modal) { window.closeComments(); } }); /* --- 3. GESTIÓN DE SHARE (COMPARTIR) --- */ window.openShare = function(videoUrl) { const modal = document.getElementById('shareModal'); if (modal) { window.currentShareVideoUrl = videoUrl; modal.classList.add('active'); } }; window.closeShare = function() { const modal = document.getElementById('shareModal'); if (modal) modal.classList.remove('active'); }; window.copyLinkGlobal = function(videoUrl) { const fullLink = window.location.origin + "?v=" + (videoUrl || window.currentShareVideoUrl); navigator.clipboard.writeText(fullLink).then(() => { alert("¡Enlace copiado!"); if(window.registrarShareEnTermux) window.registrarShareEnTermux(); window.closeShare(); }); }; /* --- 4. NAVEGACIÓN Y PERFIL --- */ window.irAlPerfil = function(username) { if (!username) return; const targetUser = username.replace('@', '').trim(); window.location.href = `../Perfil.html?user=${targetUser}`; }; window.seguirDesdeFeed = async function(usuarioASeguir, elemento) { const miID = localStorage.getItem("user_id"); if (!miID) return alert("Inicia sesión para seguir"); const server = (window.API_BASE_URL || "http://127.0.0.1:8080").replace(/\/$/, ""); try { const res = await fetch(`${server}/api/follow`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ follower: miID.replace('@','').toLowerCase(), target: usuarioASeguir.replace('@','').toLowerCase() }) }); if (res.ok) { elemento.style.transform = "scale(0)"; setTimeout(() => elemento.remove(), 300); } } catch (e) { console.error("Error follow:", e); } }; /* --- 5. BÚSQUEDA Y HASHTAGS --- */ window.buscarPorHashtag = async function(tag) { const query = tag.replace('#', ''); const server = window.API_BASE_URL || "http://127.0.0.1:8080"; try { const res = await fetch(`${server}/api/search?q=${encodeURIComponent(query)}`); const resultados = await res.json(); window.mostrarResultadosEnCuadricula(resultados, `#${query}`); } catch (err) { console.error("Error búsqueda:", err); } }; /* --- 6. INICIALIZACIÓN (VERSIÓN FINAL) --- */ document.addEventListener("DOMContentLoaded", () => { // 1. Configurar clics de la barra inferior const btnInicio = document.getElementById('nav-inicio'); const btnAdultos = document.getElementById('nav-adultos-icon'); if (btnInicio) btnInicio.onclick = () => window.syncUI('para-ti'); if (btnAdultos) btnAdultos.onclick = () => window.syncUI('adulto'); // 2. Configurar botón Perfil const btnPerfil = document.getElementById('nav-perfil'); if (btnPerfil) btnPerfil.onclick = () => window.location.href = "../Perfil.html"; // 3. LÓGICA DE CARGA INICIAL (Detección de Subida o Link) const params = new URLSearchParams(window.location.search); const videoUrl = params.get('video'); const catUrl = params.get('cat'); // <--- Capturamos la categoría del botón "VER" const videoRef = localStorage.getItem("video_referencia"); let catInicial = "para-ti"; // Prioridad 1: Si la URL dice explícitamente la categoría (del botón VER) if (catUrl) { catInicial = catUrl; } // Prioridad 2: Si el nombre del video empieza por "adulto-" else if (videoUrl && videoUrl.startsWith('adulto-')) { catInicial = "adulto"; } // Prioridad 3: Referencia guardada anteriormente else if (videoRef && videoRef.includes('adulto-')) { catInicial = "adulto"; } // 4. Ejecutar la carga del video específico si existe, o la categoría general if (videoUrl) { // Si hay un video en la URL, lo cargamos con su categoría window.loadSpecificVideo(videoUrl, catInicial); window.syncUI(catInicial, false); // Sincronizamos UI sin recargar todo el feed } else { // Si no hay video, carga normal del feed window.syncUI(catInicial); } }); window.syncUI = function(category, reloadVideos = true) { console.log("Sincronizando interfaz para:", category); window.currentCategory = category; // 1. LIMPIAR TODO (Arriba y Abajo) document.querySelectorAll('.nav-tab, .nav-item').forEach(el => { el.classList.remove('active'); }); // 2. ACTIVAR SEGÚN CATEGORÍA if (category === 'adulto') { document.getElementById('tab-adulto')?.classList.add('active'); document.getElementById('nav-adultos-icon')?.classList.add('active'); } else { document.getElementById('tab-para-ti')?.classList.add('active'); document.getElementById('nav-inicio')?.classList.add('active'); } // 3. CARGAR LOS VIDEOS (Solo si no venimos de loadSpecificVideo) if (reloadVideos && window.forceLoadVideos) { window.forceLoadVideos(category); } }; /* --- EVENTO PARA ABRIR EL MODAL AL SELECCIONAR VIDEO --- */ document.getElementById('videoInput').addEventListener('change', function(e) { const file = e.target.files ? e.target.files[0] : null; if (!file) return; const modal = document.getElementById('uploadModal'); modal.style.display = "flex"; // Usamos flex para centrar el contenido // Autocompletar título con el nombre del archivo (limpio) const cleanName = file.name.split('.').slice(0, -1).join('.'); document.getElementById('videoTitle').value = cleanName; }); /* --- FUNCIÓN DE CIERRE ACTUALIZADA --- */ window.closeUpload = function() { document.getElementById('uploadModal').style.display = "none"; document.getElementById('videoInput').value = ""; document.getElementById('videoTitle').value = ""; document.getElementById('videoDesc').value = ""; document.getElementById('videoHashtags').value = ""; // Reset del botón por si acaso quedó en "Procesando" const btn = document.getElementById('finishUpload'); btn.disabled = false; btn.innerHTML = "PUBLICAR"; }; /* --- SUBIDA CON REDIRECCIÓN INTELIGENTE --- */ window.ejecutarSubida = async function() { const fileInput = document.getElementById('videoInput'); const btn = document.getElementById('finishUpload'); const file = fileInput.files[0]; if (!file) { alert("Por favor, selecciona un video primero."); return; } btn.disabled = true; btn.innerHTML = ' SUBIENDO...'; const miAutor = { name: localStorage.getItem("user_name") || "Usuario", user: (localStorage.getItem("user_id") || "anonimo").replace(/[@ ]/g, '').toLowerCase(), photo: localStorage.getItem("user_photo") || 'https://cdn-icons-png.flaticon.com/512/3135/3135715.png' }; // 1. Guardamos la categoría elegida en una variable constante para usarla luego const selectedCat = document.getElementById('videoCategory').value; const formData = new FormData(); formData.append('video', file); const metadata = { title: document.getElementById('videoTitle').value.trim() || "Sin título", description: document.getElementById('videoDesc').value.trim(), hashtags: document.getElementById('videoHashtags').value.trim(), category: selectedCat, author: miAutor }; formData.append('metadata', JSON.stringify(metadata)); formData.append('category', selectedCat); document.getElementById('uploadModal').style.display = "none"; // --- TOAST DE PROGRESO --- const toast = document.createElement('div'); toast.id = "uploadToast"; toast.style = "position:fixed; bottom:20px; left:50%; transform:translateX(-50%); background:#1a1a1a; padding:15px; border-radius:18px; z-index:10000; width:90%; max-width:400px; border:1px solid #fe2c55; box-shadow:0 15px 35px rgba(0,0,0,0.7);"; toast.innerHTML = `