Spaces:
Running
Running
Fetch VTV Nam Bộ shorts from dedicated endpoint in loadHome
Browse files- static/app_v2.js +20 -109
static/app_v2.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
// === VNEWS Frontend v2 - Optimized for speed ===
|
| 2 |
|
| 3 |
-
// === LOAD HOME - Fast: immediate shell + parallel fetch ===
|
| 4 |
function _fetchWithTimeout(url, ms){
|
| 5 |
return new Promise((resolve,reject)=>{
|
| 6 |
const ctrl=new AbortController();
|
|
@@ -17,7 +16,6 @@ async function loadHome(){
|
|
| 17 |
const homeEl = document.getElementById('view-home');
|
| 18 |
if(!homeEl) return;
|
| 19 |
|
| 20 |
-
// Build shell IMMEDIATELY — no skeleton, no delay
|
| 21 |
homeEl.innerHTML =
|
| 22 |
'<div id="home-featured-area"></div>'
|
| 23 |
+'<div class="ai-compose"><div class="ai-compose-title">🤖 AI viết bài</div><div class="ai-compose-row"><input id="topic-input" placeholder="Nhập chủ đề..."><button onclick="searchTopic()">Tìm nguồn</button></div><div class="ai-compose-row"><input id="url-input" placeholder="Dán URL bài viết..."><button class="secondary" onclick="rewriteUrl()">Rewrite</button></div><div id="hot-topics" class="hot-topic-row"></div></div>'
|
|
@@ -28,11 +26,9 @@ async function loadHome(){
|
|
| 28 |
|
| 29 |
const afterEl = homeEl.querySelector('#home-after-wc');
|
| 30 |
|
| 31 |
-
// Start critical loads immediately
|
| 32 |
loadLivescore('today');
|
| 33 |
loadHotTopics();
|
| 34 |
|
| 35 |
-
// Fetch all data in parallel with shorter timeouts
|
| 36 |
const [featuredData, shortsData, wallData, hlLeagues, aiData, wcData, vtvShortsData] = await Promise.allSettled([
|
| 37 |
_fetchWithTimeout('/api/livescore/featured', 5000),
|
| 38 |
_fetchWithTimeout('/api/shorts', 8000),
|
|
@@ -40,10 +36,9 @@ async function loadHome(){
|
|
| 40 |
_fetchWithTimeout('/api/highlights/leagues', 10000),
|
| 41 |
_fetchWithTimeout('/api/genk_ai', 8000),
|
| 42 |
_fetchWithTimeout('/api/wc2026', 8000),
|
| 43 |
-
_fetchWithTimeout('/api/shorts/vtvnamo?count=
|
| 44 |
]).then(results => results.map(r => r.status === 'fulfilled' ? r.value : null));
|
| 45 |
|
| 46 |
-
// Render featured match
|
| 47 |
if(featuredData && featuredData.home){
|
| 48 |
const sc=featuredData.status==='live'?'':'upcoming';
|
| 49 |
const st=featuredData.status==='live'?`🔴 ${featuredData.minute||'LIVE'}`:`⏰ ${featuredData.time}`;
|
|
@@ -51,17 +46,14 @@ async function loadHome(){
|
|
| 51 |
if(area) area.innerHTML=`<div class="featured-match" onclick="openMatch('${featuredData.event_id}')"><div class="fm-league">${featuredData.league}</div><div class="fm-teams"><div class="fm-team"><img src="${featuredData.home_logo}" onerror="this.style.display='none'"><span>${featuredData.home}</span></div><div class="fm-score">${featuredData.score||'VS'}</div><div class="fm-team"><img src="${featuredData.away_logo}" onerror="this.style.display='none'"><span>${featuredData.away}</span></div></div><div class="fm-status ${sc}">${st}</div></div>`;
|
| 52 |
}
|
| 53 |
|
| 54 |
-
// Store globally
|
| 55 |
_shortsData = shortsData || [];
|
| 56 |
_wallPosts = (wallData && wallData.posts) || [];
|
| 57 |
_hlLeagueData = hlLeagues || {};
|
| 58 |
_wc2026Data = wcData;
|
| 59 |
_wcShortsData = vtvShortsData || [];
|
| 60 |
|
| 61 |
-
// Render WC if data arrived
|
| 62 |
if(wcData) switchWCTab('news');
|
| 63 |
|
| 64 |
-
// Render sections into the after-wc area
|
| 65 |
_renderShortsIn(afterEl);
|
| 66 |
_renderWallIn(afterEl);
|
| 67 |
_renderHLIn(afterEl);
|
|
@@ -134,16 +126,11 @@ function _renderHLIn(afterEl){
|
|
| 134 |
}
|
| 135 |
}
|
| 136 |
|
| 137 |
-
// === WALL POST HELPERS ===
|
| 138 |
function makeWallItem(p,i){
|
| 139 |
const hasVideo = p.video && p.video.length > 0;
|
| 140 |
-
const thumbContent = p.img
|
| 141 |
-
? `<img src="${esc(p.img)}" loading="lazy" onerror="this.style.display='none'">`
|
| 142 |
-
: (hasVideo ? `<video src="${esc(p.video)}" muted></video>` : '');
|
| 143 |
const videoBadge = hasVideo ? `<div class="wall-video-badge">🎬</div>` : '';
|
| 144 |
-
const videoBtn = hasVideo
|
| 145 |
-
? `<button class="wall-btn-video" onclick="event.stopPropagation();openShortAIFeed(${i})">▶ Xem Short</button>`
|
| 146 |
-
: `<button class="wall-btn-make" onclick="event.stopPropagation();makeShortVideo('${esc(p.id||i)}',this)">🎬 Tạo Video</button>`;
|
| 147 |
return `<div class="wall-item" id="wall-item-${esc(p.id||i)}"><div class="wall-thumb">${thumbContent}${videoBadge}</div><div class="wall-title">${esc(p.title)}</div><div class="wall-text">${esc((p.text||'').slice(0,180))}</div><div class="wall-actions"><button class="primary" onclick="readWallPost(${i})">Xem</button>${videoBtn}</div></div>`;
|
| 148 |
}
|
| 149 |
|
|
@@ -184,17 +171,12 @@ async function makeShortVideo(postId, btn, voice, speed){
|
|
| 184 |
function refreshShortAISlider(){
|
| 185 |
const aiShorts = _wallPosts.filter(p=>p.video);
|
| 186 |
let shortAISection = document.getElementById('short-ai-section');
|
| 187 |
-
if(aiShorts.length === 0){
|
| 188 |
-
if(shortAISection) shortAISection.remove();
|
| 189 |
-
return;
|
| 190 |
-
}
|
| 191 |
if(shortAISection){
|
| 192 |
const track = shortAISection.querySelector('.slider-track');
|
| 193 |
if(track){
|
| 194 |
let h = '';
|
| 195 |
-
aiShorts.slice(0,20).forEach((p,i)=>{
|
| 196 |
-
h+=`<div class="slider-item shorts-item" onclick="openShortAIFeed(${i})"><div class="slider-thumb shorts-thumb"><video src="${esc(p.video)}" muted preload="metadata"></video><div class="card-play">▶</div></div><div class="slider-title">${esc(p.title)}</div></div>`;
|
| 197 |
-
});
|
| 198 |
track.innerHTML = h;
|
| 199 |
}
|
| 200 |
}
|
|
@@ -223,20 +205,15 @@ function prependWallPost(post){
|
|
| 223 |
div.className='wall-item wall-item-new';
|
| 224 |
div.id='wall-item-'+(post.id||'new-'+Date.now());
|
| 225 |
const hasVideo = post.video && post.video.length > 0;
|
| 226 |
-
const thumbContent = post.img
|
| 227 |
-
? `<img src="${esc(post.img)}" loading="lazy" onerror="this.style.display='none'">`
|
| 228 |
-
: (hasVideo ? `<video src="${esc(post.video)}" muted></video>` : '');
|
| 229 |
const videoBadge = hasVideo ? `<div class="wall-video-badge">🎬</div>` : '';
|
| 230 |
-
const videoBtn = hasVideo
|
| 231 |
-
? `<button class="wall-btn-video" onclick="event.stopPropagation();openShortAIFeed(0)">▶ Xem Short</button>`
|
| 232 |
-
: `<button class="wall-btn-make" onclick="event.stopPropagation();makeShortVideo('${esc(post.id)}',this)">🎬 Tạo Video</button>`;
|
| 233 |
div.innerHTML=`<div class="wall-thumb">${thumbContent}${videoBadge}</div><div class="wall-title">${esc(post.title)}</div><div class="wall-text">${esc((post.text||'').slice(0,180))}</div><div class="wall-actions"><button class="primary" onclick="readWallPost(0)">Xem</button>${videoBtn}</div>`;
|
| 234 |
track.prepend(div);
|
| 235 |
track.scrollTo({left:0,behavior:'smooth'});
|
| 236 |
if(hasVideo) refreshShortAISlider();
|
| 237 |
}
|
| 238 |
|
| 239 |
-
// === REST OF FUNCTIONS ===
|
| 240 |
let _shortsData=[];
|
| 241 |
let _wallPosts=[];
|
| 242 |
let _wcShortsData=[];
|
|
@@ -272,8 +249,7 @@ function bindMatchClicks(el){
|
|
| 272 |
const teamA=this.querySelector('.teams a[href*="/tran-dau/"]');
|
| 273 |
const a = statusA || teamA;
|
| 274 |
if(a){
|
| 275 |
-
e.preventDefault();
|
| 276 |
-
e.stopPropagation();
|
| 277 |
const href=a.getAttribute('href')||'';
|
| 278 |
const m=href.match(/\/tran-dau\/(\d+)\//);
|
| 279 |
if(m){
|
|
@@ -283,9 +259,7 @@ function bindMatchClicks(el){
|
|
| 283 |
}
|
| 284 |
});
|
| 285 |
});
|
| 286 |
-
el.querySelectorAll('a').forEach(a=>{
|
| 287 |
-
a.addEventListener('click',e=>{e.preventDefault();e.stopPropagation()});
|
| 288 |
-
});
|
| 289 |
}
|
| 290 |
function openMatch(id,url){if(!id)return;_currentEventId=id;if(url)_currentMatchUrl=url;document.getElementById('match-overlay').classList.add('active');document.body.style.overflow='hidden';loadMatchTab('detail')}
|
| 291 |
function closeMatch(){document.getElementById('match-overlay').classList.remove('active');document.body.style.overflow=''}
|
|
@@ -308,23 +282,9 @@ async function openYTShortsFeed(startIdx){
|
|
| 308 |
showView('view-tiktok');
|
| 309 |
const el=document.getElementById('view-tiktok');
|
| 310 |
el.innerHTML='<div class="loading">Đang tải shorts...</div>';
|
| 311 |
-
|
| 312 |
-
// Try to get shorts from multiple sources
|
| 313 |
let arts = _shortsData.length ? _shortsData : [];
|
| 314 |
-
|
| 315 |
-
if(!arts.length){
|
| 316 |
-
try{
|
| 317 |
-
arts = await fetch('/api/shorts').then(r=>r.json()).catch(()=>[]);
|
| 318 |
-
}catch(e){
|
| 319 |
-
arts = [];
|
| 320 |
-
}
|
| 321 |
-
}
|
| 322 |
-
|
| 323 |
-
if(!arts.length){
|
| 324 |
-
el.innerHTML='<div class="loading">Không có shorts</div>';
|
| 325 |
-
return;
|
| 326 |
-
}
|
| 327 |
-
|
| 328 |
const ordered=startIdx>0?[...arts.slice(startIdx),...arts.slice(0,startIdx)]:arts;
|
| 329 |
let h=`<button class="back-btn" onclick="switchCat('home')">← Shorts</button><div class="tiktok-container"><div class="tiktok-feed" id="tiktok-feed">`;
|
| 330 |
ordered.forEach((v,i)=>{
|
|
@@ -353,29 +313,20 @@ async function readWallPost(i){const p=_wallPosts[i];if(!p)return;showView('view
|
|
| 353 |
if(images.length > 0){
|
| 354 |
imgGallery = '<div class="article-image-gallery">';
|
| 355 |
images.forEach((imgUrl, imgIdx) => {
|
| 356 |
-
if(imgIdx === 0){
|
| 357 |
-
|
| 358 |
-
} else {
|
| 359 |
-
if(imgIdx === 1) imgGallery += '<div class="gallery-thumbs">';
|
| 360 |
-
imgGallery += `<div class="gallery-thumb"><img src="${esc(imgUrl)}" onerror="this.parentElement.style.display='none'" loading="lazy"></div>`;
|
| 361 |
-
}
|
| 362 |
});
|
| 363 |
if(images.length > 1) imgGallery += '</div>';
|
| 364 |
imgGallery += '</div>';
|
| 365 |
}
|
| 366 |
const hasVideo = p.video && p.video.length > 0;
|
| 367 |
-
const voiceOptions = [
|
| 368 |
-
{id:'hoaimy', label:'🎙️ Nữ — Hoài My'},
|
| 369 |
-
{id:'namminh', label:'🎙️ Nam — Nam Minh'},
|
| 370 |
-
];
|
| 371 |
let voiceSelector = '';
|
| 372 |
if(!hasVideo){
|
| 373 |
voiceSelector = `<div class="tts-selector"><div class="tts-selector-label">🎙️ Chọn giọng đọc:</div><div class="tts-voice-btns">`;
|
| 374 |
-
voiceOptions.forEach(v=>{
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
voiceSelector += `</div><div class="tts-speed-row"><span>Tốc độ:</span><select id="selected-speed"><option value="1.0">1.0x — Bình thường</option><option value="1.2" selected>1.2x — Nhanh</option><option value="1.5">1.5x — Rất nhanh</option><option value="0.8">0.8x — Chậm</option></select></div>`;
|
| 378 |
-
voiceSelector += `<input type="hidden" id="selected-voice" value="hoaimy"></div>`;
|
| 379 |
}
|
| 380 |
document.getElementById('view-article').innerHTML=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view"><span class="badge badge-ai">AI</span><h1 class="article-title">${esc(p.title)}</h1>${imgGallery}<p class="article-p" style="white-space:pre-wrap">${esc(p.text)}</p>${hasVideo?`<video class="article-img" src="${esc(p.video)}" controls playsinline style="max-height:400px"></video>`:''}<div class="article-actions">${hasVideo?`<button onclick="openShortAIFeed(${i})">🎬 Xem Short</button>${voiceSelector}<button class="primary" onclick="makeShortVideo('${esc(p.id)}',this,document.getElementById('selected-voice')?.value,parseFloat(document.getElementById('selected-speed')?.value)||1.2)">🔄 Tạo lại Short</button>`:`${voiceSelector}<button class="primary" onclick="makeShortVideo('${esc(p.id)}',this,document.getElementById('selected-voice')?.value,parseFloat(document.getElementById('selected-speed')?.value)||1.2)">🎬 Tạo Video Shorts</button>`}<button onclick="doShare('${esc(p.title)}','${SPACE}','${esc(p.img||'')}')">📤</button></div></div>`;
|
| 381 |
const firstVoiceBtn = document.querySelector('.tts-voice-btn');
|
|
@@ -384,46 +335,6 @@ async function readWallPost(i){const p=_wallPosts[i];if(!p)return;showView('view
|
|
| 384 |
async function loadNewsTab(){const el=document.getElementById('view-cat');el.innerHTML='<div class="loading">Đang tải...</div>';try{const r=await fetch('/api/homepage');const news=await r.json();if(!news.length){el.innerHTML='<div class="loading">Không có tin</div>';return}const groups={};news.forEach(a=>{if(!groups[a.group])groups[a.group]=[];groups[a.group].push(a)});let h='';for(const[g,arts]of Object.entries(groups)){h+=`<div class="section-title">${g}</div><div class="grid">`;arts.slice(0,6).forEach(a=>{h+=`<div class="card" onclick="readArticle('${esc(a.link)}')"><div class="card-img">${a.img?`<img src="${a.img}" loading="lazy">`:''}</div><div class="card-body"><span class="badge badge-vne">${esc(a.source||'VnE')}</span><div class="card-title">${esc(a.title)}</div></div></div>`});h+='</div>'}el.innerHTML=h}catch(e){el.innerHTML='<div class="loading">Lỗi</div>'}}
|
| 385 |
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=>{h+=`<div class="card" onclick="readArticle('${esc(a.link)}')"><div class="card-img">${a.img?`<img src="${a.img}" loading="lazy">`:''}</div><div class="card-body"><span class="badge badge-vne">${esc(a.source||'')}</span><div class="card-title">${esc(a.title)}</div></div></div>`});h+='</div>';el.innerHTML=h}
|
| 386 |
fetch('/api/storage_status').then(r=>r.json()).then(j=>{if(!j.persistent){const home=document.getElementById('view-home');if(home){const w=document.createElement('div');w.className='storage-warn';w.innerHTML='⚠️ Persistent Storage chưa bật.';home.prepend(w)}}}).catch(()=>{});
|
| 387 |
-
|
| 388 |
-
(function(){
|
| 389 |
-
|
| 390 |
-
var hash = window.location.hash;
|
| 391 |
-
if(hash && hash.length > 1){
|
| 392 |
-
var articleUrl = decodeURIComponent(hash.substring(1));
|
| 393 |
-
if(articleUrl.startsWith('http')){
|
| 394 |
-
history.replaceState(null, '', window.location.pathname);
|
| 395 |
-
setTimeout(function(){
|
| 396 |
-
if(typeof readArticle==='function') readArticle(articleUrl);
|
| 397 |
-
}, 1500);
|
| 398 |
-
}
|
| 399 |
-
}
|
| 400 |
-
}catch(e){}
|
| 401 |
-
})();
|
| 402 |
-
|
| 403 |
-
(function(){
|
| 404 |
-
try{
|
| 405 |
-
const pa=localStorage.getItem('pending_article');
|
| 406 |
-
const pv=localStorage.getItem('pending_video');
|
| 407 |
-
if(pa){
|
| 408 |
-
localStorage.removeItem('pending_article');
|
| 409 |
-
setTimeout(()=>{
|
| 410 |
-
if(typeof readArticle==='function') readArticle(pa);
|
| 411 |
-
},1500);
|
| 412 |
-
}
|
| 413 |
-
if(pv){
|
| 414 |
-
localStorage.removeItem('pending_video');
|
| 415 |
-
try{
|
| 416 |
-
const v=JSON.parse(pv);
|
| 417 |
-
if(v&&v.url) setTimeout(()=>{window.open(v.url,'_blank')},1500);
|
| 418 |
-
}catch(e){}
|
| 419 |
-
}
|
| 420 |
-
}catch(e){}
|
| 421 |
-
})();
|
| 422 |
-
|
| 423 |
-
if (document.readyState === 'loading') {
|
| 424 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 425 |
-
if (typeof loadHome === 'function') loadHome();
|
| 426 |
-
});
|
| 427 |
-
} else {
|
| 428 |
-
if (typeof loadHome === 'function') loadHome();
|
| 429 |
-
}
|
|
|
|
| 1 |
// === VNEWS Frontend v2 - Optimized for speed ===
|
| 2 |
|
|
|
|
| 3 |
function _fetchWithTimeout(url, ms){
|
| 4 |
return new Promise((resolve,reject)=>{
|
| 5 |
const ctrl=new AbortController();
|
|
|
|
| 16 |
const homeEl = document.getElementById('view-home');
|
| 17 |
if(!homeEl) return;
|
| 18 |
|
|
|
|
| 19 |
homeEl.innerHTML =
|
| 20 |
'<div id="home-featured-area"></div>'
|
| 21 |
+'<div class="ai-compose"><div class="ai-compose-title">🤖 AI viết bài</div><div class="ai-compose-row"><input id="topic-input" placeholder="Nhập chủ đề..."><button onclick="searchTopic()">Tìm nguồn</button></div><div class="ai-compose-row"><input id="url-input" placeholder="Dán URL bài viết..."><button class="secondary" onclick="rewriteUrl()">Rewrite</button></div><div id="hot-topics" class="hot-topic-row"></div></div>'
|
|
|
|
| 26 |
|
| 27 |
const afterEl = homeEl.querySelector('#home-after-wc');
|
| 28 |
|
|
|
|
| 29 |
loadLivescore('today');
|
| 30 |
loadHotTopics();
|
| 31 |
|
|
|
|
| 32 |
const [featuredData, shortsData, wallData, hlLeagues, aiData, wcData, vtvShortsData] = await Promise.allSettled([
|
| 33 |
_fetchWithTimeout('/api/livescore/featured', 5000),
|
| 34 |
_fetchWithTimeout('/api/shorts', 8000),
|
|
|
|
| 36 |
_fetchWithTimeout('/api/highlights/leagues', 10000),
|
| 37 |
_fetchWithTimeout('/api/genk_ai', 8000),
|
| 38 |
_fetchWithTimeout('/api/wc2026', 8000),
|
| 39 |
+
_fetchWithTimeout('/api/shorts/vtvnamo?count=50', 12000),
|
| 40 |
]).then(results => results.map(r => r.status === 'fulfilled' ? r.value : null));
|
| 41 |
|
|
|
|
| 42 |
if(featuredData && featuredData.home){
|
| 43 |
const sc=featuredData.status==='live'?'':'upcoming';
|
| 44 |
const st=featuredData.status==='live'?`🔴 ${featuredData.minute||'LIVE'}`:`⏰ ${featuredData.time}`;
|
|
|
|
| 46 |
if(area) area.innerHTML=`<div class="featured-match" onclick="openMatch('${featuredData.event_id}')"><div class="fm-league">${featuredData.league}</div><div class="fm-teams"><div class="fm-team"><img src="${featuredData.home_logo}" onerror="this.style.display='none'"><span>${featuredData.home}</span></div><div class="fm-score">${featuredData.score||'VS'}</div><div class="fm-team"><img src="${featuredData.away_logo}" onerror="this.style.display='none'"><span>${featuredData.away}</span></div></div><div class="fm-status ${sc}">${st}</div></div>`;
|
| 47 |
}
|
| 48 |
|
|
|
|
| 49 |
_shortsData = shortsData || [];
|
| 50 |
_wallPosts = (wallData && wallData.posts) || [];
|
| 51 |
_hlLeagueData = hlLeagues || {};
|
| 52 |
_wc2026Data = wcData;
|
| 53 |
_wcShortsData = vtvShortsData || [];
|
| 54 |
|
|
|
|
| 55 |
if(wcData) switchWCTab('news');
|
| 56 |
|
|
|
|
| 57 |
_renderShortsIn(afterEl);
|
| 58 |
_renderWallIn(afterEl);
|
| 59 |
_renderHLIn(afterEl);
|
|
|
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
|
|
|
| 129 |
function makeWallItem(p,i){
|
| 130 |
const hasVideo = p.video && p.video.length > 0;
|
| 131 |
+
const thumbContent = p.img ? `<img src="${esc(p.img)}" loading="lazy" onerror="this.style.display='none'">` : (hasVideo ? `<video src="${esc(p.video)}" muted></video>` : '');
|
|
|
|
|
|
|
| 132 |
const videoBadge = hasVideo ? `<div class="wall-video-badge">🎬</div>` : '';
|
| 133 |
+
const videoBtn = hasVideo ? `<button class="wall-btn-video" onclick="event.stopPropagation();openShortAIFeed(${i})">▶ Xem Short</button>` : `<button class="wall-btn-make" onclick="event.stopPropagation();makeShortVideo('${esc(p.id||i)}',this)">🎬 Tạo Video</button>`;
|
|
|
|
|
|
|
| 134 |
return `<div class="wall-item" id="wall-item-${esc(p.id||i)}"><div class="wall-thumb">${thumbContent}${videoBadge}</div><div class="wall-title">${esc(p.title)}</div><div class="wall-text">${esc((p.text||'').slice(0,180))}</div><div class="wall-actions"><button class="primary" onclick="readWallPost(${i})">Xem</button>${videoBtn}</div></div>`;
|
| 135 |
}
|
| 136 |
|
|
|
|
| 171 |
function refreshShortAISlider(){
|
| 172 |
const aiShorts = _wallPosts.filter(p=>p.video);
|
| 173 |
let shortAISection = document.getElementById('short-ai-section');
|
| 174 |
+
if(aiShorts.length === 0){ if(shortAISection) shortAISection.remove(); return; }
|
|
|
|
|
|
|
|
|
|
| 175 |
if(shortAISection){
|
| 176 |
const track = shortAISection.querySelector('.slider-track');
|
| 177 |
if(track){
|
| 178 |
let h = '';
|
| 179 |
+
aiShorts.slice(0,20).forEach((p,i)=>{h+=`<div class="slider-item shorts-item" onclick="openShortAIFeed(${i})"><div class="slider-thumb shorts-thumb"><video src="${esc(p.video)}" muted preload="metadata"></video><div class="card-play">▶</div></div><div class="slider-title">${esc(p.title)}</div></div>`;});
|
|
|
|
|
|
|
| 180 |
track.innerHTML = h;
|
| 181 |
}
|
| 182 |
}
|
|
|
|
| 205 |
div.className='wall-item wall-item-new';
|
| 206 |
div.id='wall-item-'+(post.id||'new-'+Date.now());
|
| 207 |
const hasVideo = post.video && post.video.length > 0;
|
| 208 |
+
const thumbContent = post.img ? `<img src="${esc(post.img)}" loading="lazy" onerror="this.style.display='none'">` : (hasVideo ? `<video src="${esc(post.video)}" muted></video>` : '');
|
|
|
|
|
|
|
| 209 |
const videoBadge = hasVideo ? `<div class="wall-video-badge">🎬</div>` : '';
|
| 210 |
+
const videoBtn = hasVideo ? `<button class="wall-btn-video" onclick="event.stopPropagation();openShortAIFeed(0)">▶ Xem Short</button>` : `<button class="wall-btn-make" onclick="event.stopPropagation();makeShortVideo('${esc(post.id)}',this)">🎬 Tạo Video</button>`;
|
|
|
|
|
|
|
| 211 |
div.innerHTML=`<div class="wall-thumb">${thumbContent}${videoBadge}</div><div class="wall-title">${esc(post.title)}</div><div class="wall-text">${esc((post.text||'').slice(0,180))}</div><div class="wall-actions"><button class="primary" onclick="readWallPost(0)">Xem</button>${videoBtn}</div>`;
|
| 212 |
track.prepend(div);
|
| 213 |
track.scrollTo({left:0,behavior:'smooth'});
|
| 214 |
if(hasVideo) refreshShortAISlider();
|
| 215 |
}
|
| 216 |
|
|
|
|
| 217 |
let _shortsData=[];
|
| 218 |
let _wallPosts=[];
|
| 219 |
let _wcShortsData=[];
|
|
|
|
| 249 |
const teamA=this.querySelector('.teams a[href*="/tran-dau/"]');
|
| 250 |
const a = statusA || teamA;
|
| 251 |
if(a){
|
| 252 |
+
e.preventDefault();e.stopPropagation();
|
|
|
|
| 253 |
const href=a.getAttribute('href')||'';
|
| 254 |
const m=href.match(/\/tran-dau\/(\d+)\//);
|
| 255 |
if(m){
|
|
|
|
| 259 |
}
|
| 260 |
});
|
| 261 |
});
|
| 262 |
+
el.querySelectorAll('a').forEach(a=>{a.addEventListener('click',e=>{e.preventDefault();e.stopPropagation()});});
|
|
|
|
|
|
|
| 263 |
}
|
| 264 |
function openMatch(id,url){if(!id)return;_currentEventId=id;if(url)_currentMatchUrl=url;document.getElementById('match-overlay').classList.add('active');document.body.style.overflow='hidden';loadMatchTab('detail')}
|
| 265 |
function closeMatch(){document.getElementById('match-overlay').classList.remove('active');document.body.style.overflow=''}
|
|
|
|
| 282 |
showView('view-tiktok');
|
| 283 |
const el=document.getElementById('view-tiktok');
|
| 284 |
el.innerHTML='<div class="loading">Đang tải shorts...</div>';
|
|
|
|
|
|
|
| 285 |
let arts = _shortsData.length ? _shortsData : [];
|
| 286 |
+
if(!arts.length){try{arts=await fetch('/api/shorts').then(r=>r.json()).catch(()=>[]);}catch(e){arts=[];}}
|
| 287 |
+
if(!arts.length){el.innerHTML='<div class="loading">Không có shorts</div>';return;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
const ordered=startIdx>0?[...arts.slice(startIdx),...arts.slice(0,startIdx)]:arts;
|
| 289 |
let h=`<button class="back-btn" onclick="switchCat('home')">← Shorts</button><div class="tiktok-container"><div class="tiktok-feed" id="tiktok-feed">`;
|
| 290 |
ordered.forEach((v,i)=>{
|
|
|
|
| 313 |
if(images.length > 0){
|
| 314 |
imgGallery = '<div class="article-image-gallery">';
|
| 315 |
images.forEach((imgUrl, imgIdx) => {
|
| 316 |
+
if(imgIdx === 0){imgGallery += `<img class="article-img article-hero-img" src="${esc(imgUrl)}" onerror="this.style.display='none" loading="eager">`;}
|
| 317 |
+
else{if(imgIdx === 1) imgGallery += '<div class="gallery-thumbs">';imgGallery += `<div class="gallery-thumb"><img src="${esc(imgUrl)}" onerror="this.parentElement.style.display='none'" loading="lazy"></div>`;}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
});
|
| 319 |
if(images.length > 1) imgGallery += '</div>';
|
| 320 |
imgGallery += '</div>';
|
| 321 |
}
|
| 322 |
const hasVideo = p.video && p.video.length > 0;
|
| 323 |
+
const voiceOptions = [{id:'hoaimy',label:'🎙️ Nữ — Hoài My'},{id:'namminh',label:'🎙️ Nam — Nam Minh'}];
|
|
|
|
|
|
|
|
|
|
| 324 |
let voiceSelector = '';
|
| 325 |
if(!hasVideo){
|
| 326 |
voiceSelector = `<div class="tts-selector"><div class="tts-selector-label">🎙️ Chọn giọng đọc:</div><div class="tts-voice-btns">`;
|
| 327 |
+
voiceOptions.forEach(v=>{voiceSelector+=`<button class="tts-voice-btn" onclick="document.querySelectorAll('.tts-voice-btn').forEach(b=>b.classList.remove('active'));this.classList.add('active');document.getElementById('selected-voice').value='${v.id}'">${v.label}</button>`;});
|
| 328 |
+
voiceSelector+=`</div><div class="tts-speed-row"><span>Tốc độ:</span><select id="selected-speed"><option value="1.0">1.0x</option><option value="1.2" selected>1.2x</option><option value="1.5">1.5x</option><option value="0.8">0.8x</option></select></div>`;
|
| 329 |
+
voiceSelector+=`<input type="hidden" id="selected-voice" value="hoaimy"></div>`;
|
|
|
|
|
|
|
| 330 |
}
|
| 331 |
document.getElementById('view-article').innerHTML=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view"><span class="badge badge-ai">AI</span><h1 class="article-title">${esc(p.title)}</h1>${imgGallery}<p class="article-p" style="white-space:pre-wrap">${esc(p.text)}</p>${hasVideo?`<video class="article-img" src="${esc(p.video)}" controls playsinline style="max-height:400px"></video>`:''}<div class="article-actions">${hasVideo?`<button onclick="openShortAIFeed(${i})">🎬 Xem Short</button>${voiceSelector}<button class="primary" onclick="makeShortVideo('${esc(p.id)}',this,document.getElementById('selected-voice')?.value,parseFloat(document.getElementById('selected-speed')?.value)||1.2)">🔄 Tạo lại Short</button>`:`${voiceSelector}<button class="primary" onclick="makeShortVideo('${esc(p.id)}',this,document.getElementById('selected-voice')?.value,parseFloat(document.getElementById('selected-speed')?.value)||1.2)">🎬 Tạo Video Shorts</button>`}<button onclick="doShare('${esc(p.title)}','${SPACE}','${esc(p.img||'')}')">📤</button></div></div>`;
|
| 332 |
const firstVoiceBtn = document.querySelector('.tts-voice-btn');
|
|
|
|
| 335 |
async function loadNewsTab(){const el=document.getElementById('view-cat');el.innerHTML='<div class="loading">Đang tải...</div>';try{const r=await fetch('/api/homepage');const news=await r.json();if(!news.length){el.innerHTML='<div class="loading">Không có tin</div>';return}const groups={};news.forEach(a=>{if(!groups[a.group])groups[a.group]=[];groups[a.group].push(a)});let h='';for(const[g,arts]of Object.entries(groups)){h+=`<div class="section-title">${g}</div><div class="grid">`;arts.slice(0,6).forEach(a=>{h+=`<div class="card" onclick="readArticle('${esc(a.link)}')"><div class="card-img">${a.img?`<img src="${a.img}" loading="lazy">`:''}</div><div class="card-body"><span class="badge badge-vne">${esc(a.source||'VnE')}</span><div class="card-title">${esc(a.title)}</div></div></div>`});h+='</div>'}el.innerHTML=h}catch(e){el.innerHTML='<div class="loading">Lỗi</div>'}}
|
| 336 |
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=>{h+=`<div class="card" onclick="readArticle('${esc(a.link)}')"><div class="card-img">${a.img?`<img src="${a.img}" loading="lazy">`:''}</div><div class="card-body"><span class="badge badge-vne">${esc(a.source||'')}</span><div class="card-title">${esc(a.title)}</div></div></div>`});h+='</div>';el.innerHTML=h}
|
| 337 |
fetch('/api/storage_status').then(r=>r.json()).then(j=>{if(!j.persistent){const home=document.getElementById('view-home');if(home){const w=document.createElement('div');w.className='storage-warn';w.innerHTML='⚠️ Persistent Storage chưa bật.';home.prepend(w)}}}).catch(()=>{});
|
| 338 |
+
(function(){try{var hash=window.location.hash;if(hash&&hash.length>1){var articleUrl=decodeURIComponent(hash.substring(1));if(articleUrl.startsWith('http')){history.replaceState(null,'',window.location.pathname);setTimeout(function(){if(typeof readArticle==='function')readArticle(articleUrl);},1500);}}}catch(e){}})();
|
| 339 |
+
(function(){try{const pa=localStorage.getItem('pending_article');const pv=localStorage.getItem('pending_video');if(pa){localStorage.removeItem('pending_article');setTimeout(()=>{if(typeof readArticle==='function')readArticle(pa);},1500);}if(pv){localStorage.removeItem('pending_video');try{const v=JSON.parse(pv);if(v&&v.url)setTimeout(()=>{window.open(v.url,'_blank')},1500);}catch(e){}}}catch(e){}})();
|
| 340 |
+
if(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',function(){if(typeof loadHome==='function')loadHome();});}else{if(typeof loadHome==='function')loadHome();}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|