Spaces:
Running
Running
Restore app_v2.js from e77a637 - full e77a637 version
Browse files- static/app_v2.js +48 -52
static/app_v2.js
CHANGED
|
@@ -21,22 +21,18 @@ async function loadHome(){
|
|
| 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>'
|
| 22 |
+'<div id="hashtag-box"></div>'
|
| 23 |
+'<div class="ls-section"><div class="ls-header"><h3>⚽ Livescore</h3></div><div class="ls-tabs"><span class="ls-tab active" data-tab="today" onclick="loadLivescore(\'today\')">📅 Hôm nay</span><span class="ls-tab" 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="bxh_nha" onclick="loadLivescore(\'bxh_nha\')">🏆 NHA</span><span class="ls-tab" data-tab="bxh_laliga" onclick="loadLivescore(\'bxh_laliga\')">🏆 La Liga</span></div><div class="ls-content" id="ls-content"><div class="loading">Đang tải...</div></div></div>'
|
| 24 |
-
+'<div id="
|
| 25 |
-
+'<div id="home-after-wc"></div>';
|
| 26 |
|
| 27 |
-
const afterEl = homeEl.querySelector('#home-
|
| 28 |
|
| 29 |
loadLivescore('today');
|
| 30 |
loadHotTopics();
|
| 31 |
|
| 32 |
-
const [featuredData,
|
| 33 |
_fetchWithTimeout('/api/livescore/featured', 5000),
|
| 34 |
-
_fetchWithTimeout('/api/shorts', 8000),
|
| 35 |
_fetchWithTimeout('/api/wall', 5000),
|
| 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){
|
|
@@ -46,15 +42,9 @@ async function loadHome(){
|
|
| 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);
|
| 60 |
if(aiData && aiData.length) _renderSlidesIn('ai-articles','Ứng dụng AI','🤖',aiData,afterEl);
|
|
@@ -78,24 +68,6 @@ function _renderSlidesIn(key, label, emoji, vids, afterEl){
|
|
| 78 |
afterEl.parentNode.insertBefore(wrap, afterEl);
|
| 79 |
}
|
| 80 |
|
| 81 |
-
function _renderShortsIn(afterEl){
|
| 82 |
-
if(!_shortsData||!_shortsData.length||!afterEl) return;
|
| 83 |
-
const mixed=interleaveShorts(_shortsData);
|
| 84 |
-
if(!mixed.length) return;
|
| 85 |
-
const wrap=document.createElement('div');
|
| 86 |
-
wrap.className='slider-wrap';
|
| 87 |
-
let h=`<div class="slider-header"><span class="slider-label">📱 Shorts Dân trí · SKĐS · VTV Nam Bộ</span><span class="slider-note">Mới nhất · xen kẽ · cập nhật thời gian thực</span></div><div class="slider-track">`;
|
| 88 |
-
mixed.slice(0,36).forEach((a,i)=>{
|
| 89 |
-
let badge, badgeColor;
|
| 90 |
-
if(a.channel==='baosuckhoedoisongboyte'){ badge='SKĐS'; badgeColor='#e67e22'; }
|
| 91 |
-
else if(a.channel==='vtvnambo'){ badge='VTV Nam Bộ'; badgeColor='#0b6bcb'; }
|
| 92 |
-
else { badge='Dân trí'; badgeColor='#27ae60'; }
|
| 93 |
-
h+=`<div class="slider-item shorts-item" onclick="openYTShortsFeed(${i})"><div class="slider-thumb shorts-thumb">${a.img?`<img src="${a.img}" loading="lazy">`:''}<div class="card-play">▶</div><span class="shorts-badge" style="background:${badgeColor}">${badge}</span></div><div class="slider-title">${esc(a.title)}</div></div>`;
|
| 94 |
-
});
|
| 95 |
-
h+='</div>';wrap.innerHTML=h;
|
| 96 |
-
afterEl.parentNode.insertBefore(wrap,afterEl);
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
function _renderWallIn(afterEl){
|
| 100 |
if(!_wallPosts||!_wallPosts.length||!afterEl) return;
|
| 101 |
const posts=_wallPosts;
|
|
@@ -205,7 +177,7 @@ function prependWallPost(post){
|
|
| 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(
|
| 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>`;
|
|
@@ -214,26 +186,10 @@ function prependWallPost(post){
|
|
| 214 |
if(hasVideo) refreshShortAISlider();
|
| 215 |
}
|
| 216 |
|
| 217 |
-
let _shortsData=[];
|
| 218 |
let _wallPosts=[];
|
| 219 |
-
let _wcShortsData=[];
|
| 220 |
let _currentView='home';
|
| 221 |
let _currentEventId=null;
|
| 222 |
let _currentMatchUrl=null;
|
| 223 |
-
function interleaveShorts(shorts){
|
| 224 |
-
const dt=shorts.filter(s=>s.channel==='baodantri7941');
|
| 225 |
-
const sk=shorts.filter(s=>s.channel==='baosuckhoedoisongboyte');
|
| 226 |
-
const vt=shorts.filter(s=>s.channel==='vtvnambo');
|
| 227 |
-
const result=[];
|
| 228 |
-
let i=0,j=0,k=0;
|
| 229 |
-
const maxLen=Math.max(dt.length, sk.length, vt.length);
|
| 230 |
-
for(let x=0;x<maxLen;x++){
|
| 231 |
-
if(x<dt.length)result.push(dt[x]);
|
| 232 |
-
if(x<sk.length)result.push(sk[x]);
|
| 233 |
-
if(x<vt.length)result.push(vt[x]);
|
| 234 |
-
}
|
| 235 |
-
return result;
|
| 236 |
-
}
|
| 237 |
let _htPage=0,_htTopic='';
|
| 238 |
async function loadHotTopics(){const j=await fetch('/api/hot_topics').then(r=>r.json()).catch(()=>({topics:[]}));const el=document.getElementById('hot-topics');if(!el)return;el.innerHTML=(j.topics||[]).slice(0,18).map(t=>{const topicText=t.topic||t.label.replace(/^#/,'');return`<button class="hot-chip" onclick="searchTopic('${topicText.replace(/'/g,"\\'")}')">${esc(t.label)}</button>`;}).join('');if(j.topics&&j.topics[0]){const firstTopic=j.topics[0].topic||j.topics[0].label.replace(/^#/,'');setTimeout(()=>searchTopic(firstTopic),800);}}
|
| 239 |
function searchTopic(topic){if(!topic){topic=document.getElementById('topic-input')?.value.trim();if(!topic){alert('Nhập chủ đề');return;}}document.getElementById('topic-input').value='';_htTopic=topic;_htPage=0;showHashtagSources(topic,0);}
|
|
@@ -293,7 +249,7 @@ async function openYTShortsFeed(startIdx){
|
|
| 293 |
const vtag=`<iframe data-yt-src="${src}" allowfullscreen allow="accelerometer;autoplay;clipboard-write;encrypted-media;gyroscope;picture-in-picture"></iframe>`;
|
| 294 |
let badge,badgeClass;
|
| 295 |
if(v.channel==='baosuckhoedoisongboyte'){badge='SKĐS';badgeClass='badge-fpt';}
|
| 296 |
-
else if(v.channel==='vtvnambo'){badge='VTV Nam Bộ';badgeClass='badge-
|
| 297 |
else{badge='Dân trí';badgeClass='badge-vne';}
|
| 298 |
const videoId='yt-'+id;
|
| 299 |
h+=buildTikTokSlide({vtag,title:v.title,badge,badgeClass,videoId,idx:i,total:ordered.length,shareUrl:'https://youtube.com/shorts/'+id});
|
|
@@ -303,7 +259,47 @@ async function openYTShortsFeed(startIdx){
|
|
| 303 |
initTikTokFeed();
|
| 304 |
}
|
| 305 |
async function openShortAIFeed(startIdx){showView('view-tiktok');const el=document.getElementById('view-tiktok');el.innerHTML='<div class="loading">Đang tải...</div>';const wall=(await fetch('/api/wall').then(r=>r.json()).catch(()=>({posts:[]}))).posts||[];const vids=wall.filter(p=>p.video);if(!vids.length){el.innerHTML='<div class="loading">Chưa có Short AI</div>';return}const ordered=startIdx>0?[...vids.slice(startIdx),...vids.slice(0,startIdx)]:vids;let h=`<button class="back-btn" onclick="switchCat('home')">← Short AI</button><div class="tiktok-container"><div class="tiktok-feed" id="tiktok-feed">`;ordered.forEach((p,i)=>{const vtag=`<video src="${p.video}" playsinline loop controls></video>`;const videoId='ai-'+(p.id||i);h+=buildTikTokSlide({vtag,title:p.title,badge:'AI',badgeClass:'badge-ai',videoId,idx:i,total:ordered.length,shareUrl:SPACE});});h+='</div></div>';el.innerHTML=h;initTikTokFeed();}
|
| 306 |
-
async function readArticle(url){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
async function rewriteArticle(){const url=_currentArticle?.url;if(!url)return;toast('⏳ Đang rewrite...');try{const r=await fetch('/api/rewrite_share',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url,context:document.querySelector('.article-view')?.innerText?.slice(0,14000)||''})});const j=await r.json();if(!r.ok||j.error)throw new Error(j.error);toast('✅ Đã đăng Tường AI!');if(j.post)prependWallPost(j.post);}catch(e){toast('❌ '+e.message)}}
|
| 308 |
async function rewriteUrl(){const url=document.getElementById('url-input')?.value.trim();if(!url)return alert('Dán URL');toast('⏳ Đang rewrite...');try{const r=await fetch('/api/url_wall',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url})});const j=await r.json();if(!r.ok||j.error)throw new Error(j.error);toast('✅ Đã đăng!');document.getElementById('url-input').value='';if(j.post)prependWallPost(j.post);}catch(e){toast('❌ '+e.message)}}
|
| 309 |
async function askAI(){const q=document.getElementById('ask-q')?.value.trim();if(!q)return alert('Nhập câu hỏi');const a=document.getElementById('ask-a');a.textContent='Đang hỏi...';try{const r=await fetch('/api/article/ask',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url:_currentArticle?.url||'',question:q,context:document.querySelector('.article-view')?.innerText?.slice(0,12000)||''})});const j=await r.json();a.textContent=j.answer||'Không trả lời được';}catch(e){a.textContent='Lỗi: '+e.message}}
|
|
@@ -335,6 +331,6 @@ async function readWallPost(i){const p=_wallPosts[i];if(!p)return;showView('view
|
|
| 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);
|
| 339 |
-
(function(){try{const pa=localStorage.getItem('pending_article');const pv=localStorage.getItem('pending_video');if(pa){localStorage.removeItem('pending_article');
|
| 340 |
if(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',function(){if(typeof loadHome==='function')loadHome();});}else{if(typeof loadHome==='function')loadHome();}
|
|
|
|
| 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>'
|
| 22 |
+'<div id="hashtag-box"></div>'
|
| 23 |
+'<div class="ls-section"><div class="ls-header"><h3>⚽ Livescore</h3></div><div class="ls-tabs"><span class="ls-tab active" data-tab="today" onclick="loadLivescore(\'today\')">📅 Hôm nay</span><span class="ls-tab" 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="bxh_nha" onclick="loadLivescore(\'bxh_nha\')">🏆 NHA</span><span class="ls-tab" data-tab="bxh_laliga" onclick="loadLivescore(\'bxh_laliga\')">🏆 La Liga</span></div><div class="ls-content" id="ls-content"><div class="loading">Đang tải...</div></div></div>'
|
| 24 |
+
+'<div id="home-content"></div>';
|
|
|
|
| 25 |
|
| 26 |
+
const afterEl = homeEl.querySelector('#home-content');
|
| 27 |
|
| 28 |
loadLivescore('today');
|
| 29 |
loadHotTopics();
|
| 30 |
|
| 31 |
+
const [featuredData, wallData, hlLeagues, aiData] = await Promise.allSettled([
|
| 32 |
_fetchWithTimeout('/api/livescore/featured', 5000),
|
|
|
|
| 33 |
_fetchWithTimeout('/api/wall', 5000),
|
| 34 |
_fetchWithTimeout('/api/highlights/leagues', 10000),
|
| 35 |
_fetchWithTimeout('/api/genk_ai', 8000),
|
|
|
|
|
|
|
| 36 |
]).then(results => results.map(r => r.status === 'fulfilled' ? r.value : null));
|
| 37 |
|
| 38 |
if(featuredData && featuredData.home){
|
|
|
|
| 42 |
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>`;
|
| 43 |
}
|
| 44 |
|
|
|
|
| 45 |
_wallPosts = (wallData && wallData.posts) || [];
|
| 46 |
_hlLeagueData = hlLeagues || {};
|
|
|
|
|
|
|
| 47 |
|
|
|
|
|
|
|
|
|
|
| 48 |
_renderWallIn(afterEl);
|
| 49 |
_renderHLIn(afterEl);
|
| 50 |
if(aiData && aiData.length) _renderSlidesIn('ai-articles','Ứng dụng AI','🤖',aiData,afterEl);
|
|
|
|
| 68 |
afterEl.parentNode.insertBefore(wrap, afterEl);
|
| 69 |
}
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
function _renderWallIn(afterEl){
|
| 72 |
if(!_wallPosts||!_wallPosts.length||!afterEl) return;
|
| 73 |
const posts=_wallPosts;
|
|
|
|
| 177 |
div.className='wall-item wall-item-new';
|
| 178 |
div.id='wall-item-'+(post.id||'new-'+Date.now());
|
| 179 |
const hasVideo = post.video && post.video.length > 0;
|
| 180 |
+
const thumbContent = post.img ? `<img src="${esc(post.img)}" loading="lazy" onerror="this.style.display='none'">` : (hasVideo ? `<video src="${esc(p.video)}" muted></video>` : '');
|
| 181 |
const videoBadge = hasVideo ? `<div class="wall-video-badge">🎬</div>` : '';
|
| 182 |
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>`;
|
| 183 |
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>`;
|
|
|
|
| 186 |
if(hasVideo) refreshShortAISlider();
|
| 187 |
}
|
| 188 |
|
|
|
|
| 189 |
let _wallPosts=[];
|
|
|
|
| 190 |
let _currentView='home';
|
| 191 |
let _currentEventId=null;
|
| 192 |
let _currentMatchUrl=null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
let _htPage=0,_htTopic='';
|
| 194 |
async function loadHotTopics(){const j=await fetch('/api/hot_topics').then(r=>r.json()).catch(()=>({topics:[]}));const el=document.getElementById('hot-topics');if(!el)return;el.innerHTML=(j.topics||[]).slice(0,18).map(t=>{const topicText=t.topic||t.label.replace(/^#/,'');return`<button class="hot-chip" onclick="searchTopic('${topicText.replace(/'/g,"\\'")}')">${esc(t.label)}</button>`;}).join('');if(j.topics&&j.topics[0]){const firstTopic=j.topics[0].topic||j.topics[0].label.replace(/^#/,'');setTimeout(()=>searchTopic(firstTopic),800);}}
|
| 195 |
function searchTopic(topic){if(!topic){topic=document.getElementById('topic-input')?.value.trim();if(!topic){alert('Nhập chủ đề');return;}}document.getElementById('topic-input').value='';_htTopic=topic;_htPage=0;showHashtagSources(topic,0);}
|
|
|
|
| 249 |
const vtag=`<iframe data-yt-src="${src}" allowfullscreen allow="accelerometer;autoplay;clipboard-write;encrypted-media;gyroscope;picture-in-picture"></iframe>`;
|
| 250 |
let badge,badgeClass;
|
| 251 |
if(v.channel==='baosuckhoedoisongboyte'){badge='SKĐS';badgeClass='badge-fpt';}
|
| 252 |
+
else if(v.channel==='vtvnambo'){badge='VTV Nam Bộ';badgeClass='badge-dantri';}
|
| 253 |
else{badge='Dân trí';badgeClass='badge-vne';}
|
| 254 |
const videoId='yt-'+id;
|
| 255 |
h+=buildTikTokSlide({vtag,title:v.title,badge,badgeClass,videoId,idx:i,total:ordered.length,shareUrl:'https://youtube.com/shorts/'+id});
|
|
|
|
| 259 |
initTikTokFeed();
|
| 260 |
}
|
| 261 |
async function openShortAIFeed(startIdx){showView('view-tiktok');const el=document.getElementById('view-tiktok');el.innerHTML='<div class="loading">Đang tải...</div>';const wall=(await fetch('/api/wall').then(r=>r.json()).catch(()=>({posts:[]}))).posts||[];const vids=wall.filter(p=>p.video);if(!vids.length){el.innerHTML='<div class="loading">Chưa có Short AI</div>';return}const ordered=startIdx>0?[...vids.slice(startIdx),...vids.slice(0,startIdx)]:vids;let h=`<button class="back-btn" onclick="switchCat('home')">← Short AI</button><div class="tiktok-container"><div class="tiktok-feed" id="tiktok-feed">`;ordered.forEach((p,i)=>{const vtag=`<video src="${p.video}" playsinline loop controls></video>`;const videoId='ai-'+(p.id||i);h+=buildTikTokSlide({vtag,title:p.title,badge:'AI',badgeClass:'badge-ai',videoId,idx:i,total:ordered.length,shareUrl:SPACE});});h+='</div></div>';el.innerHTML=h;initTikTokFeed();}
|
| 262 |
+
async function readArticle(url){
|
| 263 |
+
showView('view-article');
|
| 264 |
+
const el=document.getElementById('view-article');
|
| 265 |
+
el.innerHTML='<div class="loading">Đang tải...</div>';
|
| 266 |
+
try{const cached=localStorage.getItem('article_'+url);if(cached){const parsed=JSON.parse(cached);if(parsed&&parsed.body&&parsed.body.length){_currentArticle={url,data:parsed};_renderArticle(el,parsed,url);return}}}catch(e){}
|
| 267 |
+
try{
|
| 268 |
+
const ctrl=new AbortController();
|
| 269 |
+
const tid=setTimeout(()=>ctrl.abort(),15000);
|
| 270 |
+
const r=await fetch('/api/article?url='+encodeURIComponent(url),{signal:ctrl.signal});
|
| 271 |
+
clearTimeout(tid);
|
| 272 |
+
const data=await r.json();
|
| 273 |
+
if(data&&!data.error&&data.body&&data.body.length){
|
| 274 |
+
_currentArticle={url,data};
|
| 275 |
+
try{localStorage.setItem('article_'+url,JSON.stringify(data))}catch(e){}
|
| 276 |
+
_renderArticle(el,data,url);
|
| 277 |
+
return;
|
| 278 |
+
}
|
| 279 |
+
}catch(e){}
|
| 280 |
+
el.innerHTML=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="loading"><p>Không đọc được.</p><button class="primary" onclick="window.open('${esc(url)}','_blank')" style="margin-top:8px">📖 Mở bài gốc</button></div>`;
|
| 281 |
+
}
|
| 282 |
+
function _renderArticle(el,data,url){
|
| 283 |
+
let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view"><h1 class="article-title">${esc(data.title)}</h1>`;
|
| 284 |
+
if(data.summary)h+=`<div class="article-summary">${esc(data.summary)}</div>`;
|
| 285 |
+
const seen={};
|
| 286 |
+
data.body.forEach(b=>{
|
| 287 |
+
if(b.type==='p')h+=`<p class="article-p">${b.text}</p>`;
|
| 288 |
+
else if(b.type==='img'&&b.src&&!seen[b.src]){seen[b.src]=1;h+=`<img class="article-img" src="${esc(b.src)}" onerror="this.style.display='none'">`}
|
| 289 |
+
else if(b.type==='heading')h+=`<h2 class="article-h2">${esc(b.text)}</h2>`;
|
| 290 |
+
});
|
| 291 |
+
if(data.fallback){
|
| 292 |
+
h+=`<div style="background:#fff3cd;border:1px solid #ffc107;border-radius:8px;padding:12px;margin:12px 0;font-size:13px;color:#856404">📰 <strong>Nội dung tóm tắt</strong> — Trang nguồn giới hạn truy cập. <a href="${esc(url)}" target="_blank" style="color:#856404;text-decoration:underline">Đọc bài đầy đủ →</a></div>`;
|
| 293 |
+
}
|
| 294 |
+
h+=`<div class="article-actions">`;
|
| 295 |
+
h+=`<button class="primary" onclick="window.open('${esc(url)}','_blank')">📖 Đọc bài gốc</button>`;
|
| 296 |
+
h+=`<button onclick="rewriteArticle()">🤖 Rewrite AI</button>`;
|
| 297 |
+
h+=`<button onclick="doShare('${esc(data.title)}','${esc(url)}','${esc(data.og_image||'')}')">📤</button>`;
|
| 298 |
+
h+=`</div>`;
|
| 299 |
+
h+=`<div class="article-ai-ask"><h3 style="font-size:14px;color:#5cb87a">🤖 Hỏi AI</h3><textarea id="ask-q" placeholder="Hỏi về bài viết..."></textarea><button onclick="askAI()">Hỏi</button><div id="ask-a" class="article-ai-answer"></div></div></div>`;
|
| 300 |
+
el.innerHTML=h;
|
| 301 |
+
window.scrollTo(0,0);
|
| 302 |
+
}
|
| 303 |
async function rewriteArticle(){const url=_currentArticle?.url;if(!url)return;toast('⏳ Đang rewrite...');try{const r=await fetch('/api/rewrite_share',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url,context:document.querySelector('.article-view')?.innerText?.slice(0,14000)||''})});const j=await r.json();if(!r.ok||j.error)throw new Error(j.error);toast('✅ Đã đăng Tường AI!');if(j.post)prependWallPost(j.post);}catch(e){toast('❌ '+e.message)}}
|
| 304 |
async function rewriteUrl(){const url=document.getElementById('url-input')?.value.trim();if(!url)return alert('Dán URL');toast('⏳ Đang rewrite...');try{const r=await fetch('/api/url_wall',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url})});const j=await r.json();if(!r.ok||j.error)throw new Error(j.error);toast('✅ Đã đăng!');document.getElementById('url-input').value='';if(j.post)prependWallPost(j.post);}catch(e){toast('❌ '+e.message)}}
|
| 305 |
async function askAI(){const q=document.getElementById('ask-q')?.value.trim();if(!q)return alert('Nhập câu hỏi');const a=document.getElementById('ask-a');a.textContent='Đang hỏi...';try{const r=await fetch('/api/article/ask',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url:_currentArticle?.url||'',question:q,context:document.querySelector('.article-view')?.innerText?.slice(0,12000)||''})});const j=await r.json();a.textContent=j.answer||'Không trả lời được';}catch(e){a.textContent='Lỗi: '+e.message}}
|
|
|
|
| 331 |
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>'}}
|
| 332 |
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}
|
| 333 |
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(()=>{});
|
| 334 |
+
(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);if(typeof readArticle==='function')readArticle(articleUrl);}}}catch(e){}})();
|
| 335 |
+
(function(){try{const pa=localStorage.getItem('pending_article');const pv=localStorage.getItem('pending_video');if(pa){localStorage.removeItem('pending_article');if(typeof readArticle==='function')readArticle(pa);}if(pv){localStorage.removeItem('pending_video');try{const v=JSON.parse(pv);if(v&&v.url)window.open(v.url,'_blank');}catch(e){}}}catch(e){}})();
|
| 336 |
if(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',function(){if(typeof loadHome==='function')loadHome();});}else{if(typeof loadHome==='function')loadHome();}
|