Spaces:
Running
Running
Upload static/app_v2.js
Browse files- static/app_v2.js +8 -9
static/app_v2.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
/**
|
| 2 |
* VNEWS Frontend v2 - Shorts Dantri/SKDS removed, VTV Digital CDN
|
| 3 |
-
* v2.
|
| 4 |
*/
|
| 5 |
function _proxyImg(url){
|
| 6 |
if(!url || typeof url !== 'string') return '';
|
|
@@ -52,7 +52,7 @@ async function loadHome(){
|
|
| 52 |
const sc=featuredData.status==='live'?'':'upcoming';
|
| 53 |
const st=featuredData.status==='live'?`🔴 ${featuredData.minute||'LIVE'}`:`⏰ ${featuredData.time}`;
|
| 54 |
const area=document.getElementById('home-featured-area');
|
| 55 |
-
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="${_proxyImg(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="${_proxyImg(featuredData.away_logo)}" onerror="this.style.display='none'"><span>featuredData.away}</span></div></div><div class="fm-status ${sc}">${st}</div></div>`;
|
| 56 |
}
|
| 57 |
|
| 58 |
_wallPosts = (wallData && wallData.posts) || [];
|
|
@@ -187,9 +187,8 @@ async function makeShortVideo(postId, btn, voice, speed, emotion){
|
|
| 187 |
const el = document.getElementById(itemId);
|
| 188 |
if(el){
|
| 189 |
const idx = _wallPosts.indexOf(p);
|
| 190 |
-
el.
|
| 191 |
-
|
| 192 |
-
if(newEl) newEl.className = 'wall-item wall-item-new';
|
| 193 |
}
|
| 194 |
}
|
| 195 |
}catch(e){
|
|
@@ -367,9 +366,7 @@ function prependWallPost(post){
|
|
| 367 |
}
|
| 368 |
return;
|
| 369 |
}
|
| 370 |
-
|
| 371 |
-
div.outerHTML=makeWallItem(post,0);
|
| 372 |
-
track.prepend(div);
|
| 373 |
track.scrollTo({left:0,behavior:'smooth'});
|
| 374 |
}
|
| 375 |
|
|
@@ -416,7 +413,9 @@ function makeShortVideo(postId, btn, voice, speed, emotion){
|
|
| 416 |
toast('⏳ Đang tạo...');
|
| 417 |
fetch('/api/ai/short/'+encodeURIComponent(postId),{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({voice,emotion,speed:speed||1.2})}).then(r=>r.json()).then(j=>{if(j.error)throw new Error(j.error);toast('✅ OK!');}).catch(e=>toast('❌ '+e.message));
|
| 418 |
}
|
| 419 |
-
function readWallPost(idx){const p=_wallPosts&&_wallPosts[idx];if(!p)return;readArticle(p.url||'','','',p.title,p.text);}
|
|
|
|
|
|
|
| 420 |
function readNewsTab(tab){loadNewsTab();}
|
| 421 |
function loadNewsTab(){const el=document.getElementById('view-cat');if(!el)return;el.innerHTML='<div class="loading">Đang tải tin tức...</div>';fetch('/api/homepage').then(r=>r.json()).then(articles=>{if(!articles||!articles.length){el.innerHTML='<div class="loading">Không có tin</div>';return}let h='<div class="grid">';articles.forEach(a=>{const src=a.source||'vne';const badge=a.group||a.source||'';h+=`<div class="card" onclick="readArticle('${esc(a.link)}')"><div class="card-img">${a.img?`<img src="${_proxyImg(a.img)}" loading="lazy" onerror="this.style.display=\'none\'">`:''}</div><div class="card-body"><span class="badge badge-${src}">${esc(badge)}</span><div class="card-title">${esc(a.title)}</div></div></div>`;});h+='</div>';el.innerHTML=h;}).catch(()=>{el.innerHTML='<div class="loading">Lỗi tải</div>';});}
|
| 422 |
|
|
|
|
| 1 |
/**
|
| 2 |
* VNEWS Frontend v2 - Shorts Dantri/SKDS removed, VTV Digital CDN
|
| 3 |
+
* v2.4 - Fixed: prependWallPost detached-element bug, makeShortVideo UI update, slide viewer for rewrite posts
|
| 4 |
*/
|
| 5 |
function _proxyImg(url){
|
| 6 |
if(!url || typeof url !== 'string') return '';
|
|
|
|
| 52 |
const sc=featuredData.status==='live'?'':'upcoming';
|
| 53 |
const st=featuredData.status==='live'?`🔴 ${featuredData.minute||'LIVE'}`:`⏰ ${featuredData.time}`;
|
| 54 |
const area=document.getElementById('home-featured-area');
|
| 55 |
+
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="${_proxyImg(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="${_proxyImg(featuredData.away_logo)}" onerror="this.style.display='none'"><span>${featuredData.away}</span></div></div><div class="fm-status ${sc}">${st}</div></div>`;
|
| 56 |
}
|
| 57 |
|
| 58 |
_wallPosts = (wallData && wallData.posts) || [];
|
|
|
|
| 187 |
const el = document.getElementById(itemId);
|
| 188 |
if(el){
|
| 189 |
const idx = _wallPosts.indexOf(p);
|
| 190 |
+
el.insertAdjacentHTML('afterend', makeWallItem(p, idx));
|
| 191 |
+
el.remove();
|
|
|
|
| 192 |
}
|
| 193 |
}
|
| 194 |
}catch(e){
|
|
|
|
| 366 |
}
|
| 367 |
return;
|
| 368 |
}
|
| 369 |
+
track.insertAdjacentHTML('afterbegin', makeWallItem(post, 0));
|
|
|
|
|
|
|
| 370 |
track.scrollTo({left:0,behavior:'smooth'});
|
| 371 |
}
|
| 372 |
|
|
|
|
| 413 |
toast('⏳ Đang tạo...');
|
| 414 |
fetch('/api/ai/short/'+encodeURIComponent(postId),{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({voice,emotion,speed:speed||1.2})}).then(r=>r.json()).then(j=>{if(j.error)throw new Error(j.error);toast('✅ OK!');}).catch(e=>toast('❌ '+e.message));
|
| 415 |
}
|
| 416 |
+
function readWallPost(idx){const p=_wallPosts&&_wallPosts[idx];if(!p)return;if(p.slides&&p.slides.length){readSlidePost(idx);return}readArticle(p.url||'','','',p.title,p.text);}
|
| 417 |
+
/** Show rewrite slide viewer - vertical slides with text+image */
|
| 418 |
+
function readSlidePost(idx){const p=_wallPosts[idx];if(!p||!p.slides)return;showView('view-article');const el=document.getElementById('view-article');let h=`<button class="back-btn" onclick="switchCat('home')">← Tường AI</button><div class="slide-viewer" style="padding:12px;max-width:600px;margin:0 auto">`;p.slides.forEach((s,i)=>{h+=`<div class="slide-card" style="background:#1a1a1a;border:1px solid #2a2a2a;border-radius:12px;padding:16px;margin-bottom:12px"><div class="slide-num" style="color:#5cb87a;font-size:12px;font-weight:700;margin-bottom:6px">Slide ${s.index||i+1}/${p.slides.length}</div>${s.image?`<img src="${_proxyImg(s.image)}" style="width:100%;max-height:300px;object-fit:cover;border-radius:8px;margin-bottom:8px" loading="lazy" onerror="this.style.display=\'none\'">`:''}<p style="color:#ddd;font-size:14px;line-height:1.6;margin:0">${esc(s.text)}</p></div>`;});h+=`</div>`;el.innerHTML=h;}
|
| 419 |
function readNewsTab(tab){loadNewsTab();}
|
| 420 |
function loadNewsTab(){const el=document.getElementById('view-cat');if(!el)return;el.innerHTML='<div class="loading">Đang tải tin tức...</div>';fetch('/api/homepage').then(r=>r.json()).then(articles=>{if(!articles||!articles.length){el.innerHTML='<div class="loading">Không có tin</div>';return}let h='<div class="grid">';articles.forEach(a=>{const src=a.source||'vne';const badge=a.group||a.source||'';h+=`<div class="card" onclick="readArticle('${esc(a.link)}')"><div class="card-img">${a.img?`<img src="${_proxyImg(a.img)}" loading="lazy" onerror="this.style.display=\'none\'">`:''}</div><div class="card-body"><span class="badge badge-${src}">${esc(badge)}</span><div class="card-title">${esc(a.title)}</div></div></div>`;});h+='</div>';el.innerHTML=h;}).catch(()=>{el.innerHTML='<div class="loading">Lỗi tải</div>';});}
|
| 421 |
|