Spaces:
Running
Running
fix: closeAllCmtPanels in video click handler (1 line fix)
Browse files- static/index.html +13 -135
static/index.html
CHANGED
|
@@ -11,52 +11,7 @@
|
|
| 11 |
<link rel="canonical" href="https://bep40-vnews.hf.space">
|
| 12 |
<script src="https://cdn.jsdelivr.net/npm/hls.js@1/dist/hls.min.js"></script>
|
| 13 |
<style>
|
| 14 |
-
*{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}
|
| 15 |
-
.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}
|
| 16 |
-
.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}
|
| 17 |
-
.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}
|
| 18 |
-
.view{display:none}.view.active{display:block}
|
| 19 |
-
.grid{display:grid;grid-template-columns:repeat(2,1fr);gap:6px;padding:6px 4px}@media(min-width:600px){.grid{grid-template-columns:repeat(3,1fr)}}
|
| 20 |
-
.card{background:#1a1a1a;border-radius:8px;overflow:hidden;cursor:pointer;border:1px solid #222}.card:active{transform:scale(.97)}
|
| 21 |
-
.card-img{position:relative;width:100%;aspect-ratio:16/9;background:#333;overflow:hidden}.card-img img{width:100%;height:100%;object-fit:cover}
|
| 22 |
-
.card-play{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:28px;height:28px;background:rgba(0,0,0,.5);border-radius:50%;color:#fff;display:flex;align-items:center;justify-content:center;font-size:11px}
|
| 23 |
-
.card-body{padding:6px 8px}.card-title{font-size:11px;font-weight:600;color:#eee;line-height:1.3;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
| 24 |
-
.card-meta{display:flex;gap:8px;margin-top:3px;font-size:9px;color:#666}
|
| 25 |
-
.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-bdp{background:#1a5c35;color:#fff}.badge-24h{background:#e67e22;color:#fff}.badge-bbc{background:#b80000;color:#fff}
|
| 26 |
-
.slider-wrap{margin:6px 4px;background:#1a1a1a;border-radius:8px;overflow:hidden;border:1px solid #2a2a2a}.slider-header{padding:7px 10px}.slider-label{color:#f0c040;font-size:13px;font-weight:700}
|
| 27 |
-
.slider-track{display:flex;overflow-x:auto;gap:8px;padding:4px 10px 10px;scrollbar-width:none}.slider-track::-webkit-scrollbar{display:none}
|
| 28 |
-
.slider-item{flex:0 0 160px;scroll-snap-align:start;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}
|
| 29 |
-
.slider-title{color:#ccc;font-size:10px;margin-top:3px;line-height:1.2;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
| 30 |
-
.shorts-item{flex:0 0 110px!important}.shorts-thumb{aspect-ratio:3/4!important;border-radius:8px!important}
|
| 31 |
-
.tiktok-container{width:100%;height:80vh;max-height:680px;min-height:400px;background:#000}
|
| 32 |
-
.tiktok-feed{height:100%;overflow-y:scroll;scroll-snap-type:y mandatory;scrollbar-width:none}.tiktok-feed::-webkit-scrollbar{display:none}
|
| 33 |
-
.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}
|
| 34 |
-
.tiktok-slide video{width:100%;height:100%;object-fit:cover}.tiktok-slide.contain-mode video{object-fit:contain}
|
| 35 |
-
.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}
|
| 36 |
-
.tiktok-title{color:#fff;font-size:12px;font-weight:600;margin:3px 0 5px;line-height:1.3}
|
| 37 |
-
.tiktok-seek{display:flex;gap:8px;margin-top:4px}.tiktok-seek button{background:rgba(255,255,255,.12);color:#fff;border:none;padding:4px 10px;border-radius:10px;font-size:10px;cursor:pointer}
|
| 38 |
-
.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}
|
| 39 |
-
.tiktok-unmute{position:absolute;top:8px;right:8px;background:rgba(0,0,0,.5);color:#fff;font-size:10px;padding:4px 8px;border-radius:10px;cursor:pointer;z-index:4}
|
| 40 |
-
.tiktok-right{position:absolute;right:8px;bottom:100px;display:flex;flex-direction:column;align-items:center;gap:14px;z-index:5}
|
| 41 |
-
.tiktok-right-btn{display:flex;flex-direction:column;align-items:center;gap:2px;cursor:pointer;background:none;border:none;color:#fff}
|
| 42 |
-
.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}
|
| 43 |
-
.tiktok-right-btn .count{font-size:10px;color:#ddd}
|
| 44 |
-
.cmt-panel{position:absolute;bottom:0;left:0;right:0;height:60%;background:#1a1a1a;z-index:30;transform:translateY(100%);transition:transform .3s;border-radius:14px 14px 0 0;padding:12px;overflow-y:auto}
|
| 45 |
-
.cmt-panel.open{transform:translateY(0)}
|
| 46 |
-
.cmt-panel-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}.cmt-panel-header h4{color:#fff;font-size:14px}.cmt-panel-close{background:none;border:none;color:#aaa;font-size:20px;cursor:pointer}
|
| 47 |
-
.cmt-panel .cmt-item{background:#222;border-radius:6px;padding:7px;margin-bottom:5px}.cmt-panel .cmt-item b{color:#5cb87a;font-size:11px}.cmt-panel .cmt-item p{color:#ccc;font-size:12px;margin-top:2px}.cmt-panel .cmt-item small{color:#555;font-size:9px}
|
| 48 |
-
.cmt-panel .cmt-form{display:flex;gap:5px;margin-top:8px;position:sticky;bottom:0;background:#1a1a1a;padding:6px 0}.cmt-panel .cmt-form input{flex:1;padding:8px;background:#222;border:1px solid #444;border-radius:8px;color:#eee;font-size:12px}.cmt-panel .cmt-form button{background:#2d8659;color:#fff;border:none;padding:8px 14px;border-radius:8px;font-size:12px;cursor:pointer}
|
| 49 |
-
.loading{text-align:center;padding:40px;color:#666;font-size:12px}.topbar{display:flex;justify-content:space-between;padding:6px 8px;color:#555;font-size:10px}
|
| 50 |
-
.section-title{font-size:13px;font-weight:700;color:#5cb87a;margin:8px 0 4px;padding-left:8px;border-left:3px solid #5cb87a}
|
| 51 |
-
.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}
|
| 52 |
-
a.card-link{text-decoration:none;color:inherit}
|
| 53 |
-
.article-view{padding:12px 8px 40px;max-width:700px;margin:0 auto}.article-title{font-size:18px;font-weight:800;color:#f0f0f0;line-height:1.3;margin-bottom:8px}
|
| 54 |
-
.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}
|
| 55 |
-
.article-p{font-size:14px;line-height:1.7;color:#ccc;margin-bottom:10px}.article-img{width:100%;border-radius:6px;margin:10px 0}.article-h2{font-size:16px;font-weight:700;color:#eee;margin:16px 0 8px}
|
| 56 |
-
.article-actions{display:flex;gap:10px;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:6px 12px;border-radius:14px;font-size:11px;cursor:pointer}
|
| 57 |
-
.cmt-section{margin-top:14px;border-top:1px solid #333;padding-top:10px}.cmt-section h3{font-size:13px;color:#eee;margin-bottom:6px}
|
| 58 |
-
.cmt-item{background:#1a1a1a;border-radius:6px;padding:7px;margin-bottom:5px}.cmt-item b{color:#5cb87a;font-size:11px}.cmt-item p{color:#ccc;font-size:12px;margin-top:2px}.cmt-item small{color:#555;font-size:9px}
|
| 59 |
-
.cmt-form{display:flex;gap:5px;margin-top:6px;flex-wrap:wrap}.cmt-form input{flex:1;min-width:80px;padding:6px;background:#1a1a1a;border:1px solid #333;border-radius:6px;color:#eee;font-size:11px}.cmt-form button{background:#2d8659;color:#fff;border:none;padding:6px 12px;border-radius:6px;font-size:11px;cursor:pointer}
|
| 60 |
</style>
|
| 61 |
</head>
|
| 62 |
<body>
|
|
@@ -77,20 +32,8 @@ function getCmts(id){return LS.get('c_'+id)||[]}
|
|
| 77 |
function addCmt(id,n,t){let c=getCmts(id);c.push({n,t,d:new Date().toLocaleString('vi-VN')});LS.set('c_'+id,c);return c;}
|
| 78 |
function incS(id){let v=(LS.get('s_'+id)||0)+1;LS.set('s_'+id,v);return v;}
|
| 79 |
function getS(id){return LS.get('s_'+id)||0}
|
| 80 |
-
function doShare(title,articleUrl,img){
|
| 81 |
-
|
| 82 |
-
const aid=hid(articleUrl||title);incS(aid);
|
| 83 |
-
if(navigator.share)navigator.share({title,url:shareUrl}).catch(()=>{});
|
| 84 |
-
else navigator.clipboard.writeText(shareUrl).then(()=>alert('Đã sao chép!')).catch(()=>{});
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
// ★ FIX: Click anywhere outside .cmt-panel closes it
|
| 88 |
-
document.addEventListener('click',function(e){
|
| 89 |
-
if(!e.target.closest('.cmt-panel')&&!e.target.closest('.tiktok-right-btn')){
|
| 90 |
-
document.querySelectorAll('.cmt-panel.open').forEach(p=>p.classList.remove('open'));
|
| 91 |
-
}
|
| 92 |
-
});
|
| 93 |
-
|
| 94 |
async function init(){
|
| 95 |
_cats=await fetch('/api/categories').then(r=>r.json());
|
| 96 |
let bar='<div class="cat active" data-cat="home">🏠</div><div class="cat" data-cat="video">🎬 Video</div>';
|
|
@@ -98,103 +41,38 @@ async function init(){
|
|
| 98 |
document.getElementById('cat-bar').innerHTML=bar;
|
| 99 |
document.querySelectorAll('.cat').forEach(t=>{t.onclick=()=>switchCat(t.dataset.cat);});
|
| 100 |
await loadHome();
|
| 101 |
-
// ★ FIX: Read ?open= query param (from /s share redirect) instead of localStorage
|
| 102 |
const params=new URLSearchParams(location.search);
|
| 103 |
const openUrl=params.get('open');
|
| 104 |
-
if(openUrl){
|
| 105 |
-
// Clean URL so user doesn't see ?open= in address bar
|
| 106 |
-
history.replaceState(null,'',location.pathname);
|
| 107 |
-
readArticle(openUrl,'vne');
|
| 108 |
-
}
|
| 109 |
}
|
| 110 |
function switchCat(id){document.querySelectorAll('.cat').forEach(x=>x.classList.remove('active'));document.querySelector(`[data-cat="${id}"]`)?.classList.add('active');document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.querySelectorAll('video').forEach(v=>v.pause());if(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);}}
|
| 111 |
function showView(id){document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.getElementById(id).classList.add('active');}
|
| 112 |
-
|
| 113 |
-
async function loadHome(){
|
| 114 |
-
const[news,hl,sh]=await Promise.all([fetch('/api/homepage').then(r=>r.json()),fetch('/api/highlights').then(r=>r.json()),fetch('/api/shorts').then(r=>r.json())]);
|
| 115 |
-
let h='';
|
| 116 |
-
if(sh&&sh.length){h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">📱 Shorts 24h</span></div><div class="slider-track">';sh.forEach((a,i)=>{h+=`<div class="slider-item shorts-item" onclick="openTikTok('shorts','${a.link}')"><div class="slider-thumb shorts-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`;});h+='</div></div>';}
|
| 117 |
-
if(hl&&hl.length){h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">🎬 Highlight</span></div><div class="slider-track">';hl.forEach((a,i)=>{h+=`<div class="slider-item" onclick="openTikTok('highlights','${a.link}')"><div class="slider-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`;});h+='</div></div>';}
|
| 118 |
-
const groups={};news.forEach(a=>{if(!groups[a.group])groups[a.group]=[];groups[a.group].push(a);});
|
| 119 |
-
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==='bdp'?'badge-bdp':'badge-vne';const lb=a.source==='bbc'?'BBC':a.source==='bdp'?'BDP':'VnE';const aid=hid(a.link);h+=`<div class="card" onclick="readArticle('${a.link.replace(/'/g,"\\'")}','${a.source}')"><div class="card-img">${a.img?`<img src="${a.img}">`:''}</div><div class="card-body"><span class="badge ${bg}">${lb}</span><div class="card-title">${a.title}</div><div class="card-meta"><span>👁${getV(aid)}</span><span>💬${getCmts(aid).length}</span></div></div></div>`;});h+='</div>';}
|
| 120 |
-
document.getElementById('view-home').innerHTML=h;
|
| 121 |
-
}
|
| 122 |
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());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==='bdp'?'badge-bdp':'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;}
|
| 123 |
-
|
| 124 |
-
// ★ FIX: readArticle always opens in VNEWS reader. Never window.open externally.
|
| 125 |
-
async function readArticle(url,source){
|
| 126 |
-
showView('view-article');const el=document.getElementById('view-article');el.innerHTML='<div class="loading">Đang tải...</div>';
|
| 127 |
-
const aid=hid(url);incV(aid);
|
| 128 |
-
const data=await fetch('/api/article?url='+encodeURIComponent(url)).then(r=>r.json());
|
| 129 |
-
if(!data||data.error){
|
| 130 |
-
// API doesn't support this source → show article link inside VNEWS (not external redirect)
|
| 131 |
-
el.innerHTML=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view" style="text-align:center;padding:60px 20px"><p style="color:#aaa;margin-bottom:12px">Bài viết này chưa hỗ trợ đọc trực tiếp</p><a href="${url}" target="_blank" style="color:#5cb87a;font-size:14px;text-decoration:underline">📰 Mở bài viết gốc</a></div>`;
|
| 132 |
-
return;
|
| 133 |
-
}
|
| 134 |
-
const ogImg=data.og_image||'';
|
| 135 |
-
let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view"><h1 class="article-title">${data.title}</h1>`;
|
| 136 |
-
if(data.summary)h+=`<div class="article-summary">${data.summary}</div>`;
|
| 137 |
-
data.body.forEach(b=>{if(b.type==='p')h+=`<p class="article-p">${b.text}</p>`;else if(b.type==='img')h+=`<img class="article-img" src="${b.src}">`;else if(b.type==='heading')h+=`<h2 class="article-h2">${b.text}</h2>`;});
|
| 138 |
-
h+=`<div class="article-actions"><button onclick="doShare('${data.title.replace(/'/g,"\\'")}','${url.replace(/'/g,"\\'")}','${ogImg.replace(/'/g,"\\'")}')">📤 Chia sẻ (${getS(aid)})</button><button>👁 ${getV(aid)}</button><button>💬 ${getCmts(aid).length}</button></div>`;
|
| 139 |
-
h+=renderCmtSection(aid);h+='</div>';el.innerHTML=h;window.scrollTo(0,0);
|
| 140 |
-
}
|
| 141 |
function renderCmtSection(aid){const cmts=getCmts(aid);let h=`<div class="cmt-section"><h3>💬 Bình luận (${cmts.length})</h3><div id="cl-${aid}">`;cmts.slice().reverse().forEach(c=>{h+=`<div class="cmt-item"><b>${c.n}</b> <small>${c.d}</small><p>${c.t}</p></div>`;});if(!cmts.length)h+='<p style="color:#666;font-size:11px">Chưa có bình luận</p>';h+=`</div><div class="cmt-form"><input id="cn-${aid}" placeholder="Tên"><input id="ct-${aid}" placeholder="Bình luận..."><button onclick="submitCmt('${aid}')">Gửi</button></div></div>`;return h;}
|
| 142 |
function submitCmt(aid){const n=document.getElementById('cn-'+aid),t=document.getElementById('ct-'+aid);if(!n.value.trim()||!t.value.trim())return;addCmt(aid,n.value.trim(),t.value.trim());t.value='';const cmts=getCmts(aid);let h='';cmts.slice().reverse().forEach(c=>{h+=`<div class="cmt-item"><b>${c.n}</b> <small>${c.d}</small><p>${c.t}</p></div>`;});document.getElementById('cl-'+aid).innerHTML=h;}
|
| 143 |
-
|
| 144 |
async function loadVideos(){const el=document.getElementById('view-video');if(el.dataset.loaded)return;el.innerHTML='<div class="loading">Đang tải...</div>';const[hl,bdp]=await Promise.all([fetch('/api/highlights').then(r=>r.json()),fetch('/api/bdp_videos').then(r=>r.json())]);let h='<div class="section-title">🎬 Highlight</div><div class="grid">';hl.forEach((a,i)=>{h+=`<div class="card" onclick="openTikTok('highlights','${a.link}')"><div class="card-img">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge badge-24h">24h</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','${a.link}')"><div class="card-img">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge badge-bdp">BDP</span><div class="card-title">${a.title}</div></div></div>`;});h+='</div>';}el.innerHTML=h;el.dataset.loaded='1';}
|
| 145 |
-
|
| 146 |
-
async function openTikTok(type, targetLink){
|
| 147 |
-
showView('view-tiktok');document.querySelectorAll('.cat').forEach(x=>x.classList.remove('active'));
|
| 148 |
-
const el=document.getElementById('view-tiktok');el.innerHTML='<div class="loading">Đang tải video...</div>';
|
| 149 |
-
let articles;if(type==='shorts')articles=await fetch('/api/shorts').then(r=>r.json());else if(type==='highlights')articles=await fetch('/api/highlights').then(r=>r.json());else articles=await fetch('/api/bdp_videos').then(r=>r.json());
|
| 150 |
-
const vids=[];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){if(v.all_parts&&v.all_parts.length>1){v.all_parts.forEach((p,pi)=>{vids.push({...a,src:p,poster:v.poster,_idx:i,_part:pi,title:a.title+` (P${pi+1})`});});}else{vids.push({...a,...v,_idx:i,_part:0});}}}catch(e){}}));
|
| 151 |
-
vids.sort((a,b)=>a._idx-b._idx||a._part-b._part);
|
| 152 |
-
if(!vids.length){el.innerHTML='<div class="loading">Không tìm thấy video</div>';return;}
|
| 153 |
-
const ti=vids.findIndex(v=>v.link===targetLink);
|
| 154 |
-
const ordered=ti>0?[...vids.slice(ti),...vids.slice(0,ti)]:vids;
|
| 155 |
-
_tikData=ordered;
|
| 156 |
-
let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="tiktok-container"><div class="tiktok-feed" id="tiktok-feed">`;
|
| 157 |
-
ordered.forEach((v,i)=>{
|
| 158 |
-
const aid=hid(v.link||v.title);const isHLS=v.src.includes('.m3u8');const poster=v.poster?` poster="${v.poster}"`:'';
|
| 159 |
-
const vtag=isHLS?`<video playsinline preload="metadata"${poster} data-hls="${v.src}" muted loop></video>`:`<video playsinline preload="metadata"${poster} muted loop><source src="${v.src}" type="video/mp4"></video>`;
|
| 160 |
-
const bg=v.source==='bdp'?'badge-bdp':'badge-24h';const lb=v.source==='bdp'?'BDP':'24h';
|
| 161 |
-
h+=`<div class="tiktok-slide" id="tslide-${i}" data-aid="${aid}" data-link="${(v.link||'').replace(/"/g,'')}" data-img="${(v.poster||v.img||'').replace(/"/g,'')}">
|
| 162 |
${vtag}
|
| 163 |
-
<div class="tiktok-bottom"><span class="badge ${bg}">${lb}</span><p class="tiktok-title">${v.title}</p>
|
| 164 |
-
<div class="tiktok-
|
| 165 |
-
<div class="tiktok-
|
| 166 |
-
<button class="tiktok-right-btn"><div class="icon">👁</div><div class="count" id="vc-${i}">${getV(aid)}</div></button>
|
| 167 |
-
<button class="tiktok-right-btn" onclick="event.stopPropagation();toggleCmtPanel(${i})"><div class="icon">💬</div><div class="count" id="cc-${i}">${getCmts(aid).length}</div></button>
|
| 168 |
-
<button class="tiktok-right-btn" onclick="event.stopPropagation();shareVid(${i})"><div class="icon">📤</div><div class="count" id="sc-${i}">${getS(aid)}</div></button>
|
| 169 |
-
</div>
|
| 170 |
-
<div class="tiktok-unmute" onclick="toggleMute()">🔇</div>
|
| 171 |
-
<span class="tiktok-counter">${i+1}/${ordered.length}</span>
|
| 172 |
<div class="cmt-panel" id="cpanel-${i}"><div class="cmt-panel-header"><h4>💬 Bình luận</h4><button class="cmt-panel-close" onclick="toggleCmtPanel(${i})">✕</button></div><div id="vcl-${i}"></div><div class="cmt-form"><input id="vcn-${i}" placeholder="Tên"><input id="vct-${i}" placeholder="Bình luận..."><button onclick="submitVCmt(${i},'${aid}')">Gửi</button></div></div>
|
| 173 |
-
</div>`;
|
| 174 |
-
});
|
| 175 |
-
h+='</div></div>';
|
| 176 |
-
h+=`<div class="topbar"><span>📋 Danh sách (${ordered.length})</span></div><div class="grid">`;
|
| 177 |
-
ordered.forEach((v,i)=>{const bg=v.source==='bdp'?'badge-bdp':'badge-24h';h+=`<a href="#tslide-${i}" class="card-link"><div class="card"><div class="card-img">${(v.img||v.poster)?`<img src="${v.img||v.poster}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge ${bg}">${v.source==='bdp'?'BDP':'24h'}</span><div class="card-title">${v.title}</div></div></div></a>`;});
|
| 178 |
-
h+='</div>';el.innerHTML=h;initFeed();
|
| 179 |
-
ordered.forEach((v,i)=>{renderVCmts(i,hid(v.link||v.title));});
|
| 180 |
-
}
|
| 181 |
function shareVid(i){const v=_tikData[i];if(!v)return;doShare(v.title,v.link||'',v.poster||v.img||'');const aid=hid(v.link||v.title);document.getElementById('sc-'+i).textContent=getS(aid);}
|
| 182 |
function toggleCmtPanel(i){const p=document.getElementById('cpanel-'+i);p.classList.toggle('open');}
|
| 183 |
function closeAllCmtPanels(){document.querySelectorAll('.cmt-panel.open').forEach(p=>p.classList.remove('open'));}
|
| 184 |
function renderVCmts(i,aid){const el=document.getElementById('vcl-'+i);if(!el)return;const cmts=getCmts(aid);let h='';cmts.slice().reverse().forEach(c=>{h+=`<div class="cmt-item"><b>${c.n}</b> <small>${c.d}</small><p>${c.t}</p></div>`;});if(!cmts.length)h='<p style="color:#666;font-size:11px">Chưa có bình luận</p>';el.innerHTML=h;}
|
| 185 |
function submitVCmt(i,aid){const n=document.getElementById('vcn-'+i),t=document.getElementById('vct-'+i);if(!n.value.trim()||!t.value.trim())return;addCmt(aid,n.value.trim(),t.value.trim());t.value='';renderVCmts(i,aid);document.getElementById('cc-'+i).textContent=getCmts(aid).length;}
|
| 186 |
-
|
| 187 |
function initFeed(){const feed=document.getElementById('tiktok-feed');if(!feed)return;const slides=feed.querySelectorAll('.tiktok-slide');slides.forEach(sl=>{const v=sl.querySelector('video[data-hls]');if(v&&!v._h){v._h=1;const s=v.dataset.hls;if(v.canPlayType('application/vnd.apple.mpegURL'))v.src=s;else if(Hls.isSupported()){const h=new Hls();h.loadSource(s);h.attachMedia(v);}else v.src=s;}});
|
| 188 |
-
let cur=-1;function act(idx){if(idx===cur)return;
|
| 189 |
-
closeAllCmtPanels();
|
| 190 |
-
slides.forEach((sl,i)=>{const v=sl.querySelector('video');if(i===idx){v.currentTime=0;v.play().catch(()=>setTimeout(()=>v.play().catch(()=>{}),500));const aid=sl.dataset.aid;if(aid){incV(aid);const vc=document.getElementById('vc-'+i);if(vc)vc.textContent=getV(aid);}}else v.pause();});cur=idx;}
|
| 191 |
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)act(best);},150);});
|
| 192 |
setTimeout(()=>act(0),500);
|
| 193 |
-
slides.forEach(sl=>{const v=sl.querySelector('video');v.addEventListener('click',e=>{e.preventDefault();v.paused?v.play().catch(()=>{}):v.pause();});});}
|
| 194 |
function toggleMute(){const f=document.getElementById('tiktok-feed');if(!f)return;const vs=f.querySelectorAll('video');const m=!vs[0]?.muted;vs.forEach(v=>v.muted=m);f.querySelectorAll('.tiktok-unmute').forEach(b=>b.textContent=m?'🔇':'🔊');}
|
| 195 |
function toggleContain(btn){const sl=btn.closest('.tiktok-slide');sl.classList.toggle('contain-mode');btn.textContent=sl.classList.contains('contain-mode')?'⤢':'⬇';}
|
| 196 |
function seekV(i,s){const sl=document.getElementById('tslide-'+i);if(sl){const v=sl.querySelector('video');if(v)v.currentTime=Math.max(0,Math.min(v.duration||9999,v.currentTime+s));}}
|
| 197 |
-
|
| 198 |
init();
|
| 199 |
</script>
|
| 200 |
</body>
|
|
|
|
| 11 |
<link rel="canonical" href="https://bep40-vnews.hf.space">
|
| 12 |
<script src="https://cdn.jsdelivr.net/npm/hls.js@1/dist/hls.min.js"></script>
|
| 13 |
<style>
|
| 14 |
+
*{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}.grid{display:grid;grid-template-columns:repeat(2,1fr);gap:6px;padding:6px 4px}@media(min-width:600px){.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(.97)}.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:28px;height:28px;background:rgba(0,0,0,.5);border-radius:50%;color:#fff;display:flex;align-items:center;justify-content:center;font-size:11px}.card-body{padding:6px 8px}.card-title{font-size:11px;font-weight:600;color:#eee;line-height:1.3;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.card-meta{display:flex;gap:8px;margin-top:3px;font-size:9px;color:#666}.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-bdp{background:#1a5c35;color:#fff}.badge-24h{background:#e67e22;color:#fff}.badge-bbc{background:#b80000;color:#fff}.slider-wrap{margin:6px 4px;background:#1a1a1a;border-radius:8px;overflow:hidden;border:1px solid #2a2a2a}.slider-header{padding:7px 10px}.slider-label{color:#f0c040;font-size:13px;font-weight:700}.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;scroll-snap-align:start;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.2;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}.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{width:100%;height:100%;object-fit:cover}.tiktok-slide.contain-mode video{object-fit:contain}.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-seek{display:flex;gap:8px;margin-top:4px}.tiktok-seek button{background:rgba(255,255,255,.12);color:#fff;border:none;padding:4px 10px;border-radius:10px;font-size:10px;cursor:pointer}.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-unmute{position:absolute;top:8px;right:8px;background:rgba(0,0,0,.5);color:#fff;font-size:10px;padding:4px 8px;border-radius:10px;cursor:pointer;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}.tiktok-right-btn .count{font-size:10px;color:#ddd}.cmt-panel{position:absolute;bottom:0;left:0;right:0;height:60%;background:#1a1a1a;z-index:30;transform:translateY(100%);transition:transform .3s;border-radius:14px 14px 0 0;padding:12px;overflow-y:auto}.cmt-panel.open{transform:translateY(0)}.cmt-panel-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}.cmt-panel-header h4{color:#fff;font-size:14px}.cmt-panel-close{background:none;border:none;color:#aaa;font-size:20px;cursor:pointer}.cmt-panel .cmt-item{background:#222;border-radius:6px;padding:7px;margin-bottom:5px}.cmt-panel .cmt-item b{color:#5cb87a;font-size:11px}.cmt-panel .cmt-item p{color:#ccc;font-size:12px;margin-top:2px}.cmt-panel .cmt-item small{color:#555;font-size:9px}.cmt-panel .cmt-form{display:flex;gap:5px;margin-top:8px;position:sticky;bottom:0;background:#1a1a1a;padding:6px 0}.cmt-panel .cmt-form input{flex:1;padding:8px;background:#222;border:1px solid #444;border-radius:8px;color:#eee;font-size:12px}.cmt-panel .cmt-form button{background:#2d8659;color:#fff;border:none;padding:8px 14px;border-radius:8px;font-size:12px;cursor:pointer}.loading{text-align:center;padding:40px;color:#666;font-size:12px}.topbar{display:flex;justify-content:space-between;padding:6px 8px;color:#555;font-size:10px}.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}a.card-link{text-decoration:none;color:inherit}.article-view{padding:12px 8px 40px;max-width:700px;margin:0 auto}.article-title{font-size:18px;font-weight:800;color:#f0f0f0;line-height:1.3;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.7;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:10px;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:6px 12px;border-radius:14px;font-size:11px;cursor:pointer}.cmt-section{margin-top:14px;border-top:1px solid #333;padding-top:10px}.cmt-section h3{font-size:13px;color:#eee;margin-bottom:6px}.cmt-item{background:#1a1a1a;border-radius:6px;padding:7px;margin-bottom:5px}.cmt-item b{color:#5cb87a;font-size:11px}.cmt-item p{color:#ccc;font-size:12px;margin-top:2px}.cmt-item small{color:#555;font-size:9px}.cmt-form{display:flex;gap:5px;margin-top:6px;flex-wrap:wrap}.cmt-form input{flex:1;min-width:80px;padding:6px;background:#1a1a1a;border:1px solid #333;border-radius:6px;color:#eee;font-size:11px}.cmt-form button{background:#2d8659;color:#fff;border:none;padding:6px 12px;border-radius:6px;font-size:11px;cursor:pointer}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
</style>
|
| 16 |
</head>
|
| 17 |
<body>
|
|
|
|
| 32 |
function addCmt(id,n,t){let c=getCmts(id);c.push({n,t,d:new Date().toLocaleString('vi-VN')});LS.set('c_'+id,c);return c;}
|
| 33 |
function incS(id){let v=(LS.get('s_'+id)||0)+1;LS.set('s_'+id,v);return v;}
|
| 34 |
function getS(id){return LS.get('s_'+id)||0}
|
| 35 |
+
function doShare(title,articleUrl,img){const shareUrl=SPACE+'/s?url='+encodeURIComponent(articleUrl)+'&title='+encodeURIComponent(title)+'&img='+encodeURIComponent(img||'');const aid=hid(articleUrl||title);incS(aid);if(navigator.share)navigator.share({title,url:shareUrl}).catch(()=>{});else navigator.clipboard.writeText(shareUrl).then(()=>alert('Đã sao chép!')).catch(()=>{});}
|
| 36 |
+
document.addEventListener('click',function(e){if(!e.target.closest('.cmt-panel')&&!e.target.closest('.tiktok-right-btn')){document.querySelectorAll('.cmt-panel.open').forEach(p=>p.classList.remove('open'));}});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
async function init(){
|
| 38 |
_cats=await fetch('/api/categories').then(r=>r.json());
|
| 39 |
let bar='<div class="cat active" data-cat="home">🏠</div><div class="cat" data-cat="video">🎬 Video</div>';
|
|
|
|
| 41 |
document.getElementById('cat-bar').innerHTML=bar;
|
| 42 |
document.querySelectorAll('.cat').forEach(t=>{t.onclick=()=>switchCat(t.dataset.cat);});
|
| 43 |
await loadHome();
|
|
|
|
| 44 |
const params=new URLSearchParams(location.search);
|
| 45 |
const openUrl=params.get('open');
|
| 46 |
+
if(openUrl){history.replaceState(null,'',location.pathname);readArticle(openUrl,'vne');}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
function switchCat(id){document.querySelectorAll('.cat').forEach(x=>x.classList.remove('active'));document.querySelector(`[data-cat="${id}"]`)?.classList.add('active');document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.querySelectorAll('video').forEach(v=>v.pause());if(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);}}
|
| 49 |
function showView(id){document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.getElementById(id).classList.add('active');}
|
| 50 |
+
async function loadHome(){const[news,hl,sh]=await Promise.all([fetch('/api/homepage').then(r=>r.json()),fetch('/api/highlights').then(r=>r.json()),fetch('/api/shorts').then(r=>r.json())]);let h='';if(sh&&sh.length){h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">📱 Shorts 24h</span></div><div class="slider-track">';sh.forEach((a,i)=>{h+=`<div class="slider-item shorts-item" onclick="openTikTok('shorts','${a.link}')"><div class="slider-thumb shorts-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`;});h+='</div></div>';}if(hl&&hl.length){h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">🎬 Highlight</span></div><div class="slider-track">';hl.forEach((a,i)=>{h+=`<div class="slider-item" onclick="openTikTok('highlights','${a.link}')"><div class="slider-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`;});h+='</div></div>';}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==='bdp'?'badge-bdp':'badge-vne';const lb=a.source==='bbc'?'BBC':a.source==='bdp'?'BDP':'VnE';const aid=hid(a.link);h+=`<div class="card" onclick="readArticle('${a.link.replace(/'/g,"\\'")}','${a.source}')"><div class="card-img">${a.img?`<img src="${a.img}">`:''}</div><div class="card-body"><span class="badge ${bg}">${lb}</span><div class="card-title">${a.title}</div><div class="card-meta"><span>👁${getV(aid)}</span><span>💬${getCmts(aid).length}</span></div></div></div>`;});h+='</div>';}document.getElementById('view-home').innerHTML=h;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
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());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==='bdp'?'badge-bdp':'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;}
|
| 52 |
+
async function readArticle(url,source){showView('view-article');const el=document.getElementById('view-article');el.innerHTML='<div class="loading">Đang tải...</div>';const aid=hid(url);incV(aid);const data=await fetch('/api/article?url='+encodeURIComponent(url)).then(r=>r.json());if(!data||data.error){el.innerHTML=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view" style="text-align:center;padding:60px 20px"><p style="color:#aaa;margin-bottom:12px">Không tải được nội dung</p><a href="${url}" target="_blank" style="color:#5cb87a;font-size:14px">📰 Mở bài viết gốc</a></div>`;return;}const ogImg=data.og_image||'';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>`;data.body.forEach(b=>{if(b.type==='p')h+=`<p class="article-p">${b.text}</p>`;else if(b.type==='img')h+=`<img class="article-img" src="${b.src}">`;else if(b.type==='heading')h+=`<h2 class="article-h2">${b.text}</h2>`;});h+=`<div class="article-actions"><button onclick="doShare('${data.title.replace(/'/g,"\\'")}','${url.replace(/'/g,"\\'")}','${ogImg.replace(/'/g,"\\'")}')">📤 Chia sẻ (${getS(aid)})</button><button>👁 ${getV(aid)}</button><button>💬 ${getCmts(aid).length}</button></div>`;h+=renderCmtSection(aid);h+='</div>';el.innerHTML=h;window.scrollTo(0,0);}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
function renderCmtSection(aid){const cmts=getCmts(aid);let h=`<div class="cmt-section"><h3>💬 Bình luận (${cmts.length})</h3><div id="cl-${aid}">`;cmts.slice().reverse().forEach(c=>{h+=`<div class="cmt-item"><b>${c.n}</b> <small>${c.d}</small><p>${c.t}</p></div>`;});if(!cmts.length)h+='<p style="color:#666;font-size:11px">Chưa có bình luận</p>';h+=`</div><div class="cmt-form"><input id="cn-${aid}" placeholder="Tên"><input id="ct-${aid}" placeholder="Bình luận..."><button onclick="submitCmt('${aid}')">Gửi</button></div></div>`;return h;}
|
| 54 |
function submitCmt(aid){const n=document.getElementById('cn-'+aid),t=document.getElementById('ct-'+aid);if(!n.value.trim()||!t.value.trim())return;addCmt(aid,n.value.trim(),t.value.trim());t.value='';const cmts=getCmts(aid);let h='';cmts.slice().reverse().forEach(c=>{h+=`<div class="cmt-item"><b>${c.n}</b> <small>${c.d}</small><p>${c.t}</p></div>`;});document.getElementById('cl-'+aid).innerHTML=h;}
|
|
|
|
| 55 |
async function loadVideos(){const el=document.getElementById('view-video');if(el.dataset.loaded)return;el.innerHTML='<div class="loading">Đang tải...</div>';const[hl,bdp]=await Promise.all([fetch('/api/highlights').then(r=>r.json()),fetch('/api/bdp_videos').then(r=>r.json())]);let h='<div class="section-title">🎬 Highlight</div><div class="grid">';hl.forEach((a,i)=>{h+=`<div class="card" onclick="openTikTok('highlights','${a.link}')"><div class="card-img">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge badge-24h">24h</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','${a.link}')"><div class="card-img">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge badge-bdp">BDP</span><div class="card-title">${a.title}</div></div></div>`;});h+='</div>';}el.innerHTML=h;el.dataset.loaded='1';}
|
| 56 |
+
async function openTikTok(type,targetLink){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());else if(type==='highlights')articles=await fetch('/api/highlights').then(r=>r.json());else articles=await fetch('/api/bdp_videos').then(r=>r.json());const vids=[];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){if(v.all_parts&&v.all_parts.length>1){v.all_parts.forEach((p,pi)=>{vids.push({...a,src:p,poster:v.poster,_idx:i,_part:pi,title:a.title+` (P${pi+1})`});});}else{vids.push({...a,...v,_idx:i,_part:0});}}}catch(e){}}));vids.sort((a,b)=>a._idx-b._idx||a._part-b._part);if(!vids.length){el.innerHTML='<div class="loading">Không tìm thấy video</div>';return;}const ti=vids.findIndex(v=>v.link===targetLink);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 aid=hid(v.link||v.title);const isHLS=v.src.includes('.m3u8');const poster=v.poster?` poster="${v.poster}"`:'';const vtag=isHLS?`<video playsinline preload="metadata"${poster} data-hls="${v.src}" muted loop></video>`:`<video playsinline preload="metadata"${poster} muted loop><source src="${v.src}" type="video/mp4"></video>`;const bg=v.source==='bdp'?'badge-bdp':'badge-24h';const lb=v.source==='bdp'?'BDP':'24h';h+=`<div class="tiktok-slide" id="tslide-${i}" data-aid="${aid}" data-link="${(v.link||'').replace(/"/g,'')}" data-img="${(v.poster||v.img||'').replace(/"/g,'')}">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
${vtag}
|
| 58 |
+
<div class="tiktok-bottom"><span class="badge ${bg}">${lb}</span><p class="tiktok-title">${v.title}</p><div class="tiktok-seek"><button onclick="seekV(${i},-10)">⏪ 10s</button><button onclick="seekV(${i},10)">10s ⏩</button><button onclick="toggleContain(this)">⬇</button></div></div>
|
| 59 |
+
<div class="tiktok-right"><button class="tiktok-right-btn"><div class="icon">👁</div><div class="count" id="vc-${i}">${getV(aid)}</div></button><button class="tiktok-right-btn" onclick="event.stopPropagation();toggleCmtPanel(${i})"><div class="icon">💬</div><div class="count" id="cc-${i}">${getCmts(aid).length}</div></button><button class="tiktok-right-btn" onclick="event.stopPropagation();shareVid(${i})"><div class="icon">📤</div><div class="count" id="sc-${i}">${getS(aid)}</div></button></div>
|
| 60 |
+
<div class="tiktok-unmute" onclick="toggleMute()">🔇</div><span class="tiktok-counter">${i+1}/${ordered.length}</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
<div class="cmt-panel" id="cpanel-${i}"><div class="cmt-panel-header"><h4>💬 Bình luận</h4><button class="cmt-panel-close" onclick="toggleCmtPanel(${i})">✕</button></div><div id="vcl-${i}"></div><div class="cmt-form"><input id="vcn-${i}" placeholder="Tên"><input id="vct-${i}" placeholder="Bình luận..."><button onclick="submitVCmt(${i},'${aid}')">Gửi</button></div></div>
|
| 62 |
+
</div>`;});h+='</div></div>';h+=`<div class="topbar"><span>📋 Danh sách (${ordered.length})</span></div><div class="grid">`;ordered.forEach((v,i)=>{const bg=v.source==='bdp'?'badge-bdp':'badge-24h';h+=`<a href="#tslide-${i}" class="card-link"><div class="card"><div class="card-img">${(v.img||v.poster)?`<img src="${v.img||v.poster}">`:''}<div class="card-play">▶</div></div><div class="card-body"><span class="badge ${bg}">${v.source==='bdp'?'BDP':'24h'}</span><div class="card-title">${v.title}</div></div></div></a>`;});h+='</div>';el.innerHTML=h;initFeed();ordered.forEach((v,i)=>{renderVCmts(i,hid(v.link||v.title));});}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
function shareVid(i){const v=_tikData[i];if(!v)return;doShare(v.title,v.link||'',v.poster||v.img||'');const aid=hid(v.link||v.title);document.getElementById('sc-'+i).textContent=getS(aid);}
|
| 64 |
function toggleCmtPanel(i){const p=document.getElementById('cpanel-'+i);p.classList.toggle('open');}
|
| 65 |
function closeAllCmtPanels(){document.querySelectorAll('.cmt-panel.open').forEach(p=>p.classList.remove('open'));}
|
| 66 |
function renderVCmts(i,aid){const el=document.getElementById('vcl-'+i);if(!el)return;const cmts=getCmts(aid);let h='';cmts.slice().reverse().forEach(c=>{h+=`<div class="cmt-item"><b>${c.n}</b> <small>${c.d}</small><p>${c.t}</p></div>`;});if(!cmts.length)h='<p style="color:#666;font-size:11px">Chưa có bình luận</p>';el.innerHTML=h;}
|
| 67 |
function submitVCmt(i,aid){const n=document.getElementById('vcn-'+i),t=document.getElementById('vct-'+i);if(!n.value.trim()||!t.value.trim())return;addCmt(aid,n.value.trim(),t.value.trim());t.value='';renderVCmts(i,aid);document.getElementById('cc-'+i).textContent=getCmts(aid).length;}
|
|
|
|
| 68 |
function initFeed(){const feed=document.getElementById('tiktok-feed');if(!feed)return;const slides=feed.querySelectorAll('.tiktok-slide');slides.forEach(sl=>{const v=sl.querySelector('video[data-hls]');if(v&&!v._h){v._h=1;const s=v.dataset.hls;if(v.canPlayType('application/vnd.apple.mpegURL'))v.src=s;else if(Hls.isSupported()){const h=new Hls();h.loadSource(s);h.attachMedia(v);}else v.src=s;}});
|
| 69 |
+
let cur=-1;function act(idx){if(idx===cur)return;closeAllCmtPanels();slides.forEach((sl,i)=>{const v=sl.querySelector('video');if(i===idx){v.currentTime=0;v.play().catch(()=>setTimeout(()=>v.play().catch(()=>{}),500));const aid=sl.dataset.aid;if(aid){incV(aid);const vc=document.getElementById('vc-'+i);if(vc)vc.textContent=getV(aid);}}else v.pause();});cur=idx;}
|
|
|
|
|
|
|
| 70 |
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)act(best);},150);});
|
| 71 |
setTimeout(()=>act(0),500);
|
| 72 |
+
slides.forEach(sl=>{const v=sl.querySelector('video');v.addEventListener('click',e=>{e.preventDefault();closeAllCmtPanels();v.paused?v.play().catch(()=>{}):v.pause();});});}
|
| 73 |
function toggleMute(){const f=document.getElementById('tiktok-feed');if(!f)return;const vs=f.querySelectorAll('video');const m=!vs[0]?.muted;vs.forEach(v=>v.muted=m);f.querySelectorAll('.tiktok-unmute').forEach(b=>b.textContent=m?'🔇':'🔊');}
|
| 74 |
function toggleContain(btn){const sl=btn.closest('.tiktok-slide');sl.classList.toggle('contain-mode');btn.textContent=sl.classList.contains('contain-mode')?'⤢':'⬇';}
|
| 75 |
function seekV(i,s){const sl=document.getElementById('tslide-'+i);if(sl){const v=sl.querySelector('video');if(v)v.currentTime=Math.max(0,Math.min(v.duration||9999,v.currentTime+s));}}
|
|
|
|
| 76 |
init();
|
| 77 |
</script>
|
| 78 |
</body>
|