1/* Menú móvil */ 2(function(){ 3 var btn=document.querySelector('.hamburger'); 4 var nav=document.querySelector('.movil'); 5 var ov=document.querySelector('.overlay'); 6 var x=document.querySelector('.movil-close'); 7 function open(){nav.classList.add('on');ov.classList.add('on');document.documentElement.classList.add('locked');document.body.classList.add('locked')} 8 function close(){nav.classList.remove('on');ov.classList.remove('on');document.documentElement.classList.remove('locked');document.body.classList.remove('locked')} 9 if(btn)btn.addEventListener('click',open); 10 if(ov)ov.addEventListener('click',close); 11 if(x)x.addEventListener('click',close); 12})(); 13 14/* Lazy-load AdSense */ 15(function(){ 16 var ok=false; 17 function go(){ 18 if(ok)return;ok=true; 19 var s=document.createElement('script'); 20 s.src='https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8178564232918506'; 21 s.async=true;s.crossOrigin='anonymous'; 22 document.head.appendChild(s); 23 s.onload=function(){ 24 var a=document.querySelectorAll('.adsbygoogle'); 25 for(var i=0;i<a.length;i++){try{(adsbygoogle=window.adsbygoogle||[]).push({})}catch(e){}} 26 }; 27 } 28 ['scroll','touchstart','mousemove'].forEach(function(e){ 29 window.addEventListener(e,go,{once:true,passive:true}); 30 }); 31 setTimeout(go,3000); 32})(); 33 34/* Acordeones menú móvil â event delegation */ 35(function(){ 36 var links=document.querySelector('.movil-links'); 37 if(!links)return; 38 links.addEventListener('click',function(e){ 39 var btn=e.target.closest('.movil-acc'); 40 if(!btn)return; 41 e.preventDefault(); 42 e.stopPropagation(); 43 var sub=btn.nextElementSibling; 44 if(!sub)return; 45 var open=btn.classList.toggle('on'); 46 sub.classList.toggle('on',open); 47 }); 48})(); 49 50/* Búsqueda */ 51(function(){ 52 var btn=document.querySelector('.search-open'); 53 var box=document.querySelector('.buscador'); 54 var x=document.querySelector('.buscador-x'); 55 if(btn&&box){ 56 btn.addEventListener('click',function(e){e.preventDefault();box.classList.add('on');box.querySelector('input').focus()}); 57 if(x)x.addEventListener('click',function(){box.classList.remove('on')}); 58 box.addEventListener('click',function(e){if(e.target===box)box.classList.remove('on')}); 59 } 60})(); 61 62/* Cargar más noticias */ 63(function(){ 64 var wrap=document.getElementById('cargar-mas-wrap'); 65 if(!wrap)return; 66 var btn=document.getElementById('btn-cargar-mas'); 67 var spinner=document.getElementById('cargar-mas-spinner'); 68 var grid=document.querySelector('.noticias-grid'); 69 var dominio=wrap.dataset.dominio; 70 var urlbase=wrap.dataset.urlbase; 71 var paginaActual=parseInt(wrap.dataset.paginaActual,10); 72 var totalPaginas=parseInt(wrap.dataset.totalPaginas,10); 73 74 /* Colores de categorÃa â espejo de color_categoria() PHP */ 75 var coloresCat={ 76 'nacional':'#c0392b','internacional':'#8e44ad','politica':'#c0392b', 77 'economia':'#2980b9','deportes':'#27ae60','deporte':'#27ae60', 78 'cultura':'#8e44ad','sociedad':'#e67e22','tecnologia':'#2c3e50', 79 'motor':'#34495e','sucesos':'#e74c3c','salud':'#1abc9c', 80 'educacion':'#3498db','medio-ambiente':'#27ae60','turismo':'#f39c12', 81 'consumo':'#e67e22','justicia-social':'#9b59b6','cotilleo':'#e91e63' 82 }; 83 84 function colorCat(slug){return coloresCat[slug]||null;} 85 86 /* Tiempo relativo â espejo de tiempo_relativo() PHP */ 87 function tiempoRelativo(fechaIso){ 88 var ts=Math.floor(new Date(fechaIso).getTime()/1000); 89 var diff=Math.floor(Date.now()/1000)-ts; 90 if(diff<60)return'Ahora mismo'; 91 if(diff<3600)return'Hace '+Math.floor(diff/60)+' min'; 92 if(diff<86400)return'Hace '+Math.floor(diff/3600)+'h'; 93 if(diff<604800)return'Hace '+Math.floor(diff/86400)+' dÃas'; 94 var d=new Date(fechaIso); 95 return d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear(); 96 } 97 98 /* Reciente â últimas 3 horas */ 99 function esReciente(fechaIso){ 100 return(Date.now()-new Date(fechaIso).getTime())<10800000; 101 } 102 103 /* Renderiza un artÃculo .noticia con el mismo HTML que PHP */ 104 function renderNoticia(n){ 105 var cc=colorCat(n.categoria_slug); 106 var borde=cc?'border-left-color:'+cc:'border-left-color:var(--c1)'; 107 var etiquetaStyle=cc?' style="color:'+cc+'"':''; 108 var badgeUh=esReciente(n.fecha)?'<span class="badge-uh">Ahora</span>':''; 109 return '<article class="noticia" style="'+borde+'">' 110 +'<span class="etiqueta"'+etiquetaStyle+'>'+escHtml(n.categoria)+'</span>' 111 +'<h2><a href="'+escHtml(n.slug)+'">'+escHtml(n.titulo)+'</a></h2>' 112 +'<div class="meta"><span>'+tiempoRelativo(n.fecha)+'</span>'+badgeUh+'</div>' 113 +'</article>'; 114 } 115 116 function escHtml(s){ 117 return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); 118 } 119 120 btn.addEventListener('click',function(){ 121 var siguientePag=paginaActual+1; 122 btn.disabled=true; 123 spinner.classList.add('activo'); 124 125 fetch(urlbase+'/api_noticias.php?dominio='+encodeURIComponent(dominio)+'&page='+siguientePag) 126 .then(function(r){ 127 if(!r.ok)throw new Error('HTTP '+r.status); 128 return r.json(); 129 }) 130 .then(function(data){ 131 if(!data.noticias||!data.noticias.length){ 132 wrap.style.display='none'; 133 return; 134 } 135 var html=''; 136 for(var i=0;i<data.noticias.length;i++){html+=renderNoticia(data.noticias[i]);} 137 grid.insertAdjacentHTML('beforeend',html); 138 paginaActual=siguientePag; 139 wrap.dataset.paginaActual=paginaActual; 140 if(paginaActual>=data.total_paginas){ 141 wrap.style.display='none'; 142 } else { 143 btn.disabled=false; 144 } 145 }) 146 .catch(function(){ 147 btn.disabled=false; 148 }) 149 .finally(function(){ 150 spinner.classList.remove('activo'); 151 }); 152 }); 153})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.