bep40 commited on
Commit
702a71e
·
verified ·
1 Parent(s): 0af187e

Restore homepage features: livescore, shorts, highlights, league highlights, AI wall, World Cup 2026 from TheThaoVanHoa

Browse files
Files changed (1) hide show
  1. static/index.html +20 -13
static/index.html CHANGED
@@ -4,26 +4,28 @@
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
6
  <title>VNEWS - Tin Tức Việt Nam</title>
7
- <meta name="description" content="Tin tức tổng hợp, bóng đá trực tiếp, video highlight.">
8
  <meta property="og:title" content="VNEWS - Tin Tức Việt Nam">
9
  <meta property="og:image" content="https://s1.vnecdn.net/vnexpress/restruct/i/v9505/logo_default.jpg">
10
  <link rel="canonical" href="https://bep40-vnews.hf.space">
11
  <script src="https://cdn.jsdelivr.net/npm/hls.js@1/dist/hls.min.js"></script>
12
  <style>
13
- *{box-sizing:border-box;margin:0;padding:0}body{background:#111;color:#eee;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;overflow-x:hidden}.header{background:linear-gradient(135deg,#0d1117,#1a3a2a 50%,#8b7500);padding:12px;text-align:center}.header h1{font-size:18px}.header p{font-size:10px;color:#aaa}.cats{display:flex;overflow-x:auto;background:#1a1a1a;border-bottom:1px solid #333;padding:0 4px;position:sticky;top:0;z-index:50;scrollbar-width:none}.cat{padding:9px 11px;color:#888;font-size:11px;white-space:nowrap;border-bottom:2px solid transparent;cursor:pointer}.cat.active{color:#5cb87a;border-bottom-color:#5cb87a;font-weight:700}.view{display:none}.view.active{display:block}.loading{text-align:center;padding:30px;color:#777;font-size:12px}.slider-wrap,.ls-section{margin:6px 4px;background:#1a1a1a;border:1px solid #2a2a2a;border-radius:8px;overflow:hidden}.slider-header,.ls-header{padding:7px 10px}.slider-label,.ls-header h3{color:#f0c040;font-size:13px;font-weight:800}.slider-track{display:flex;overflow-x:auto;gap:8px;padding:4px 10px 10px;scrollbar-width:none}.slider-item{flex:0 0 160px;cursor:pointer}.shorts-item{flex:0 0 110px!important}.slider-thumb{position:relative;width:100%;aspect-ratio:16/9;border-radius:6px;overflow:hidden;background:#333}.shorts-thumb{aspect-ratio:3/4!important;border-radius:8px!important}.slider-thumb img,.card-img img{width:100%;height:100%;object-fit:cover}.slider-title{font-size:10px;color:#ccc;margin-top:3px;line-height:1.25;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.card-play{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:30px;height:30px;border-radius:50%;background:rgba(0,0,0,.55);display:flex;align-items:center;justify-content:center;color:#fff;font-size:12px}.grid{display:grid;grid-template-columns:repeat(2,1fr);gap:6px;padding:6px 4px}@media(min-width:650px){.grid{grid-template-columns:repeat(3,1fr)}}.card{background:#1a1a1a;border:1px solid #222;border-radius:8px;overflow:hidden;cursor:pointer}.card-img{position:relative;aspect-ratio:16/9;background:#333}.card-body{padding:6px 8px}.card-title{font-size:11px;line-height:1.35;color:#eee;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.badge{font-size:8px;padding:1px 5px;border-radius:3px;font-weight:700;display:inline-block;margin-bottom:2px}.badge-vne{background:#c0392b}.badge-bbc{background:#b80000}.badge-dt{background:#1565c0}.badge-genk{background:#6a1b9a}.badge-fpt{background:#f26522}.badge-bdp{background:#1a5c35}.section-title{font-size:13px;font-weight:800;color:#5cb87a;margin:8px 0 4px;padding-left:8px;border-left:3px solid #5cb87a}.back-btn{background:#111;color:#fff;border:none;padding:10px;font-size:12px;width:100%;position:sticky;top:0;z-index:60}.article-view{padding:12px 8px 40px;max-width:760px;margin:0 auto}.article-title{font-size:18px;font-weight:800;line-height:1.3;margin-bottom:8px}.article-summary{background:#1a2a1f;border-left:3px solid #2d8659;padding:10px;margin-bottom:14px;color:#ccc;font-size:13px}.article-p{font-size:14px;line-height:1.7;color:#ccc;margin-bottom:10px}.article-img{width:100%;border-radius:6px;margin:10px 0}.article-h2{font-size:16px;margin:16px 0 8px}.article-actions{display:flex;gap:8px;flex-wrap:wrap;border-top:1px solid #333;margin-top:16px;padding-top:10px}.article-actions button{background:#1a1a1a;border:1px solid #333;color:#ccc;padding:7px 12px;border-radius:14px;font-size:11px}.featured-match{margin:6px 4px;background:linear-gradient(135deg,#1a2a1f,#0d1117);border:1px solid #2d8659;border-radius:10px;padding:12px;cursor:pointer}.fm-league{text-align:center;color:#5cb87a;font-size:9px;font-weight:700;text-transform:uppercase}.fm-teams{display:flex;align-items:center;justify-content:center;gap:10px;margin-top:6px}.fm-team{flex:1;display:flex;flex-direction:column;align-items:center;gap:4px}.fm-team img{width:32px;height:32px;object-fit:contain}.fm-team span{font-size:10px;color:#ccc;text-align:center}.fm-score{font-size:22px;font-weight:900;min-width:60px;text-align:center}.fm-status{text-align:center;margin-top:6px;font-size:9px;color:#e74c3c;font-weight:700}.fm-status.upcoming{color:#f0c040}.ls-tabs{display:flex;gap:4px;padding:0 10px 8px;overflow-x:auto;scrollbar-width:none}.ls-tab{padding:4px 10px;background:#222;border:1px solid #333;border-radius:12px;color:#999;font-size:10px;white-space:nowrap;cursor:pointer}.ls-tab.active{background:#2d8659;border-color:#2d8659;color:#fff;font-weight:700}.ls-content{max-height:420px;overflow-y:auto;padding:0 6px 8px}.ls-content .matchs-league{list-style:none}.ls-content .title-content{display:flex;gap:6px;align-items:center;background:#222;border-radius:4px;margin:4px 0;padding:4px 6px}.ls-content .title-content img{width:16px;height:16px}.ls-content .title-content strong{font-size:11px}.ls-content .match-detail{padding:5px 6px;border-bottom:1px solid #222;cursor:pointer}.ls-content .match{display:flex;flex-wrap:wrap;align-items:center;gap:4px}.ls-content .datetime{width:100%;font-size:9px;color:#888}.ls-content .teams{display:flex;width:100%;align-items:center;gap:4px}.ls-content .team{flex:1;display:flex;align-items:center;gap:4px;text-decoration:none;min-width:0}.ls-content .team .name{font-size:11px;color:#ddd;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ls-content .team .logo img{width:18px;height:18px}.ls-content .home-team{justify-content:flex-end;text-align:right}.ls-content .status{flex:0 0 50px;text-align:center}.ls-content .status a{color:#fff;text-decoration:none;font-weight:800;font-size:12px}.ls-content .status .label{font-size:8px;color:#888;display:block}.ls-content .status .label.live{color:#e74c3c}.ls-content .info,.ls-content .btns{display:none}.match-overlay{position:fixed;inset:0;background:#111;z-index:9999;display:none;flex-direction:column;overflow:auto}.match-overlay.active{display:flex}.mo-header{padding:10px;background:#1a1a1a;display:flex;justify-content:space-between;align-items:center;position:sticky;top:0;z-index:1}.mo-header h3{font-size:13px}.mo-close{background:none;border:0;color:#fff;font-size:22px}.mo-tabs{display:flex;gap:4px;padding:8px 10px;background:#1a1a1a}.mo-tab{padding:5px 12px;background:#222;border:1px solid #333;border-radius:10px;color:#999;font-size:10px}.mo-tab.active{background:#2d8659;color:#fff}.mo-body{padding:8px;overflow-x:auto}.vp-wrap{background:#000;width:100%;aspect-ratio:1/1;position:relative}.vp-wrap.wide{aspect-ratio:16/9}.vp-wrap video,.vp-wrap iframe{width:100%;height:100%;object-fit:contain;border:none}.vp-ratio-btn{position:absolute;right:8px;top:8px;z-index:5;background:rgba(0,0,0,.6);border:1px solid #777;color:#fff;border-radius:12px;padding:3px 8px;font-size:9px}.vp-title{padding:8px 10px;background:#1a1a1a;font-size:13px;font-weight:700}.pl-list{padding:4px}.pl-item{display:flex;gap:8px;padding:8px 6px;border-bottom:1px solid #1a1a1a;border-radius:6px}.pl-item.active{background:#1a2a1f;border:1px solid #2d8659}.pl-item-thumb{flex:0 0 100px;aspect-ratio:16/9;border-radius:4px;overflow:hidden;background:#333;position:relative}.pl-item-thumb img{width:100%;height:100%;object-fit:cover}.pl-item-title{font-size:11px;color:#ccc;line-height:1.3}.tiktok-container{width:100%;height:80vh;max-height:680px;min-height:400px;background:#000}.tiktok-feed{height:100%;overflow-y:scroll;scroll-snap-type:y mandatory;scrollbar-width:none}.tiktok-slide{height:80vh;max-height:680px;min-height:400px;scroll-snap-align:start;position:relative;background:#000;display:flex;align-items:center;justify-content:center}.tiktok-slide video,.tiktok-slide iframe{width:100%;height:100%;object-fit:contain;border:none}.tiktok-bottom{position:absolute;bottom:0;left:0;right:60px;padding:12px 10px 16px;background:linear-gradient(transparent,rgba(0,0,0,.85))}.tiktok-title{font-size:12px;color:#fff}.tiktok-counter{position:absolute;top:8px;left:8px;background:rgba(0,0,0,.5);font-size:9px;padding:2px 7px;border-radius:8px}.tiktok-right{position:absolute;right:8px;bottom:100px}.tiktok-right-btn{background:none;border:0;color:#fff}.tiktok-right-btn .icon{width:42px;height:42px;border-radius:50%;background:rgba(255,255,255,.12);display:flex;align-items:center;justify-content:center;font-size:20px}
14
  </style>
15
  </head>
16
  <body>
17
- <div class="header"><h1>📰 VNEWS</h1><p>Tin tức · Video · Bóng đá trực tiếp</p></div>
18
  <div class="cats" id="cat-bar"></div>
19
  <div id="view-home" class="view active"><div class="loading">Đang tải...</div></div>
20
  <div id="view-cat" class="view"></div><div id="view-video" class="view"></div><div id="view-tiktok" class="view"></div><div id="view-article" class="view"></div>
21
  <div class="match-overlay" id="match-overlay"><div class="mo-header"><h3 id="mo-title">Chi tiết trận đấu</h3><button class="mo-close" onclick="closeMatch()">✕</button></div><div class="mo-tabs"><span class="mo-tab active" onclick="loadMatchTab('comm')">Diễn biến</span><span class="mo-tab" onclick="loadMatchTab('stats')">Thống kê</span></div><div class="mo-body" id="mo-body"><div class="loading">Đang tải...</div></div></div>
22
  <script>
23
- const SPACE=location.origin;let _cats=[],_tikData=[],_currentEventId='',_featuredEventId='',_hlLeagueData={},_vpHls=null;
24
- const HL_CONFIG={"premier-league":{name:"Premier League",emoji:"🏴"},"fa-cup":{name:"FA Cup",emoji:"🏆"},"champions-league":{name:"Champions League",emoji:"⭐"},"europa-league":{name:"Europa League",emoji:"🟠"},"la-liga":{name:"La Liga",emoji:"🇪🇸"},"serie-a":{name:"Serie A",emoji:"🇮🇹"},"bundesliga":{name:"Bundesliga",emoji:"🇩🇪"},"world-cup":{name:"Đường đến World Cup 2026",emoji:"🌍"}};
 
25
  function doShareVideo(title,url,img,type){const shareUrl=SPACE+'/v?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&img='+encodeURIComponent(img||'')+'&type='+encodeURIComponent(type||'highlights');if(navigator.share)navigator.share({title:'🎬 '+title,url:shareUrl}).catch(()=>{});else navigator.clipboard.writeText(shareUrl).then(()=>alert('Đã sao chép link!')).catch(()=>{})}
26
  function doShare(title,url,img){const shareUrl=SPACE+'/s?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&img='+encodeURIComponent(img||'');if(navigator.share)navigator.share({title,url:shareUrl}).catch(()=>{});else navigator.clipboard.writeText(shareUrl).then(()=>alert('Đã sao chép!')).catch(()=>{})}
 
27
  async function openMatch(id){if(!id)return;_currentEventId=id;document.getElementById('match-overlay').classList.add('active');document.body.style.overflow='hidden';loadMatchTab('comm')}
28
  function closeMatch(){document.getElementById('match-overlay').classList.remove('active');document.body.style.overflow=''}
29
  async function loadMatchTab(tab){document.querySelectorAll('.mo-tab').forEach(t=>t.classList.remove('active'));document.querySelectorAll('.mo-tab').forEach(t=>{if((tab==='comm'&&t.textContent==='Diễn biến')||(tab==='stats'&&t.textContent==='Thống kê'))t.classList.add('active')});const el=document.getElementById('mo-body');el.innerHTML='<div class="loading">Đang tải...</div>';try{const r=await fetch(tab==='stats'?`/api/match/${_currentEventId}/stats`:`/api/match/${_currentEventId}/commentaries`);const d=await r.json();el.innerHTML=d.html||'<div class="loading">Không có dữ liệu</div>'}catch(e){el.innerHTML='<div class="loading">Lỗi</div>'}}
@@ -33,19 +35,24 @@ async function loadLivescore(tab){_lsTab=tab;document.querySelectorAll('.ls-tab'
33
  setInterval(()=>{if(_lsTab==='live')loadLivescore('live')},60000);
34
  async function refreshFeatured(){try{const r=await fetch('/api/livescore/featured');const f=await r.json();if(!f||!f.home)return;_featuredEventId=f.event_id;const el=document.querySelector('.featured-match');if(!el)return;const sc=f.status==='live'?'':'upcoming';const st=f.status==='live'?`🔴 ${f.minute||'LIVE'}`:`⏰ ${f.time}`;el.querySelector('.fm-league').textContent=f.league;el.querySelector('.fm-score').textContent=f.score||'VS';el.querySelector('.fm-status').className='fm-status '+sc;el.querySelector('.fm-status').textContent=st;el.setAttribute('onclick',`openMatch('${f.event_id}')`)}catch(e){}}
35
  setInterval(refreshFeatured,30000);
36
- async function init(){_cats=await fetch('/api/categories').then(r=>r.json()).catch(()=>[]);let bar='<div class="cat active" data-cat="home">🏠</div><div class="cat" data-cat="video">🎬 Video</div>';_cats.forEach(c=>bar+=`<div class="cat" data-cat="${c.id}">${c.name}</div>`);document.getElementById('cat-bar').innerHTML=bar;document.querySelectorAll('.cat').forEach(t=>t.onclick=()=>switchCat(t.dataset.cat));await loadHome()}
37
  function switchCat(id){document.querySelectorAll('.cat').forEach(x=>x.classList.remove('active'));document.querySelector(`[data-cat="${id}"]`)?.classList.add('active');document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.querySelectorAll('video').forEach(v=>{v.pause();if(v._hls){v._hls.destroy();v._hls=null}});if(_vpHls){_vpHls.destroy();_vpHls=null}document.querySelectorAll('iframe[data-yt-src]').forEach(f=>{f.src=''});if(id==='home'){document.getElementById('view-home').classList.add('active')}else if(id==='video'){document.getElementById('view-video').classList.add('active');loadVideos()}else{document.getElementById('view-cat').classList.add('active');loadCat(id)}}
38
  function showView(id){document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.getElementById(id).classList.add('active')}
39
- async function openLeaguePlayer(league,idx){showView('view-tiktok');document.querySelectorAll('.cat').forEach(x=>x.classList.remove('active'));const el=document.getElementById('view-tiktok');el.innerHTML='<div class="loading">Đang tải video...</div>';const articles=_hlLeagueData[league]||[];if(!articles.length){el.innerHTML='<div class="loading">Không có video</div>';return}const cfg=HL_CONFIG[league]||{name:league,emoji:'🎬'};let h=`<button class="back-btn" onclick="switchCat('home')">← ${cfg.emoji} ${cfg.name}</button><div class="vp-wrap" id="vp-wrap"><video id="vp-video" playsinline controls loop></video><button class="vp-ratio-btn" onclick="toggleRatio()">16:9</button></div><div class="vp-title" id="vp-title"></div><div class="pl-list" id="pl-list">`;articles.forEach((a,i)=>{h+=`<div class="pl-item${i===idx?' active':''}" data-idx="${i}" onclick="playFromList('${league}',${i})"><div class="pl-item-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="pl-item-body"><div class="pl-item-title">${a.title}</div></div></div>`});h+='</div>';el.innerHTML=h;playFromList(league,idx)}
40
- async function playFromList(league,idx){const a=(_hlLeagueData[league]||[])[idx];if(!a)return;document.querySelectorAll('.pl-item').forEach(x=>x.classList.remove('active'));document.querySelector(`.pl-item[data-idx="${idx}"]`)?.classList.add('active');const titleEl=document.getElementById('vp-title');if(titleEl)titleEl.textContent=a.title;const video=document.getElementById('vp-video');if(!video)return;if(_vpHls){_vpHls.destroy();_vpHls=null}video.removeAttribute('src');video.innerHTML='';const r=await fetch('/api/video_url?url='+encodeURIComponent(a.link));const v=await r.json();if(!v||!v.src){titleEl.textContent=a.title+' (lỗi)';return}if(v.type==='youtube'){video.parentElement.innerHTML=`<iframe src="${v.src}" allowfullscreen allow="accelerometer;autoplay;clipboard-write;encrypted-media;gyroscope;picture-in-picture" style="width:100%;height:100%;border:none"></iframe>`;return}if(v.poster)video.poster=v.poster;if(v.type==='hls'&&Hls.isSupported()){_vpHls=new Hls({maxBufferLength:60,maxMaxBufferLength:120,maxBufferSize:30*1000*1000,startLevel:-1});_vpHls.loadSource(v.src);_vpHls.attachMedia(video);_vpHls.on(Hls.Events.MANIFEST_PARSED,()=>video.play().catch(()=>{}));_vpHls.on(Hls.Events.ERROR,(e,d)=>{if(d.fatal&&d.type===Hls.ErrorTypes.NETWORK_ERROR)_vpHls.startLoad()})}else{video.src=v.src;video.play().catch(()=>{})}video.scrollIntoView({behavior:'smooth',block:'start'})}
41
- async function loadHome(){const[news,sh,dantri,featured,hlLeagues]=await Promise.all([fetch('/api/homepage').then(r=>r.json()).catch(()=>[]),fetch('/api/shorts').then(r=>r.json()).catch(()=>[]),fetch('/api/genk_ai').then(r=>r.json()).catch(()=>[]),fetch('/api/livescore/featured').then(r=>r.json()).catch(()=>null),fetch('/api/highlights/leagues').then(r=>r.json()).catch(()=>({}))]);_hlLeagueData=hlLeagues;let h='';if(featured&&featured.home){_featuredEventId=featured.event_id;const sc=featured.status==='live'?'':'upcoming';const st=featured.status==='live'?`🔴 ${featured.minute||'LIVE'}`:`⏰ ${featured.time}`;h+=`<div class="featured-match" onclick="openMatch('${featured.event_id}')"><div class="fm-league">${featured.league}</div><div class="fm-teams"><div class="fm-team"><img src="${featured.home_logo}" onerror="this.style.display='none'"><span>${featured.home}</span></div><div class="fm-score">${featured.score||'VS'}</div><div class="fm-team"><img src="${featured.away_logo}" onerror="this.style.display='none'"><span>${featured.away}</span></div></div><div class="fm-status ${sc}">${st}</div></div>`}
42
  h+=`<div class="ls-section"><div class="ls-header"><h3>⚽ Livescore</h3></div><div class="ls-tabs"><span class="ls-tab active" data-tab="live" onclick="loadLivescore('live')">🔴 Live</span><span class="ls-tab" data-tab="incoming" onclick="loadLivescore('incoming')">⏰ Sắp tới</span><span class="ls-tab" data-tab="results" onclick="loadLivescore('results')">✅ Kết quả</span><span class="ls-tab" data-tab="today" onclick="loadLivescore('today')">📅 Hôm nay</span><span class="ls-tab" data-tab="bxh_nha" onclick="loadLivescore('bxh_nha')">🏆 NHA</span><span class="ls-tab" data-tab="bxh_laliga" onclick="loadLivescore('bxh_laliga')">🏆 La Liga</span><span class="ls-tab" data-tab="bxh_seriea" onclick="loadLivescore('bxh_seriea')">🏆 Serie A</span><span class="ls-tab" data-tab="bxh_bundesliga" onclick="loadLivescore('bxh_bundesliga')">🏆 Bundesliga</span><span class="ls-tab" data-tab="bxh_ligue1" onclick="loadLivescore('bxh_ligue1')">🏆 Ligue 1</span></div><div class="ls-content" id="ls-content"><div class="loading" style="padding:20px">Đang tải...</div></div></div>`;
43
- if(sh&&sh.length){h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">📱 Shorts · FPT Bóng Đá</span></div><div class="slider-track">';sh.forEach((a,i)=>{h+=`<div class="slider-item shorts-item" onclick="openTikTok('shorts',${i})"><div class="slider-thumb shorts-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`});h+='</div></div>'}
 
44
  for(const[key,cfg] of Object.entries(HL_CONFIG)){const vids=hlLeagues[key];if(!vids||!vids.length)continue;h+=`<div class="slider-wrap"><div class="slider-header"><span class="slider-label">${cfg.emoji} ${cfg.name}</span></div><div class="slider-track">`;vids.slice(0,8).forEach((a,i)=>{h+=`<div class="slider-item" onclick="openLeaguePlayer('${key}',${i})"><div class="slider-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`});h+='</div></div>'}
45
- if(dantri&&dantri.length){h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">🤖 Ứng dụng AI</span></div><div class="slider-track">';dantri.forEach(a=>{h+=`<div class="slider-item" onclick="readArticle('${a.link.replace(/'/g,"\\'")}','genk')"><div class="slider-thumb">${a.img?`<img src="${a.img}">`:''}</div><div class="slider-title">${a.title}</div></div>`});h+='</div></div>'}
46
- const groups={};news.forEach(a=>{if(!groups[a.group])groups[a.group]=[];groups[a.group].push(a)});for(const[g,arts] of Object.entries(groups)){h+=`<div class="section-title">${g}</div><div class="grid">`;arts.slice(0,6).forEach(a=>{const bg=a.source==='bbc'?'badge-bbc':a.source==='dantri'?'badge-dt':a.source==='genk'?'badge-genk':'badge-vne';const lb=a.source==='bbc'?'BBC':a.source==='dantri'?'DT':a.source==='genk'?'GenK':'VnE';h+=`<div class="card" onclick="readArticle('${a.link.replace(/'/g,"\\'")}','${a.source}')"><div class="card-img">${a.img?`<img src="${a.img}">`:''}</div><div class="card-body"><span class="badge ${bg}">${lb}</span><div class="card-title">${a.title}</div></div></div>`});h+='</div>'}document.getElementById('view-home').innerHTML=h;loadLivescore('live')}
 
 
 
 
47
  async function loadCat(id){const el=document.getElementById('view-cat');el.innerHTML='<div class="loading">Đang tải...</div>';const arts=await fetch('/api/category/'+id).then(r=>r.json()).catch(()=>[]);if(!arts.length){el.innerHTML='<div class="loading">Không có tin</div>';return}let h='<div class="grid">';arts.forEach(a=>{const bg=a.source==='bbc'?'badge-bbc':a.source==='dantri'?'badge-dt':a.source==='genk'?'badge-genk':'badge-vne';h+=`<div class="card" onclick="readArticle('${a.link.replace(/'/g,"\\'")}','${a.source}')"><div class="card-img">${a.img?`<img src="${a.img}">`:''}</div><div class="card-body"><span class="badge ${bg}">${a.source}</span><div class="card-title">${a.title}</div></div></div>`});h+='</div>';el.innerHTML=h}
48
- async function readArticle(url,source){if(source!=='vne'&&source!=='bbc'&&source!=='dantri'&&source!=='genk'){window.open(url,'_blank');return}showView('view-article');const el=document.getElementById('view-article');el.innerHTML='<div class="loading">Đang tải...</div>';const data=await fetch('/api/article?url='+encodeURIComponent(url)).then(r=>r.json()).catch(()=>null);if(!data||data.error||!data.body||!data.body.length){el.innerHTML=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="loading"><a href="${url}" target="_blank" style="color:#5cb87a">Mở link gốc</a></div>`;return}let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view"><h1 class="article-title">${data.title}</h1>`;if(data.summary)h+=`<div class="article-summary">${data.summary}</div>`;let lastImg='';data.body.forEach(b=>{if(b.type==='p')h+=`<p class="article-p">${b.text}</p>`;else if(b.type==='img'&&b.src&&b.src!==lastImg){lastImg=b.src;h+=`<img class="article-img" src="${b.src}">`}else if(b.type==='heading')h+=`<h2 class="article-h2">${b.text}</h2>`});h+=`<div class="article-actions"><button onclick="doShare('${(data.title||'').replace(/'/g,"\\'")}','${url.replace(/'/g,"\\'")}','')">📤 Chia sẻ</button><button onclick="window.open('${url}','_blank')">🔗 Gốc</button></div></div>`;el.innerHTML=h;window.scrollTo(0,0)}
 
49
  async function loadVideos(){const el=document.getElementById('view-video');if(el.dataset.loaded)return;el.innerHTML='<div class="loading">Đang tải...</div>';const[hl,bdp]=await Promise.all([fetch('/api/highlights').then(r=>r.json()).catch(()=>[]),fetch('/api/bdp_videos').then(r=>r.json()).catch(()=>[])]);let h='<div class="section-title">🎬 Highlight</div><div class="grid">';hl.forEach((a,i)=>{h+=`<div class="card" onclick="openTikTok('highlights',${i})"><div class="card-img">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge badge-fpt">HL</span><div class="card-title">${a.title}</div></div></div>`});h+='</div>';if(bdp.length){h+='<div class="section-title">⚽ BDP</div><div class="grid">';bdp.forEach((a,i)=>{h+=`<div class="card" onclick="openTikTok('bdp',${i})"><div class="card-img">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge badge-bdp">BDP</span><div class="card-title">${a.title}</div></div></div>`});h+='</div>'}el.innerHTML=h;el.dataset.loaded='1'}
50
  async function openTikTok(type,startIdx){showView('view-tiktok');document.querySelectorAll('.cat').forEach(x=>x.classList.remove('active'));const el=document.getElementById('view-tiktok');el.innerHTML='<div class="loading">Đang tải video...</div>';let articles;if(type==='shorts')articles=await fetch('/api/shorts').then(r=>r.json()).catch(()=>[]);else if(type==='highlights')articles=await fetch('/api/highlights').then(r=>r.json()).catch(()=>[]);else articles=await fetch('/api/bdp_videos').then(r=>r.json()).catch(()=>[]);await buildTikTokPlayer(articles,startIdx,type)}
51
  async function buildTikTokPlayer(articles,startIdx,type){const el=document.getElementById('view-tiktok');const vids=[];const results=await Promise.all(articles.map(async(a,i)=>{try{const r=await fetch('/api/video_url?url='+encodeURIComponent(a.link));const v=await r.json();if(v&&v.src)return{article:a,video:v,idx:i}}catch(e){}return null}));results.forEach(r=>{if(!r)return;const{article:a,video:v,idx:i}=r;vids.push({...a,...v,_idx:i})});vids.sort((a,b)=>a._idx-b._idx);if(!vids.length){el.innerHTML='<div class="loading">Không tìm thấy video</div>';return}let ti=vids.findIndex(v=>v._idx===startIdx);if(ti<0)ti=0;const ordered=ti>0?[...vids.slice(ti),...vids.slice(0,ti)]:vids;_tikData=ordered;let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="tiktok-container"><div class="tiktok-feed" id="tiktok-feed">`;ordered.forEach((v,i)=>{const isYT=v.type==='youtube';const isHLS=!isYT&&v.src&&v.src.includes('.m3u8');const poster=v.poster?` poster="${v.poster}"`:'';const vtag=isYT?`<iframe data-yt-src="${v.src}" allowfullscreen allow="accelerometer;autoplay;clipboard-write;encrypted-media;gyroscope;picture-in-picture"></iframe>`:isHLS?`<video playsinline preload="none"${poster} data-hls="${v.src}" loop controls></video>`:`<video playsinline preload="none"${poster} loop controls><source src="${v.src}" type="video/mp4"></video>`;h+=`<div class="tiktok-slide" id="tslide-${i}">${vtag}<div class="tiktok-bottom"><span class="badge badge-fpt">VIDEO</span><p class="tiktok-title">${v.title}</p></div><div class="tiktok-right"><button class="tiktok-right-btn" onclick="event.stopPropagation();shareVid(${i})"><div class="icon">📤</div></button></div><span class="tiktok-counter">${i+1}/${ordered.length}</span></div>`});h+='</div></div>';el.innerHTML=h;initFeed()}
 
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
6
  <title>VNEWS - Tin Tức Việt Nam</title>
7
+ <meta name="description" content="Tin tức tổng hợp, bóng đá trực tiếp, video highlight, rewrite AI.">
8
  <meta property="og:title" content="VNEWS - Tin Tức Việt Nam">
9
  <meta property="og:image" content="https://s1.vnecdn.net/vnexpress/restruct/i/v9505/logo_default.jpg">
10
  <link rel="canonical" href="https://bep40-vnews.hf.space">
11
  <script src="https://cdn.jsdelivr.net/npm/hls.js@1/dist/hls.min.js"></script>
12
  <style>
13
+ *{box-sizing:border-box;margin:0;padding:0}body{background:#111;color:#eee;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;overflow-x:hidden}.header{background:linear-gradient(135deg,#0d1117,#1a3a2a 50%,#8b7500);padding:12px;text-align:center}.header h1{font-size:18px}.header p{font-size:10px;color:#aaa}.cats{display:flex;overflow-x:auto;background:#1a1a1a;border-bottom:1px solid #333;padding:0 4px;position:sticky;top:0;z-index:50;scrollbar-width:none}.cat{padding:9px 11px;color:#888;font-size:11px;white-space:nowrap;border-bottom:2px solid transparent;cursor:pointer}.cat.active{color:#5cb87a;border-bottom-color:#5cb87a;font-weight:700}.view{display:none}.view.active{display:block}.loading{text-align:center;padding:30px;color:#777;font-size:12px}.slider-wrap,.ls-section{margin:6px 4px;background:#1a1a1a;border:1px solid #2a2a2a;border-radius:8px;overflow:hidden}.slider-header,.ls-header{padding:7px 10px;display:flex;align-items:center;justify-content:space-between}.slider-label,.ls-header h3{color:#f0c040;font-size:13px;font-weight:800}.slider-note{font-size:10px;color:#777}.slider-track{display:flex;overflow-x:auto;gap:8px;padding:4px 10px 10px;scrollbar-width:none}.slider-item{flex:0 0 160px;cursor:pointer}.shorts-item{flex:0 0 110px!important}.slider-thumb{position:relative;width:100%;aspect-ratio:16/9;border-radius:6px;overflow:hidden;background:#333}.shorts-thumb{aspect-ratio:3/4!important;border-radius:8px!important}.slider-thumb img,.card-img img{width:100%;height:100%;object-fit:cover}.slider-title{font-size:10px;color:#ccc;margin-top:3px;line-height:1.25;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.card-play{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:30px;height:30px;border-radius:50%;background:rgba(0,0,0,.55);display:flex;align-items:center;justify-content:center;color:#fff;font-size:12px}.grid{display:grid;grid-template-columns:repeat(2,1fr);gap:6px;padding:6px 4px}@media(min-width:650px){.grid{grid-template-columns:repeat(3,1fr)}}.card{background:#1a1a1a;border:1px solid #222;border-radius:8px;overflow:hidden;cursor:pointer}.card-img{position:relative;aspect-ratio:16/9;background:#333}.card-body{padding:6px 8px}.card-title{font-size:11px;line-height:1.35;color:#eee;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.badge{font-size:8px;padding:1px 5px;border-radius:3px;font-weight:700;display:inline-block;margin-bottom:2px;color:#fff}.badge-vne{background:#c0392b}.badge-bbc{background:#b80000}.badge-dt{background:#1565c0}.badge-genk{background:#6a1b9a}.badge-fpt{background:#f26522}.badge-ai{background:#2d8659}.badge-wc{background:#0b6bcb}.section-title{font-size:13px;font-weight:800;color:#5cb87a;margin:8px 0 4px;padding-left:8px;border-left:3px solid #5cb87a}.back-btn{background:#111;color:#fff;border:none;padding:10px;font-size:12px;width:100%;position:sticky;top:0;z-index:60}.article-view{padding:12px 8px 40px;max-width:760px;margin:0 auto}.article-title{font-size:18px;font-weight:800;line-height:1.3;margin-bottom:8px}.article-summary{background:#1a2a1f;border-left:3px solid #2d8659;padding:10px;margin-bottom:14px;color:#ccc;font-size:13px}.article-p{font-size:14px;line-height:1.7;color:#ccc;margin-bottom:10px}.article-img{width:100%;border-radius:6px;margin:10px 0}.article-h2{font-size:16px;margin:16px 0 8px}.article-actions{display:flex;gap:8px;flex-wrap:wrap;border-top:1px solid #333;margin-top:16px;padding-top:10px}.article-actions button,.article-actions select{background:#1a1a1a;border:1px solid #333;color:#ccc;padding:7px 12px;border-radius:14px;font-size:11px}.article-actions button.primary{background:#2d8659;border-color:#2d8659;color:#fff}.featured-match{margin:6px 4px;background:linear-gradient(135deg,#1a2a1f,#0d1117);border:1px solid #2d8659;border-radius:10px;padding:12px;cursor:pointer}.fm-league{text-align:center;color:#5cb87a;font-size:9px;font-weight:700;text-transform:uppercase}.fm-teams{display:flex;align-items:center;justify-content:center;gap:10px;margin-top:6px}.fm-team{flex:1;display:flex;flex-direction:column;align-items:center;gap:4px}.fm-team img{width:32px;height:32px;object-fit:contain}.fm-team span{font-size:10px;color:#ccc;text-align:center}.fm-score{font-size:22px;font-weight:900;min-width:60px;text-align:center}.fm-status{text-align:center;margin-top:6px;font-size:9px;color:#e74c3c;font-weight:700}.fm-status.upcoming{color:#f0c040}.ls-tabs{display:flex;gap:4px;padding:0 10px 8px;overflow-x:auto;scrollbar-width:none}.ls-tab{padding:4px 10px;background:#222;border:1px solid #333;border-radius:12px;color:#999;font-size:10px;white-space:nowrap;cursor:pointer}.ls-tab.active{background:#2d8659;border-color:#2d8659;color:#fff;font-weight:700}.ls-content{max-height:420px;overflow-y:auto;padding:0 6px 8px}.ls-content .matchs-league{list-style:none}.ls-content .title-content{display:flex;gap:6px;align-items:center;background:#222;border-radius:4px;margin:4px 0;padding:4px 6px}.ls-content .title-content img{width:16px;height:16px}.ls-content .title-content strong{font-size:11px}.ls-content .match-detail{padding:5px 6px;border-bottom:1px solid #222;cursor:pointer}.ls-content .match{display:flex;flex-wrap:wrap;align-items:center;gap:4px}.ls-content .datetime{width:100%;font-size:9px;color:#888}.ls-content .teams{display:flex;width:100%;align-items:center;gap:4px}.ls-content .team{flex:1;display:flex;align-items:center;gap:4px;text-decoration:none;min-width:0}.ls-content .team .name{font-size:11px;color:#ddd;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ls-content .team .logo img{width:18px;height:18px}.ls-content .home-team{justify-content:flex-end;text-align:right}.ls-content .status{flex:0 0 50px;text-align:center}.ls-content .status a{color:#fff;text-decoration:none;font-weight:800;font-size:12px}.ls-content .status .label{font-size:8px;color:#888;display:block}.ls-content .status .label.live{color:#e74c3c}.ls-content .info,.ls-content .btns{display:none}.match-overlay{position:fixed;inset:0;background:#111;z-index:9999;display:none;flex-direction:column;overflow:auto}.match-overlay.active{display:flex}.mo-header{padding:10px;background:#1a1a1a;display:flex;justify-content:space-between;align-items:center;position:sticky;top:0;z-index:1}.mo-header h3{font-size:13px}.mo-close{background:none;border:0;color:#fff;font-size:22px}.mo-tabs{display:flex;gap:4px;padding:8px 10px;background:#1a1a1a}.mo-tab{padding:5px 12px;background:#222;border:1px solid #333;border-radius:10px;color:#999;font-size:10px}.mo-tab.active{background:#2d8659;color:#fff}.mo-body{padding:8px;overflow-x:auto}.wall-item{flex:0 0 260px;background:#141414;border:1px solid #2b2b2b;border-radius:10px;padding:8px}.wall-thumb{width:100%;aspect-ratio:16/9;border-radius:8px;background:#222;overflow:hidden;margin-bottom:6px}.wall-thumb img{width:100%;height:100%;object-fit:cover}.wall-title{font-size:12px;color:#5cb87a;font-weight:800;line-height:1.3;margin-bottom:4px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.wall-tone{font-size:9px;color:#f0c040;margin-bottom:4px}.wall-text{font-size:11px;color:#bbb;line-height:1.4;white-space:pre-wrap;display:-webkit-box;-webkit-line-clamp:5;-webkit-box-orient:vertical;overflow:hidden}.wall-actions{display:flex;gap:6px;margin-top:8px}.wall-actions button{flex:1;border:1px solid #333;background:#222;color:#ddd;border-radius:14px;padding:6px 8px;font-size:10px}.wall-actions button.primary{background:#2d8659;border-color:#2d8659;color:#fff}.rewrite-box{margin-top:12px;background:#141414;border:1px solid #2b2b2b;border-radius:10px;padding:10px}.rewrite-title{font-size:12px;font-weight:800;color:#5cb87a;margin-bottom:6px}.rewrite-text{font-size:12px;line-height:1.55;color:#ccc;white-space:pre-wrap}.vp-wrap{background:#000;width:100%;aspect-ratio:1/1;position:relative}.vp-wrap.wide{aspect-ratio:16/9}.vp-wrap video,.vp-wrap iframe{width:100%;height:100%;object-fit:contain;border:none}.vp-ratio-btn{position:absolute;right:8px;top:8px;z-index:5;background:rgba(0,0,0,.6);border:1px solid #777;color:#fff;border-radius:12px;padding:3px 8px;font-size:9px}.vp-title{padding:8px 10px;background:#1a1a1a;font-size:13px;font-weight:700}.pl-list{padding:4px}.pl-item{display:flex;gap:8px;padding:8px 6px;border-bottom:1px solid #1a1a1a;border-radius:6px}.pl-item.active{background:#1a2a1f;border:1px solid #2d8659}.pl-item-thumb{flex:0 0 100px;aspect-ratio:16/9;border-radius:4px;overflow:hidden;background:#333;position:relative}.pl-item-thumb img{width:100%;height:100%;object-fit:cover}.pl-item-title{font-size:11px;color:#ccc;line-height:1.3}.tiktok-container{width:100%;height:80vh;max-height:680px;min-height:400px;background:#000}.tiktok-feed{height:100%;overflow-y:scroll;scroll-snap-type:y mandatory;scrollbar-width:none}.tiktok-slide{height:80vh;max-height:680px;min-height:400px;scroll-snap-align:start;position:relative;background:#000;display:flex;align-items:center;justify-content:center}.tiktok-slide video,.tiktok-slide iframe{width:100%;height:100%;object-fit:contain;border:none}.tiktok-bottom{position:absolute;bottom:0;left:0;right:60px;padding:12px 10px 16px;background:linear-gradient(transparent,rgba(0,0,0,.85))}.tiktok-title{font-size:12px;color:#fff}.tiktok-counter{position:absolute;top:8px;left:8px;background:rgba(0,0,0,.5);font-size:9px;padding:2px 7px;border-radius:8px}.tiktok-right{position:absolute;right:8px;bottom:100px}.tiktok-right-btn{background:none;border:0;color:#fff}.tiktok-right-btn .icon{width:42px;height:42px;border-radius:50%;background:rgba(255,255,255,.12);display:flex;align-items:center;justify-content:center;font-size:20px}
14
  </style>
15
  </head>
16
  <body>
17
+ <div class="header"><h1>📰 VNEWS</h1><p>Tin tức · Video · Bóng đá trực tiếp · Rewrite AI</p></div>
18
  <div class="cats" id="cat-bar"></div>
19
  <div id="view-home" class="view active"><div class="loading">Đang tải...</div></div>
20
  <div id="view-cat" class="view"></div><div id="view-video" class="view"></div><div id="view-tiktok" class="view"></div><div id="view-article" class="view"></div>
21
  <div class="match-overlay" id="match-overlay"><div class="mo-header"><h3 id="mo-title">Chi tiết trận đấu</h3><button class="mo-close" onclick="closeMatch()">✕</button></div><div class="mo-tabs"><span class="mo-tab active" onclick="loadMatchTab('comm')">Diễn biến</span><span class="mo-tab" onclick="loadMatchTab('stats')">Thống kê</span></div><div class="mo-body" id="mo-body"><div class="loading">Đang tải...</div></div></div>
22
  <script>
23
+ const SPACE=location.origin;let _cats=[],_tikData=[],_currentEventId='',_featuredEventId='',_hlLeagueData={},_vpHls=null,_serverWall=[],_currentArticle=null;
24
+ const HL_CONFIG={"premier-league":{name:"Premier League",emoji:"🏴"},"fa-cup":{name:"FA Cup",emoji:"🏆"},"champions-league":{name:"Champions League",emoji:"⭐"},"europa-league":{name:"Europa League",emoji:"🟠"},"la-liga":{name:"La Liga",emoji:"🇪🇸"},"serie-a":{name:"Serie A",emoji:"🇮🇹"},"bundesliga":{name:"Bundesliga",emoji:"🇩🇪"}};
25
+ function escapeHtml(s){return String(s||'').replace(/[&<>"']/g,m=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[m]));}
26
  function doShareVideo(title,url,img,type){const shareUrl=SPACE+'/v?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&img='+encodeURIComponent(img||'')+'&type='+encodeURIComponent(type||'highlights');if(navigator.share)navigator.share({title:'🎬 '+title,url:shareUrl}).catch(()=>{});else navigator.clipboard.writeText(shareUrl).then(()=>alert('Đã sao chép link!')).catch(()=>{})}
27
  function doShare(title,url,img){const shareUrl=SPACE+'/s?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&img='+encodeURIComponent(img||'');if(navigator.share)navigator.share({title,url:shareUrl}).catch(()=>{});else navigator.clipboard.writeText(shareUrl).then(()=>alert('Đã sao chép!')).catch(()=>{})}
28
+ function fetchJsonTimeout(url,ms=9000){const c=new AbortController();const t=setTimeout(()=>c.abort(),ms);return fetch(url,{signal:c.signal}).then(r=>r.json()).finally(()=>clearTimeout(t));}
29
  async function openMatch(id){if(!id)return;_currentEventId=id;document.getElementById('match-overlay').classList.add('active');document.body.style.overflow='hidden';loadMatchTab('comm')}
30
  function closeMatch(){document.getElementById('match-overlay').classList.remove('active');document.body.style.overflow=''}
31
  async function loadMatchTab(tab){document.querySelectorAll('.mo-tab').forEach(t=>t.classList.remove('active'));document.querySelectorAll('.mo-tab').forEach(t=>{if((tab==='comm'&&t.textContent==='Diễn biến')||(tab==='stats'&&t.textContent==='Thống kê'))t.classList.add('active')});const el=document.getElementById('mo-body');el.innerHTML='<div class="loading">Đang tải...</div>';try{const r=await fetch(tab==='stats'?`/api/match/${_currentEventId}/stats`:`/api/match/${_currentEventId}/commentaries`);const d=await r.json();el.innerHTML=d.html||'<div class="loading">Không có dữ liệu</div>'}catch(e){el.innerHTML='<div class="loading">Lỗi</div>'}}
 
35
  setInterval(()=>{if(_lsTab==='live')loadLivescore('live')},60000);
36
  async function refreshFeatured(){try{const r=await fetch('/api/livescore/featured');const f=await r.json();if(!f||!f.home)return;_featuredEventId=f.event_id;const el=document.querySelector('.featured-match');if(!el)return;const sc=f.status==='live'?'':'upcoming';const st=f.status==='live'?`🔴 ${f.minute||'LIVE'}`:`⏰ ${f.time}`;el.querySelector('.fm-league').textContent=f.league;el.querySelector('.fm-score').textContent=f.score||'VS';el.querySelector('.fm-status').className='fm-status '+sc;el.querySelector('.fm-status').textContent=st;el.setAttribute('onclick',`openMatch('${f.event_id}')`)}catch(e){}}
37
  setInterval(refreshFeatured,30000);
38
+ async function init(){_cats=await fetch('/api/categories').then(r=>r.json()).catch(()=>[]);let bar='<div class="cat active" data-cat="home">🏠</div><div class="cat" data-cat="video">🎬 Video</div>';_cats.forEach(c=>bar+=`<div class="cat" data-cat="${c.id}">${c.name}</div>`);document.getElementById('cat-bar').innerHTML=bar;document.querySelectorAll('.cat').forEach(t=>t.onclick=()=>switchCat(t.dataset.cat));await loadHome();const pending=localStorage.getItem('pending_article');if(pending){localStorage.removeItem('pending_article');readArticle(pending)}}
39
  function switchCat(id){document.querySelectorAll('.cat').forEach(x=>x.classList.remove('active'));document.querySelector(`[data-cat="${id}"]`)?.classList.add('active');document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.querySelectorAll('video').forEach(v=>{v.pause();if(v._hls){v._hls.destroy();v._hls=null}});if(_vpHls){_vpHls.destroy();_vpHls=null}document.querySelectorAll('iframe[data-yt-src]').forEach(f=>{f.src=''});if(id==='home'){document.getElementById('view-home').classList.add('active')}else if(id==='video'){document.getElementById('view-video').classList.add('active');loadVideos()}else{document.getElementById('view-cat').classList.add('active');loadCat(id)}}
40
  function showView(id){document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.getElementById(id).classList.add('active')}
41
+ async function loadHome(){const[news,sh,ai,wall,featured,hlLeagues,wc]=await Promise.all([fetchJsonTimeout('/api/homepage').catch(()=>[]),fetchJsonTimeout('/api/shorts').catch(()=>[]),fetchJsonTimeout('/api/genk_ai').catch(()=>[]),fetchJsonTimeout('/api/wall').catch(()=>({posts:[]})),fetchJsonTimeout('/api/livescore/featured').catch(()=>null),fetchJsonTimeout('/api/highlights/leagues').catch(()=>({})),fetchJsonTimeout('/api/worldcup2026').catch(()=>[])]);_hlLeagueData=hlLeagues;_serverWall=(wall&&wall.posts)||[];let h='';
42
+ if(featured&&featured.home){_featuredEventId=featured.event_id;const sc=featured.status==='live'?'':'upcoming';const st=featured.status==='live'?`🔴 ${featured.minute||'LIVE'}`:`⏰ ${featured.time}`;h+=`<div class="featured-match" onclick="openMatch('${featured.event_id}')"><div class="fm-league">${featured.league}</div><div class="fm-teams"><div class="fm-team"><img src="${featured.home_logo}" onerror="this.style.display='none'"><span>${featured.home}</span></div><div class="fm-score">${featured.score||'VS'}</div><div class="fm-team"><img src="${featured.away_logo}" onerror="this.style.display='none'"><span>${featured.away}</span></div></div><div class="fm-status ${sc}">${st}</div></div>`}
 
43
  h+=`<div class="ls-section"><div class="ls-header"><h3>⚽ Livescore</h3></div><div class="ls-tabs"><span class="ls-tab active" data-tab="live" onclick="loadLivescore('live')">🔴 Live</span><span class="ls-tab" data-tab="incoming" onclick="loadLivescore('incoming')">⏰ Sắp tới</span><span class="ls-tab" data-tab="results" onclick="loadLivescore('results')">✅ Kết quả</span><span class="ls-tab" data-tab="today" onclick="loadLivescore('today')">📅 Hôm nay</span><span class="ls-tab" data-tab="bxh_nha" onclick="loadLivescore('bxh_nha')">🏆 NHA</span><span class="ls-tab" data-tab="bxh_laliga" onclick="loadLivescore('bxh_laliga')">🏆 La Liga</span><span class="ls-tab" data-tab="bxh_seriea" onclick="loadLivescore('bxh_seriea')">🏆 Serie A</span><span class="ls-tab" data-tab="bxh_bundesliga" onclick="loadLivescore('bxh_bundesliga')">🏆 Bundesliga</span><span class="ls-tab" data-tab="bxh_ligue1" onclick="loadLivescore('bxh_ligue1')">🏆 Ligue 1</span></div><div class="ls-content" id="ls-content"><div class="loading" style="padding:20px">Đang tải...</div></div></div>`;
44
+ if(_serverWall.length)h+=renderWallSlide(_serverWall);
45
+ if(sh&&sh.length){h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">📱 Shorts</span></div><div class="slider-track">';sh.forEach((a,i)=>{h+=`<div class="slider-item shorts-item" onclick="openTikTok('shorts',${i})"><div class="slider-thumb shorts-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`});h+='</div></div>'}
46
  for(const[key,cfg] of Object.entries(HL_CONFIG)){const vids=hlLeagues[key];if(!vids||!vids.length)continue;h+=`<div class="slider-wrap"><div class="slider-header"><span class="slider-label">${cfg.emoji} ${cfg.name}</span></div><div class="slider-track">`;vids.slice(0,8).forEach((a,i)=>{h+=`<div class="slider-item" onclick="openLeaguePlayer('${key}',${i})"><div class="slider-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`});h+='</div></div>'}
47
+ if(wc&&wc.length){h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">🌍 Đường đến World Cup 2026</span><span class="slider-note">Thethaovanhoa.vn</span></div><div class="slider-track">';wc.slice(0,18).forEach(a=>{h+=`<div class="slider-item" onclick="readArticle('${a.link.replace(/'/g,"\\'")}','ttvh')"><div class="slider-thumb">${a.img?`<img src="${a.img}">`:''}</div><div class="slider-title">${a.title}</div></div>`});h+='</div></div>'}
48
+ if(ai&&ai.length){h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">🤖 Ứng dụng AI</span></div><div class="slider-track">';ai.forEach(a=>{h+=`<div class="slider-item" onclick="readArticle('${a.link.replace(/'/g,"\\'")}','genk')"><div class="slider-thumb">${a.img?`<img src="${a.img}">`:''}</div><div class="slider-title">${a.title}</div></div>`});h+='</div></div>'}
49
+ const groups={};news.forEach(a=>{if(!groups[a.group])groups[a.group]=[];groups[a.group].push(a)});for(const[g,arts] of Object.entries(groups)){h+=`<div class="section-title">${g}</div><div class="grid">`;arts.slice(0,6).forEach(a=>{const bg=a.source==='bbc'?'badge-bbc':a.source==='dantri'?'badge-dt':a.source==='genk'?'badge-genk':'badge-vne';const lb=a.source==='bbc'?'BBC':a.source==='dantri'?'DT':a.source==='genk'?'GenK':'VnE';h+=`<div class="card" onclick="readArticle('${a.link.replace(/'/g,"\\'")}','${a.source}')"><div class="card-img">${a.img?`<img src="${a.img}">`:''}</div><div class="card-body"><span class="badge ${bg}">${lb}</span><div class="card-title">${a.title}</div></div></div>`});h+='</div>'}
50
+ document.getElementById('view-home').innerHTML=h;loadLivescore('live')}
51
+ function renderWallSlide(posts){let h='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">🧱 Tường AI</span><span class="slider-note">Rewrite AI</span></div><div class="slider-track">';posts.slice(0,30).forEach(p=>{h+=`<div class="wall-item"><div class="wall-thumb">${p.img?`<img src="${p.img}">`:''}</div><div class="wall-title">${escapeHtml(p.title)}</div><div class="wall-tone">Rewrite AI</div><div class="wall-text">${escapeHtml(p.text)}</div><div class="wall-actions"><button class="primary" onclick="readWallPost('${p.id}')">Xem</button>${p.url?`<button onclick="readArticle('${p.url.replace(/'/g,"\\'")}')">Gốc</button>`:''}</div></div>`});h+='</div></div>';return h}
52
+ function readWallPost(id){let p=_serverWall.find(x=>x.id===id);if(!p)return;showView('view-article');let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view"><span class="badge badge-ai">AI Rewrite</span><h1 class="article-title">${escapeHtml(p.title)}</h1>${p.img?`<img class="article-img" src="${p.img}">`:''}<div class="article-summary">Bài viết AI tóm tắt và viết lại</div><p class="article-p" style="white-space:pre-wrap">${escapeHtml(p.text)}</p><div class="article-actions"><button onclick="doShare('${escapeHtml(p.title)}','${p.url||location.href}','${p.img||''}')">📤 Chia sẻ</button>${p.url?`<button onclick="readArticle('${p.url.replace(/'/g,"\\'")}')">Đọc bài gốc</button>`:''}</div></div>`;document.getElementById('view-article').innerHTML=h;window.scrollTo(0,0)}
53
  async function loadCat(id){const el=document.getElementById('view-cat');el.innerHTML='<div class="loading">Đang tải...</div>';const arts=await fetch('/api/category/'+id).then(r=>r.json()).catch(()=>[]);if(!arts.length){el.innerHTML='<div class="loading">Không có tin</div>';return}let h='<div class="grid">';arts.forEach(a=>{const bg=a.source==='bbc'?'badge-bbc':a.source==='dantri'?'badge-dt':a.source==='genk'?'badge-genk':'badge-vne';h+=`<div class="card" onclick="readArticle('${a.link.replace(/'/g,"\\'")}','${a.source}')"><div class="card-img">${a.img?`<img src="${a.img}">`:''}</div><div class="card-body"><span class="badge ${bg}">${a.source}</span><div class="card-title">${a.title}</div></div></div>`});h+='</div>';el.innerHTML=h}
54
+ async function readArticle(url,source){const supported=url.includes('vnexpress.net')||url.includes('bbc.com')||url.includes('dantri.com.vn')||url.includes('genk.vn')||url.includes('thethaovanhoa.vn');if(!supported){window.open(url,'_blank');return}showView('view-article');const el=document.getElementById('view-article');el.innerHTML='<div class="loading">Đang tải...</div>';const data=await fetch('/api/article?url='+encodeURIComponent(url)).then(r=>r.json()).catch(()=>null);if(!data||data.error||!data.body||!data.body.length){el.innerHTML=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="loading"><a href="${url}" target="_blank" style="color:#5cb87a">Mở link gốc</a></div>`;return}_currentArticle={url,data};let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view"><h1 class="article-title">${data.title}</h1>`;if(data.summary)h+=`<div class="article-summary">${data.summary}</div>`;let lastImg='';data.body.forEach(b=>{if(b.type==='p')h+=`<p class="article-p">${b.text}</p>`;else if(b.type==='img'&&b.src&&b.src!==lastImg){lastImg=b.src;h+=`<img class="article-img" src="${b.src}">`}else if(b.type==='heading')h+=`<h2 class="article-h2">${b.text}</h2>`});h+=`<div class="article-actions"><select id="rewrite-tone"><option value="vui-ve">Vui vẻ</option><option value="nghiem-tuc">Nghiêm túc</option><option value="nghi-luan">Nghị luận</option><option value="hoi-dap">Hỏi đáp</option><option value="soi-noi">Sôi nổi</option><option value="thu-hut">Thu hút</option><option value="phan-tich">Phân tích</option><option value="chuyen-gia">Chuyên gia</option></select><button class="primary" onclick="rewriteCurrentArticle()">🤖 Rewrite AI</button><button onclick="doShare('${(data.title||'').replace(/'/g,"\\'")}','${url.replace(/'/g,"\\'")}','${(data.og_image||'').replace(/'/g,"\\'")}')">📤 Chia sẻ</button><button onclick="window.open('${url}','_blank')">🔗 Gốc</button></div><div id="rewrite-result"></div></div>`;el.innerHTML=h;window.scrollTo(0,0)}
55
+ function rewriteCurrentArticle(){if(!_currentArticle)return;let tone=document.getElementById('rewrite-tone')?.value||'nghiem-tuc';let btn=document.querySelector('.article-actions button.primary');if(btn){btn.textContent='Đang rewrite...';btn.disabled=true}fetch('/api/rewrite_share',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url:_currentArticle.url,tone})}).then(r=>r.json()).then(j=>{if(j&&j.post){document.getElementById('rewrite-result').innerHTML=`<div class="rewrite-box"><div class="rewrite-title">Đã rewrite và đăng lên Tường AI</div><div class="rewrite-text">${escapeHtml(j.post.text||'')}</div></div>`;alert('Đã đăng lên Tường AI');}else alert(j.error||'Không tạo được bài AI')}).catch(()=>alert('Lỗi tạo bài AI')).finally(()=>{if(btn){btn.textContent='🤖 Rewrite AI';btn.disabled=false}})}
56
  async function loadVideos(){const el=document.getElementById('view-video');if(el.dataset.loaded)return;el.innerHTML='<div class="loading">Đang tải...</div>';const[hl,bdp]=await Promise.all([fetch('/api/highlights').then(r=>r.json()).catch(()=>[]),fetch('/api/bdp_videos').then(r=>r.json()).catch(()=>[])]);let h='<div class="section-title">🎬 Highlight</div><div class="grid">';hl.forEach((a,i)=>{h+=`<div class="card" onclick="openTikTok('highlights',${i})"><div class="card-img">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge badge-fpt">HL</span><div class="card-title">${a.title}</div></div></div>`});h+='</div>';if(bdp.length){h+='<div class="section-title">⚽ BDP</div><div class="grid">';bdp.forEach((a,i)=>{h+=`<div class="card" onclick="openTikTok('bdp',${i})"><div class="card-img">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge badge-bdp">BDP</span><div class="card-title">${a.title}</div></div></div>`});h+='</div>'}el.innerHTML=h;el.dataset.loaded='1'}
57
  async function openTikTok(type,startIdx){showView('view-tiktok');document.querySelectorAll('.cat').forEach(x=>x.classList.remove('active'));const el=document.getElementById('view-tiktok');el.innerHTML='<div class="loading">Đang tải video...</div>';let articles;if(type==='shorts')articles=await fetch('/api/shorts').then(r=>r.json()).catch(()=>[]);else if(type==='highlights')articles=await fetch('/api/highlights').then(r=>r.json()).catch(()=>[]);else articles=await fetch('/api/bdp_videos').then(r=>r.json()).catch(()=>[]);await buildTikTokPlayer(articles,startIdx,type)}
58
  async function buildTikTokPlayer(articles,startIdx,type){const el=document.getElementById('view-tiktok');const vids=[];const results=await Promise.all(articles.map(async(a,i)=>{try{const r=await fetch('/api/video_url?url='+encodeURIComponent(a.link));const v=await r.json();if(v&&v.src)return{article:a,video:v,idx:i}}catch(e){}return null}));results.forEach(r=>{if(!r)return;const{article:a,video:v,idx:i}=r;vids.push({...a,...v,_idx:i})});vids.sort((a,b)=>a._idx-b._idx);if(!vids.length){el.innerHTML='<div class="loading">Không tìm thấy video</div>';return}let ti=vids.findIndex(v=>v._idx===startIdx);if(ti<0)ti=0;const ordered=ti>0?[...vids.slice(ti),...vids.slice(0,ti)]:vids;_tikData=ordered;let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="tiktok-container"><div class="tiktok-feed" id="tiktok-feed">`;ordered.forEach((v,i)=>{const isYT=v.type==='youtube';const isHLS=!isYT&&v.src&&v.src.includes('.m3u8');const poster=v.poster?` poster="${v.poster}"`:'';const vtag=isYT?`<iframe data-yt-src="${v.src}" allowfullscreen allow="accelerometer;autoplay;clipboard-write;encrypted-media;gyroscope;picture-in-picture"></iframe>`:isHLS?`<video playsinline preload="none"${poster} data-hls="${v.src}" loop controls></video>`:`<video playsinline preload="none"${poster} loop controls><source src="${v.src}" type="video/mp4"></video>`;h+=`<div class="tiktok-slide" id="tslide-${i}">${vtag}<div class="tiktok-bottom"><span class="badge badge-fpt">VIDEO</span><p class="tiktok-title">${v.title}</p></div><div class="tiktok-right"><button class="tiktok-right-btn" onclick="event.stopPropagation();shareVid(${i})"><div class="icon">📤</div></button></div><span class="tiktok-counter">${i+1}/${ordered.length}</span></div>`});h+='</div></div>';el.innerHTML=h;initFeed()}