Spaces:
Running
Running
Speed up homepage with lazy-loaded sections
Browse files- static/index.html +15 -23
static/index.html
CHANGED
|
@@ -6,13 +6,11 @@
|
|
| 6 |
<title>VNEWS - Tin Tức Việt Nam</title>
|
| 7 |
<meta name="description" content="Tin tức tổng hợp, video short, highlight bóng đá, tường AI.">
|
| 8 |
<meta property="og:title" content="VNEWS - Tin Tức Việt Nam">
|
| 9 |
-
<meta property="og:description" content="Đọc tin, xem video, tạo short AI từ bài viết.">
|
| 10 |
<meta property="og:image" content="https://s1.vnecdn.net/vnexpress/restruct/i/v9505/logo_default.jpg">
|
| 11 |
-
<meta property="og:type" content="website">
|
| 12 |
<link rel="canonical" href="https://bep40-vnews.hf.space">
|
| 13 |
<script src="https://cdn.jsdelivr.net/npm/hls.js@1/dist/hls.min.js"></script>
|
| 14 |
<style>
|
| 15 |
-
*{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{color:#fff;font-size:18px;font-weight:800}.header p{color:rgba(255,255,255,.6);font-size:10px;margin-top:2px}.cats{display:flex;overflow-x:auto;background:#1a1a1a;border-bottom:1px solid #333;padding:0 4px;scrollbar-width:none;position:sticky;top:0;z-index:50}.cats::-webkit-scrollbar{display:none}.cat{padding:9px 11px;color:#888;font-size:11px;cursor:pointer;white-space:nowrap;border-bottom:2px solid transparent;flex-shrink:0}.cat.active{color:#5cb87a;border-bottom-color:#5cb87a;font-weight:600}.view{display:none}.view.active{display:block}.loading{text-align:center;padding:40px;color:#666;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-radius:8px;overflow:hidden;cursor:pointer;border:1px solid #222}.card:active{transform:scale(.98)}.card-img{position:relative;width:100%;aspect-ratio:16/9;background:#333;overflow:hidden}.card-img img{width:100%;height:100%;object-fit:cover}.card-play{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:30px;height:30px;background:rgba(0,0,0,.55);border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;font-size:11px}.card-body{padding:6px 8px}.card-title{font-size:11px;font-weight:600;color:#eee;line-height:1.35;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.
|
| 16 |
</style>
|
| 17 |
</head>
|
| 18 |
<body>
|
|
@@ -23,28 +21,23 @@
|
|
| 23 |
<div id="view-video" class="view"></div>
|
| 24 |
<div id="view-tiktok" class="view"></div>
|
| 25 |
<div id="view-article" class="view"></div>
|
| 26 |
-
<div class="ai-short" id="ai-short"><div class="ai-bg" id="ai-bg"></div><div class="ai-phone"><div class="ai-hero" id="ai-hero"></div><div class="ai-grad"></div><div class="ai-brand">VNEWS AI SHORT</div><div class="ai-topic" id="ai-topic">Tin tức</div><div class="ai-caption" id="ai-caption"></div><div class="ai-title" id="ai-title"></div><div class="ai-progress" id="ai-progress"></div></div><button class="ai-close" onclick="closeAiShort()">×</button><div class="ai-controls"><button onclick="replayAiShort()">↻</button><button onclick="toggleAiVoice()" id="ai-voice-btn">🔊</button></div><div class="ai-note">Short AI dùng giọng đọc tiếng Việt của trình duyệt.
|
| 27 |
<script>
|
| 28 |
const SPACE=location.origin;let _cats=[],_tikData=[],_wallPosts=[],_currentAiPost=null,_aiMuted=false,_aiTimer=null,_aiStep=0;
|
| 29 |
-
const LS={get(k){try{return JSON.parse(localStorage.getItem(k))}catch{return null}},set(k,v){try{localStorage.setItem(k,JSON.stringify(v))}catch{}}};
|
| 30 |
-
function hid(s){let h=0;for(let i=0;i<s.length;i++){h=((h<<5)-h)+s.charCodeAt(i);h|=0;}return Math.abs(h).toString(36).slice(0,10);}
|
| 31 |
function escapeHtml(s){return String(s||'').replace(/[&<>"']/g,m=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[m]));}
|
| 32 |
-
function incS(id){let v=(LS.get('s_'+id)||0)+1;LS.set('s_'+id,v);return v;}function getS(id){return LS.get('s_'+id)||0}
|
| 33 |
function doShareVideo(title,videoUrl,img,type){const shareUrl=SPACE+'/v?url='+encodeURIComponent(videoUrl)+'&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 video!')).catch(()=>{});}
|
| 34 |
function doShare(title,articleUrl,img){const shareUrl=SPACE+'/s?url='+encodeURIComponent(articleUrl)+'&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 link!')).catch(()=>{});}
|
| 35 |
-
|
|
|
|
| 36 |
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=>{try{v.pause()}catch(e){}});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);}}
|
| 37 |
function showView(id){document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.getElementById(id).classList.add('active');}
|
| 38 |
-
async function
|
| 39 |
-
if(
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
const
|
| 44 |
-
function
|
| 45 |
-
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;}
|
| 46 |
-
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;}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 class="primary" onclick="rewriteAndShare('${url.replace(/'/g,"\\'")}')">🤖 AI viết lại & đăng tường</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>`;el.innerHTML=h;window.scrollTo(0,0);}
|
| 47 |
-
function rewriteAndShare(url){if(!confirm('Dùng AI viết lại bài này và đăng lên Tường AI?'))return;fetch('/api/rewrite_share',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url})}).then(r=>r.json()).then(j=>{if(j&&j.post){alert('Đã đăng lên Tường AI');switchCat('home');setTimeout(loadHome,600);}else alert(j.error||'Không tạo được bài AI');}).catch(()=>alert('Lỗi tạo bài AI'));}
|
| 48 |
function inferTopic(post){let t=((post.title||'')+' '+(post.text||'')).toLowerCase();if(/bóng đá|world cup|trận|đội tuyển|ngoại hạng|champions/.test(t))return 'Thể thao';if(/ai|trí tuệ|công nghệ|robot|iphone|app|mạng/.test(t))return 'Công nghệ';if(/sức khỏe|bệnh|bác sĩ|thuốc|y tế/.test(t))return 'Sức khỏe';if(/kinh tế|doanh nghiệp|giá|thị trường|tỷ phú/.test(t))return 'Kinh tế';if(/thế giới|mỹ|nga|trung quốc|châu âu/.test(t))return 'Thế giới';return 'Tin nóng';}
|
| 49 |
function buildShortScript(post){let txt=(post.text||post.title||'').replace(/Bản tin AI viết lại:/i,'').replace(/Điểm chính:/i,'').replace(/[•\n]+/g,'. ');let parts=txt.split(/[.!?]+/).map(x=>x.trim()).filter(x=>x.length>25).slice(0,7);if(!parts.length)parts=[post.title||'Bản tin mới trên VNEWS'];return parts.map((p,i)=>i===0?'Tin đáng chú ý: '+p:p);}
|
| 50 |
function openAiShort(id){let post=_wallPosts.find(p=>p.id===id);if(!post)return;_currentAiPost=post;document.documentElement.classList.add('ms-lock');document.body.classList.add('ms-lock');document.getElementById('ai-title').textContent=post.title||'';document.getElementById('ai-topic').textContent=inferTopic(post);let img=post.img||'https://s1.vnecdn.net/vnexpress/restruct/i/v9505/logo_default.jpg';document.getElementById('ai-bg').style.backgroundImage=`url('${img}')`;document.getElementById('ai-hero').style.backgroundImage=`url('${img}')`;document.getElementById('ai-short').classList.add('active');startAiShort();}
|
|
@@ -53,11 +46,10 @@ function stopAiVoice(){clearTimeout(_aiTimer);_aiTimer=null;if(window.speechSynt
|
|
| 53 |
function pickViVoice(){let vs=(speechSynthesis.getVoices&&speechSynthesis.getVoices())||[];return vs.find(v=>/vi|Vietnam/i.test(v.lang+' '+v.name))||vs.find(v=>/Google|Microsoft|Natural/i.test(v.name))||vs[0]||null;}
|
| 54 |
function speakVi(text,cb){if(_aiMuted||!window.speechSynthesis){_aiTimer=setTimeout(cb,3200);return;}speechSynthesis.cancel();let u=new SpeechSynthesisUtterance(text);u.lang='vi-VN';u.rate=1.02;u.pitch=1.02;let v=pickViVoice();if(v)u.voice=v;u.onend=()=>cb&&cb();u.onerror=()=>{_aiTimer=setTimeout(cb,2600)};speechSynthesis.speak(u);}
|
| 55 |
function startAiShort(){stopAiVoice();let post=_currentAiPost;if(!post)return;let lines=buildShortScript(post);_aiStep=0;function next(){if(!document.getElementById('ai-short').classList.contains('active'))return;let line=lines[_aiStep%lines.length];document.getElementById('ai-caption').textContent=line;document.getElementById('ai-progress').style.width=Math.round(((_aiStep+1)/lines.length)*100)+'%';speakVi(line,()=>{_aiStep++;if(_aiStep<lines.length)_aiTimer=setTimeout(next,350);else _aiTimer=setTimeout(()=>{document.getElementById('ai-progress').style.width='0%';_aiStep=0;next();},1800);});}next();}
|
| 56 |
-
function replayAiShort(){startAiShort();}
|
| 57 |
-
function
|
| 58 |
-
async function
|
| 59 |
-
async function
|
| 60 |
-
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);}
|
| 61 |
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();}
|
| 62 |
function shareVid(i){const v=_tikData[i];if(!v)return;doShareVideo(v.title,v.link||'',v.poster||v.img||'','highlights');}
|
| 63 |
function initFeed(){const feed=document.getElementById('tiktok-feed');if(!feed)return;const slides=feed.querySelectorAll('.tiktok-slide');let cur=-1;function activate(idx){if(idx===cur)return;slides.forEach((sl,i)=>{const v=sl.querySelector('video');const f=sl.querySelector('iframe');if(i===idx){if(v&&v.dataset.hls){if(!v._hls){const hls=new Hls();hls.loadSource(v.dataset.hls);hls.attachMedia(v);hls.on(Hls.Events.MANIFEST_PARSED,()=>v.play().catch(()=>{}));v._hls=hls;}else v.play().catch(()=>{});}else if(v)v.play().catch(()=>{});if(f&&!f.src&&f.dataset.ytSrc)f.src=f.dataset.ytSrc;}else{if(v){v.pause();if(v._hls){v._hls.destroy();v._hls=null;}}if(f&&f.src)f.src='';}});cur=idx;}let sT;feed.addEventListener('scroll',()=>{clearTimeout(sT);sT=setTimeout(()=>{const rect=feed.getBoundingClientRect();const ctr=rect.top+rect.height/2;let best=-1,bestD=1e9;slides.forEach((sl,i)=>{const d=Math.abs(sl.getBoundingClientRect().top+sl.getBoundingClientRect().height/2-ctr);if(d<bestD){bestD=d;best=i;}});if(best>=0)activate(best);},150);});setTimeout(()=>activate(0),300);}
|
|
|
|
| 6 |
<title>VNEWS - Tin Tức Việt Nam</title>
|
| 7 |
<meta name="description" content="Tin tức tổng hợp, video short, highlight bóng đá, tường 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{color:#fff;font-size:18px;font-weight:800}.header p{color:rgba(255,255,255,.6);font-size:10px;margin-top:2px}.cats{display:flex;overflow-x:auto;background:#1a1a1a;border-bottom:1px solid #333;padding:0 4px;scrollbar-width:none;position:sticky;top:0;z-index:50}.cats::-webkit-scrollbar{display:none}.cat{padding:9px 11px;color:#888;font-size:11px;cursor:pointer;white-space:nowrap;border-bottom:2px solid transparent;flex-shrink:0}.cat.active{color:#5cb87a;border-bottom-color:#5cb87a;font-weight:600}.view{display:none}.view.active{display:block}.loading{text-align:center;padding:40px;color:#666;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-radius:8px;overflow:hidden;cursor:pointer;border:1px solid #222}.card:active{transform:scale(.98)}.card-img{position:relative;width:100%;aspect-ratio:16/9;background:#333;overflow:hidden}.card-img img{width:100%;height:100%;object-fit:cover}.card-play{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:30px;height:30px;background:rgba(0,0,0,.55);border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;font-size:11px}.card-body{padding:6px 8px}.card-title{font-size:11px;font-weight:600;color:#eee;line-height:1.35;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;color:#fff}.badge-bbc{background:#b80000;color:#fff}.badge-dt{background:#1565c0;color:#fff}.badge-genk{background:#6a1b9a;color:#fff}.badge-ai{background:#2d8659;color:#fff}.badge-fpt{background:#f26522;color:#fff}.slider-wrap{margin:6px 4px;background:#1a1a1a;border-radius:8px;overflow:hidden;border:1px solid #2a2a2a}.slider-header{padding:7px 10px;display:flex;align-items:center;justify-content:space-between}.slider-label{color:#f0c040;font-size:13px;font-weight:700}.slider-note{font-size:10px;color:#777}.slider-track{display:flex;overflow-x:auto;gap:8px;padding:4px 10px 10px;scrollbar-width:none}.slider-track::-webkit-scrollbar{display:none}.slider-item{flex:0 0 160px;cursor:pointer;flex-shrink:0}.slider-thumb{position:relative;width:100%;aspect-ratio:16/9;border-radius:6px;overflow:hidden;background:#333}.slider-thumb img{width:100%;height:100%;object-fit:cover}.slider-title{color:#ccc;font-size:10px;margin-top:3px;line-height:1.25;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.shorts-item{flex:0 0 110px!important}.shorts-thumb{aspect-ratio:3/4!important;border-radius:8px!important}.section-title{font-size:13px;font-weight:700;color:#5cb87a;margin:8px 0 4px;padding-left:8px;border-left:3px solid #5cb87a}.back-btn{background:rgba(17,17,17,.95);color:#fff;border:none;padding:10px;font-size:12px;cursor:pointer;width:100%;text-align:center;position:sticky;top:0;z-index:50}.article-view{padding:12px 8px 40px;max-width:760px;margin:0 auto}.article-title{font-size:18px;font-weight:800;color:#f0f0f0;line-height:1.32;margin-bottom:8px}.article-summary{background:#1a2a1f;border-left:3px solid #2d8659;padding:10px;margin-bottom:14px;font-weight:600;color:#ccc;font-size:13px;border-radius:0 6px 6px 0}.article-p{font-size:14px;line-height:1.72;color:#ccc;margin-bottom:10px}.article-img{width:100%;border-radius:6px;margin:10px 0}.article-h2{font-size:16px;font-weight:700;color:#eee;margin:16px 0 8px}.article-actions{display:flex;gap:8px;padding:10px 0;border-top:1px solid #333;margin-top:16px;flex-wrap:wrap}.article-actions button{background:#1a1a1a;border:1px solid #333;color:#ccc;padding:7px 12px;border-radius:14px;font-size:11px;cursor:pointer}.article-actions button.primary{background:#2d8659;border-color:#2d8659;color:#fff}.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-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;cursor:pointer}.wall-actions button.primary{background:#2d8659;border-color:#2d8659;color:#fff}.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-feed::-webkit-scrollbar{display:none}.tiktok-slide{height:80vh;max-height:680px;min-height:400px;scroll-snap-align:start;scroll-snap-stop:always;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));z-index:3}.tiktok-title{color:#fff;font-size:12px;font-weight:600;margin:3px 0 5px;line-height:1.3}.tiktok-counter{position:absolute;top:8px;left:8px;background:rgba(0,0,0,.5);color:#fff;font-size:9px;padding:2px 7px;border-radius:8px;z-index:4}.tiktok-right{position:absolute;right:8px;bottom:100px;display:flex;flex-direction:column;align-items:center;gap:14px;z-index:5}.tiktok-right-btn{display:flex;flex-direction:column;align-items:center;gap:2px;cursor:pointer;background:none;border:none;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}.ai-short{position:fixed;inset:0;background:#000;z-index:99999;display:none;color:#fff}.ai-short.active{display:block}.ai-bg{position:absolute;inset:-30px;background:center/cover no-repeat;filter:blur(24px);transform:scale(1.1);opacity:.38}.ai-phone{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);height:100dvh;max-height:900px;aspect-ratio:9/16;background:#050505;overflow:hidden;border-left:1px solid #222;border-right:1px solid #222}.ai-hero{position:absolute;inset:0;background:center/cover no-repeat;opacity:.6}.ai-grad{position:absolute;inset:0;background:linear-gradient(to bottom,rgba(0,0,0,.35),rgba(0,0,0,.15) 35%,rgba(0,0,0,.86))}.ai-brand{position:absolute;top:18px;left:16px;font-size:12px;font-weight:900;color:#6ee78f;text-shadow:0 2px 8px #000}.ai-topic{position:absolute;top:42px;left:16px;font-size:10px;color:#ddd;background:rgba(0,0,0,.45);padding:3px 8px;border-radius:10px}.ai-caption{position:absolute;left:18px;right:18px;bottom:108px;font-size:20px;line-height:1.25;font-weight:900;text-shadow:0 3px 12px #000}.ai-title{position:absolute;left:18px;right:18px;bottom:42px;font-size:13px;line-height:1.35;color:#eee;text-shadow:0 2px 8px #000;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.ai-progress{position:absolute;left:0;bottom:0;height:4px;background:#2d8659;width:0%;transition:width .3s}.ai-close{position:fixed;top:max(12px,env(safe-area-inset-top));right:max(12px,env(safe-area-inset-right));z-index:4;width:40px;height:40px;border-radius:50%;border:1px solid rgba(255,255,255,.2);background:rgba(0,0,0,.55);color:#fff;font-size:24px}.ai-controls{position:fixed;right:12px;bottom:max(18px,env(safe-area-inset-bottom));z-index:4;display:flex;flex-direction:column;gap:8px}.ai-controls button{width:44px;height:44px;border-radius:50%;border:0;background:rgba(255,255,255,.15);color:#fff;font-size:18px}.ai-note{position:fixed;left:12px;right:70px;bottom:max(18px,env(safe-area-inset-bottom));z-index:4;font-size:11px;color:#ddd;text-shadow:0 1px 6px #000}.ms-lock{overflow:hidden!important}
|
| 14 |
</style>
|
| 15 |
</head>
|
| 16 |
<body>
|
|
|
|
| 21 |
<div id="view-video" class="view"></div>
|
| 22 |
<div id="view-tiktok" class="view"></div>
|
| 23 |
<div id="view-article" class="view"></div>
|
| 24 |
+
<div class="ai-short" id="ai-short"><div class="ai-bg" id="ai-bg"></div><div class="ai-phone"><div class="ai-hero" id="ai-hero"></div><div class="ai-grad"></div><div class="ai-brand">VNEWS AI SHORT</div><div class="ai-topic" id="ai-topic">Tin tức</div><div class="ai-caption" id="ai-caption"></div><div class="ai-title" id="ai-title"></div><div class="ai-progress" id="ai-progress"></div></div><button class="ai-close" onclick="closeAiShort()">×</button><div class="ai-controls"><button onclick="replayAiShort()">↻</button><button onclick="toggleAiVoice()" id="ai-voice-btn">🔊</button></div><div class="ai-note">Short AI dùng giọng đọc tiếng Việt của trình duyệt.</div></div>
|
| 25 |
<script>
|
| 26 |
const SPACE=location.origin;let _cats=[],_tikData=[],_wallPosts=[],_currentAiPost=null,_aiMuted=false,_aiTimer=null,_aiStep=0;
|
|
|
|
|
|
|
| 27 |
function escapeHtml(s){return String(s||'').replace(/[&<>"']/g,m=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[m]));}
|
|
|
|
| 28 |
function doShareVideo(title,videoUrl,img,type){const shareUrl=SPACE+'/v?url='+encodeURIComponent(videoUrl)+'&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 video!')).catch(()=>{});}
|
| 29 |
function doShare(title,articleUrl,img){const shareUrl=SPACE+'/s?url='+encodeURIComponent(articleUrl)+'&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 link!')).catch(()=>{});}
|
| 30 |
+
function fetchJsonTimeout(url,ms=8000){const c=new AbortController();const t=setTimeout(()=>c.abort(),ms);return fetch(url,{signal:c.signal}).then(r=>r.json()).finally(()=>clearTimeout(t));}
|
| 31 |
+
async function init(){_cats=await fetchJsonTimeout('/api/categories',5000).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 loadHomeFast();const pendingVideo=localStorage.getItem('pending_video');if(pendingVideo){localStorage.removeItem('pending_video');try{const pv=JSON.parse(pendingVideo);if(pv.url)openTikTokByUrl(pv.url,pv.type||'highlights');}catch(e){}}const pending=localStorage.getItem('pending_article');if(pending){localStorage.removeItem('pending_article');readArticle(pending);}}
|
| 32 |
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=>{try{v.pause()}catch(e){}});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);}}
|
| 33 |
function showView(id){document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.getElementById(id).classList.add('active');}
|
| 34 |
+
async function loadHomeFast(){const home=document.getElementById('view-home');home.innerHTML='<div id="home-fast"></div><div id="home-lazy"></div><div class="loading" id="home-loadnote">Đang tải tin chính...</div>';fetchJsonTimeout('/api/homepage',9000).then(news=>renderNews(news||[])).catch(()=>{document.getElementById('home-loadnote').textContent='Không tải được tin chính';});setTimeout(loadLazySections,80);}
|
| 35 |
+
function renderNews(news){const note=document.getElementById('home-loadnote');if(note)note.remove();let h='';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 loading="lazy" 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('home-fast').innerHTML=h||'<div class="loading">Không có dữ liệu</div>';}
|
| 36 |
+
async function loadLazySections(){const lazy=document.getElementById('home-lazy');let h='';try{let wall=await fetchJsonTimeout('/api/wall',5000);_wallPosts=(wall&&wall.posts)||[];if(_wallPosts.length)h+=renderWallSlide(_wallPosts);}catch(e){}lazy.innerHTML=h;Promise.allSettled([fetchJsonTimeout('/api/dantri_hot',7000),fetchJsonTimeout('/api/shorts',9000),fetchJsonTimeout('/api/vne_video',7000),fetchJsonTimeout('/api/highlights',9000)]).then(res=>{let dantri=res[0].value||[],shorts=res[1].value||[],vneVid=res[2].value||[],hl=res[3].value||[];let out=lazy.innerHTML||'';if(dantri.length){out+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">🔥 Tin Nổi Bật</span></div><div class="slider-track">';dantri.forEach(a=>{out+=`<div class="slider-item" onclick="readArticle('${a.link.replace(/'/g,"\\'")}','dantri')"><div class="slider-thumb">${a.img?`<img loading="lazy" src="${a.img}">`:''}</div><div class="slider-title">${a.title}</div></div>`;});out+='</div></div>';}let all=[...shorts,...vneVid];if(all.length){out+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">📱 Video · Shorts</span></div><div class="slider-track">';all.forEach((a,i)=>{if(a.source==='vne-video'){out+=`<div class="slider-item" onclick="window.open('${a.link}','_blank')"><div class="slider-thumb">${a.img?`<img loading="lazy" src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`;}else{out+=`<div class="slider-item shorts-item" onclick="openTikTok('shorts',${i})"><div class="slider-thumb shorts-thumb">${a.img?`<img loading="lazy" src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`;}});out+='</div></div>';}if(hl.length){out+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">🎬 Highlight</span></div><div class="slider-track">';hl.slice(0,20).forEach((a,i)=>{out+=`<div class="slider-item" onclick="openTikTok('highlights',${i})"><div class="slider-thumb">${a.img?`<img loading="lazy" src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`;});out+='</div></div>';}lazy.innerHTML=out;});}
|
| 37 |
+
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">Bài viết AI viết lại</span></div><div class="slider-track">';posts.slice(0,30).forEach(p=>{h+=`<div class="wall-item"><div class="wall-thumb">${p.img?`<img loading="lazy" src="${p.img}">`:''}</div><div class="wall-title">${escapeHtml(p.title)}</div><div class="wall-text">${escapeHtml(p.text)}</div><div class="wall-actions"><button class="primary" onclick="openAiShort('${p.id}')">🎬 Tạo short AI</button><button onclick="readArticle('${(p.url||'').replace(/'/g,"\\'")}')">Đọc</button></div></div>`;});h+='</div></div>';return h;}
|
| 38 |
+
async function loadCat(id){const el=document.getElementById('view-cat');el.innerHTML='<div class="loading">Đang tải...</div>';const arts=await fetchJsonTimeout('/api/category/'+id,9000).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 loading="lazy" 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;}
|
| 39 |
+
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 fetchJsonTimeout('/api/article?url='+encodeURIComponent(url),12000).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 loading="lazy" 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 class="primary" onclick="rewriteAndShare('${url.replace(/'/g,"\\'")}')">🤖 AI viết lại & đăng tường</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>`;el.innerHTML=h;window.scrollTo(0,0);}
|
| 40 |
+
function rewriteAndShare(url){if(!confirm('Dùng AI viết lại bài này và đăng lên Tường AI?'))return;fetch('/api/rewrite_share',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url})}).then(r=>r.json()).then(j=>{if(j&&j.post){alert('Đã đăng lên Tường AI');switchCat('home');setTimeout(loadHomeFast,600);}else alert(j.error||'Không tạo được bài AI');}).catch(()=>alert('Lỗi tạo bài AI'));}
|
|
|
|
|
|
|
|
|
|
| 41 |
function inferTopic(post){let t=((post.title||'')+' '+(post.text||'')).toLowerCase();if(/bóng đá|world cup|trận|đội tuyển|ngoại hạng|champions/.test(t))return 'Thể thao';if(/ai|trí tuệ|công nghệ|robot|iphone|app|mạng/.test(t))return 'Công nghệ';if(/sức khỏe|bệnh|bác sĩ|thuốc|y tế/.test(t))return 'Sức khỏe';if(/kinh tế|doanh nghiệp|giá|thị trường|tỷ phú/.test(t))return 'Kinh tế';if(/thế giới|mỹ|nga|trung quốc|châu âu/.test(t))return 'Thế giới';return 'Tin nóng';}
|
| 42 |
function buildShortScript(post){let txt=(post.text||post.title||'').replace(/Bản tin AI viết lại:/i,'').replace(/Điểm chính:/i,'').replace(/[•\n]+/g,'. ');let parts=txt.split(/[.!?]+/).map(x=>x.trim()).filter(x=>x.length>25).slice(0,7);if(!parts.length)parts=[post.title||'Bản tin mới trên VNEWS'];return parts.map((p,i)=>i===0?'Tin đáng chú ý: '+p:p);}
|
| 43 |
function openAiShort(id){let post=_wallPosts.find(p=>p.id===id);if(!post)return;_currentAiPost=post;document.documentElement.classList.add('ms-lock');document.body.classList.add('ms-lock');document.getElementById('ai-title').textContent=post.title||'';document.getElementById('ai-topic').textContent=inferTopic(post);let img=post.img||'https://s1.vnecdn.net/vnexpress/restruct/i/v9505/logo_default.jpg';document.getElementById('ai-bg').style.backgroundImage=`url('${img}')`;document.getElementById('ai-hero').style.backgroundImage=`url('${img}')`;document.getElementById('ai-short').classList.add('active');startAiShort();}
|
|
|
|
| 46 |
function pickViVoice(){let vs=(speechSynthesis.getVoices&&speechSynthesis.getVoices())||[];return vs.find(v=>/vi|Vietnam/i.test(v.lang+' '+v.name))||vs.find(v=>/Google|Microsoft|Natural/i.test(v.name))||vs[0]||null;}
|
| 47 |
function speakVi(text,cb){if(_aiMuted||!window.speechSynthesis){_aiTimer=setTimeout(cb,3200);return;}speechSynthesis.cancel();let u=new SpeechSynthesisUtterance(text);u.lang='vi-VN';u.rate=1.02;u.pitch=1.02;let v=pickViVoice();if(v)u.voice=v;u.onend=()=>cb&&cb();u.onerror=()=>{_aiTimer=setTimeout(cb,2600)};speechSynthesis.speak(u);}
|
| 48 |
function startAiShort(){stopAiVoice();let post=_currentAiPost;if(!post)return;let lines=buildShortScript(post);_aiStep=0;function next(){if(!document.getElementById('ai-short').classList.contains('active'))return;let line=lines[_aiStep%lines.length];document.getElementById('ai-caption').textContent=line;document.getElementById('ai-progress').style.width=Math.round(((_aiStep+1)/lines.length)*100)+'%';speakVi(line,()=>{_aiStep++;if(_aiStep<lines.length)_aiTimer=setTimeout(next,350);else _aiTimer=setTimeout(()=>{document.getElementById('ai-progress').style.width='0%';_aiStep=0;next();},1800);});}next();}
|
| 49 |
+
function replayAiShort(){startAiShort();}function toggleAiVoice(){_aiMuted=!_aiMuted;document.getElementById('ai-voice-btn').textContent=_aiMuted?'🔇':'🔊';if(_aiMuted&&speechSynthesis)speechSynthesis.cancel();else startAiShort();}
|
| 50 |
+
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([fetchJsonTimeout('/api/highlights',9000).catch(()=>[]),fetchJsonTimeout('/api/bdp_videos',9000).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 loading="lazy" 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 loading="lazy" src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge badge-fpt">BDP</span><div class="card-title">${a.title}</div></div></div>`;});h+='</div>';}el.innerHTML=h;el.dataset.loaded='1';}
|
| 51 |
+
async function openTikTokByUrl(targetUrl,type){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 fetchJsonTimeout('/api/shorts',9000).catch(()=>[]);else if(type==='highlights')articles=await fetchJsonTimeout('/api/highlights',9000).catch(()=>[]);else articles=await fetchJsonTimeout('/api/bdp_videos',9000).catch(()=>[]);let startIdx=0;for(let i=0;i<articles.length;i++){if(articles[i].link===targetUrl){startIdx=i;break;}}await buildTikTokPlayer(articles,startIdx,type);}
|
| 52 |
+
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 fetchJsonTimeout('/api/shorts',9000).catch(()=>[]);else if(type==='highlights')articles=await fetchJsonTimeout('/api/highlights',9000).catch(()=>[]);else articles=await fetchJsonTimeout('/api/bdp_videos',9000).catch(()=>[]);await buildTikTokPlayer(articles,startIdx,type);}
|
|
|
|
| 53 |
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();}
|
| 54 |
function shareVid(i){const v=_tikData[i];if(!v)return;doShareVideo(v.title,v.link||'',v.poster||v.img||'','highlights');}
|
| 55 |
function initFeed(){const feed=document.getElementById('tiktok-feed');if(!feed)return;const slides=feed.querySelectorAll('.tiktok-slide');let cur=-1;function activate(idx){if(idx===cur)return;slides.forEach((sl,i)=>{const v=sl.querySelector('video');const f=sl.querySelector('iframe');if(i===idx){if(v&&v.dataset.hls){if(!v._hls){const hls=new Hls();hls.loadSource(v.dataset.hls);hls.attachMedia(v);hls.on(Hls.Events.MANIFEST_PARSED,()=>v.play().catch(()=>{}));v._hls=hls;}else v.play().catch(()=>{});}else if(v)v.play().catch(()=>{});if(f&&!f.src&&f.dataset.ytSrc)f.src=f.dataset.ytSrc;}else{if(v){v.pause();if(v._hls){v._hls.destroy();v._hls=null;}}if(f&&f.src)f.src='';}});cur=idx;}let sT;feed.addEventListener('scroll',()=>{clearTimeout(sT);sT=setTimeout(()=>{const rect=feed.getBoundingClientRect();const ctr=rect.top+rect.height/2;let best=-1,bestD=1e9;slides.forEach((sl,i)=>{const d=Math.abs(sl.getBoundingClientRect().top+sl.getBoundingClientRect().height/2-ctr);if(d<bestD){bestD=d;best=i;}});if(best>=0)activate(best);},150);});setTimeout(()=>activate(0),300);}
|