Spaces:
Running
Running
feat: video comments panel, right-side action buttons TikTok style, hash routing works, SEO share URL
Browse files- static/index.html +77 -29
static/index.html
CHANGED
|
@@ -4,9 +4,9 @@
|
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
|
| 6 |
<title>VNEWS - Tin Tức Việt Nam</title>
|
| 7 |
-
<meta name="description" content="Tin tức tổng hợp VnExpress, BongDaPlus, 24h, BBC Tiếng Việt">
|
| 8 |
<meta property="og:title" content="VNEWS - Tin Tức Việt Nam">
|
| 9 |
-
<meta property="og:description" content="Đọc tin
|
| 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">
|
|
@@ -32,16 +32,32 @@
|
|
| 32 |
.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}
|
| 33 |
.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}
|
| 34 |
.shorts-item{flex:0 0 110px!important}.shorts-thumb{aspect-ratio:3/4!important;border-radius:8px!important}
|
|
|
|
| 35 |
.tiktok-container{width:100%;height:80vh;max-height:680px;min-height:400px;background:#000}
|
| 36 |
.tiktok-feed{height:100%;overflow-y:scroll;scroll-snap-type:y mandatory;scrollbar-width:none}.tiktok-feed::-webkit-scrollbar{display:none}
|
| 37 |
.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}
|
| 38 |
.tiktok-slide video{width:100%;height:100%;object-fit:cover}.tiktok-slide.contain-mode video{object-fit:contain}
|
| 39 |
-
.tiktok-bottom{position:absolute;bottom:0;left:0;right:
|
| 40 |
.tiktok-title{color:#fff;font-size:12px;font-weight:600;margin:3px 0 5px;line-height:1.3}
|
| 41 |
-
.tiktok-
|
|
|
|
| 42 |
.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}
|
| 43 |
.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}
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
.loading{text-align:center;padding:40px;color:#666;font-size:12px}
|
| 46 |
.topbar{display:flex;justify-content:space-between;padding:6px 8px;color:#555;font-size:10px}
|
| 47 |
.section-title{font-size:13px;font-weight:700;color:#5cb87a;margin:8px 0 4px;padding-left:8px;border-left:3px solid #5cb87a}
|
|
@@ -62,7 +78,7 @@ a.card-link{text-decoration:none;color:inherit}
|
|
| 62 |
</style>
|
| 63 |
</head>
|
| 64 |
<body>
|
| 65 |
-
<div class="header"><h1>📰 VNEWS</h1><p>Tin tức
|
| 66 |
<div class="cats" id="cat-bar"></div>
|
| 67 |
<div id="view-home" class="view active"><div class="loading">Đang tải...</div></div>
|
| 68 |
<div id="view-cat" class="view"></div>
|
|
@@ -79,7 +95,16 @@ function getCmts(id){return LS.get('c_'+id)||[]}
|
|
| 79 |
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;}
|
| 80 |
function incS(id){let v=(LS.get('s_'+id)||0)+1;LS.set('s_'+id,v);return v;}
|
| 81 |
function getS(id){return LS.get('s_'+id)||0}
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
async function init(){
|
| 85 |
_cats=await fetch('/api/categories').then(r=>r.json());
|
|
@@ -88,13 +113,23 @@ async function init(){
|
|
| 88 |
document.getElementById('cat-bar').innerHTML=bar;
|
| 89 |
document.querySelectorAll('.cat').forEach(t=>{t.onclick=()=>switchCat(t.dataset.cat);});
|
| 90 |
await loadHome();
|
| 91 |
-
// Handle hash routing on page load
|
| 92 |
handleHash();
|
| 93 |
}
|
| 94 |
function handleHash(){
|
| 95 |
const h=location.hash;if(!h||h.length<4)return;
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
|
|
|
|
|
|
| 98 |
function switchCat(id){
|
| 99 |
document.querySelectorAll('.cat').forEach(x=>x.classList.remove('active'));
|
| 100 |
document.querySelector(`[data-cat="${id}"]`)?.classList.add('active');
|
|
@@ -109,19 +144,16 @@ function showView(id){document.querySelectorAll('.view').forEach(x=>x.classList.
|
|
| 109 |
async function loadHome(){
|
| 110 |
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())]);
|
| 111 |
let h='';
|
| 112 |
-
// Shorts
|
| 113 |
if(sh&&sh.length){
|
| 114 |
h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">📱 Shorts 24h</span></div><div class="slider-track">';
|
| 115 |
sh.forEach((a,i)=>{h+=`<div class="slider-item shorts-item" onclick="openTikTok('shorts',${i})"><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>`;});
|
| 116 |
h+='</div></div>';
|
| 117 |
}
|
| 118 |
-
// Highlights
|
| 119 |
if(hl&&hl.length){
|
| 120 |
-
h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">🎬 Highlight
|
| 121 |
hl.forEach((a,i)=>{h+=`<div class="slider-item" onclick="openTikTok('highlights',${i})"><div class="slider-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`;});
|
| 122 |
h+='</div></div>';
|
| 123 |
}
|
| 124 |
-
// News
|
| 125 |
const groups={};news.forEach(a=>{if(!groups[a.group])groups[a.group]=[];groups[a.group].push(a);});
|
| 126 |
for(const[g,arts] of Object.entries(groups)){
|
| 127 |
h+=`<div class="section-title">${g}</div><div class="grid">`;
|
|
@@ -137,25 +169,18 @@ async function loadCat(id){const el=document.getElementById('view-cat');el.inner
|
|
| 137 |
async function readArticle(url,source){
|
| 138 |
if(source!=='vne'&&source!=='bbc'){window.open(url,'_blank');return;}
|
| 139 |
showView('view-article');const el=document.getElementById('view-article');el.innerHTML='<div class="loading">Đang tải...</div>';
|
| 140 |
-
const aid=hid(url);incV(aid);location.hash='#/'+aid;
|
| 141 |
const data=await fetch('/api/article?url='+encodeURIComponent(url)).then(r=>r.json());
|
| 142 |
if(!data||data.error){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;}
|
| 143 |
let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view"><h1 class="article-title">${data.title}</h1>`;
|
| 144 |
if(data.summary)h+=`<div class="article-summary">${data.summary}</div>`;
|
| 145 |
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>`;});
|
| 146 |
-
h+=`<div class="article-actions"><button onclick="doShare('${data.title.replace(/'/g,"\\'")}','${aid}')">📤 Chia sẻ (${getS(aid)})</button><button>👁 ${getV(aid)}</button><button>💬 ${getCmts(aid).length}</button></div>`;
|
| 147 |
h+=renderCmtSection(aid);
|
| 148 |
h+='</div>';el.innerHTML=h;window.scrollTo(0,0);
|
| 149 |
}
|
| 150 |
|
| 151 |
-
function renderCmtSection(aid){
|
| 152 |
-
const cmts=getCmts(aid);
|
| 153 |
-
let h=`<div class="cmt-section"><h3>💬 Bình luận (${cmts.length})</h3><div id="cl-${aid}">`;
|
| 154 |
-
cmts.slice().reverse().forEach(c=>{h+=`<div class="cmt-item"><b>${c.n}</b> <small>${c.d}</small><p>${c.t}</p></div>`;});
|
| 155 |
-
if(!cmts.length)h+='<p style="color:#666;font-size:11px">Chưa có bình luận</p>';
|
| 156 |
-
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>`;
|
| 157 |
-
return h;
|
| 158 |
-
}
|
| 159 |
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;}
|
| 160 |
|
| 161 |
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',${i})"><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',${i})"><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';}
|
|
@@ -169,20 +194,43 @@ async function openTikTok(type,startIdx){
|
|
| 169 |
if(!vids.length){el.innerHTML='<div class="loading">Không tìm thấy video</div>';return;}
|
| 170 |
const ti=vids.findIndex(v=>v._idx===startIdx);const ordered=ti>0?[...vids.slice(ti),...vids.slice(0,ti)]:vids;_tikData=ordered;
|
| 171 |
let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="tiktok-container"><div class="tiktok-feed" id="tiktok-feed">`;
|
| 172 |
-
ordered.forEach((v,i)=>{
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
//
|
| 180 |
-
|
| 181 |
}
|
| 182 |
|
| 183 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
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?'🔇':'🔊');}
|
| 185 |
-
function toggleContain(btn){const sl=btn.closest('.tiktok-slide');sl.classList.toggle('contain-mode');btn.textContent=sl.classList.contains('contain-mode')?'⤢':'⬇';}
|
| 186 |
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));}}
|
| 187 |
|
| 188 |
init();
|
|
|
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
|
| 6 |
<title>VNEWS - Tin Tức Việt Nam</title>
|
| 7 |
+
<meta name="description" content="Tin tức tổng hợp VnExpress, BongDaPlus, 24h, BBC Tiếng Việt. Video highlight bóng đá, shorts 24h.">
|
| 8 |
<meta property="og:title" content="VNEWS - Tin Tức Việt Nam">
|
| 9 |
+
<meta property="og:description" content="Đọc tin, xem video highlight bóng đá, shorts 24h">
|
| 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">
|
|
|
|
| 32 |
.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}
|
| 33 |
.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}
|
| 34 |
.shorts-item{flex:0 0 110px!important}.shorts-thumb{aspect-ratio:3/4!important;border-radius:8px!important}
|
| 35 |
+
/* TikTok Feed */
|
| 36 |
.tiktok-container{width:100%;height:80vh;max-height:680px;min-height:400px;background:#000}
|
| 37 |
.tiktok-feed{height:100%;overflow-y:scroll;scroll-snap-type:y mandatory;scrollbar-width:none}.tiktok-feed::-webkit-scrollbar{display:none}
|
| 38 |
.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}
|
| 39 |
.tiktok-slide video{width:100%;height:100%;object-fit:cover}.tiktok-slide.contain-mode video{object-fit:contain}
|
| 40 |
+
.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}
|
| 41 |
.tiktok-title{color:#fff;font-size:12px;font-weight:600;margin:3px 0 5px;line-height:1.3}
|
| 42 |
+
.tiktok-seek{display:flex;gap:8px;margin-top:4px}
|
| 43 |
+
.tiktok-seek button{background:rgba(255,255,255,.12);color:#fff;border:none;padding:4px 10px;border-radius:10px;font-size:10px;cursor:pointer}
|
| 44 |
.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}
|
| 45 |
.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}
|
| 46 |
+
/* Right side action buttons (TikTok style) */
|
| 47 |
+
.tiktok-right{position:absolute;right:8px;bottom:100px;display:flex;flex-direction:column;align-items:center;gap:14px;z-index:5}
|
| 48 |
+
.tiktok-right-btn{display:flex;flex-direction:column;align-items:center;gap:2px;cursor:pointer;background:none;border:none;color:#fff}
|
| 49 |
+
.tiktok-right-btn .icon{width:40px;height:40px;border-radius:50%;background:rgba(255,255,255,.12);display:flex;align-items:center;justify-content:center;font-size:18px}
|
| 50 |
+
.tiktok-right-btn .count{font-size:10px;color:#ddd}
|
| 51 |
+
/* Comment panel */
|
| 52 |
+
.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}
|
| 53 |
+
.cmt-panel.open{transform:translateY(0)}
|
| 54 |
+
.cmt-panel-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
|
| 55 |
+
.cmt-panel-header h4{color:#fff;font-size:14px}.cmt-panel-close{background:none;border:none;color:#aaa;font-size:20px;cursor:pointer}
|
| 56 |
+
.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}
|
| 57 |
+
.cmt-panel .cmt-form{display:flex;gap:5px;margin-top:8px;position:sticky;bottom:0;background:#1a1a1a;padding:6px 0}
|
| 58 |
+
.cmt-panel .cmt-form input{flex:1;padding:8px;background:#222;border:1px solid #444;border-radius:8px;color:#eee;font-size:12px}
|
| 59 |
+
.cmt-panel .cmt-form button{background:#2d8659;color:#fff;border:none;padding:8px 14px;border-radius:8px;font-size:12px;cursor:pointer}
|
| 60 |
+
/* Others */
|
| 61 |
.loading{text-align:center;padding:40px;color:#666;font-size:12px}
|
| 62 |
.topbar{display:flex;justify-content:space-between;padding:6px 8px;color:#555;font-size:10px}
|
| 63 |
.section-title{font-size:13px;font-weight:700;color:#5cb87a;margin:8px 0 4px;padding-left:8px;border-left:3px solid #5cb87a}
|
|
|
|
| 78 |
</style>
|
| 79 |
</head>
|
| 80 |
<body>
|
| 81 |
+
<div class="header"><h1>📰 VNEWS</h1><p>Tin tức · Video · Cập nhật liên tục</p></div>
|
| 82 |
<div class="cats" id="cat-bar"></div>
|
| 83 |
<div id="view-home" class="view active"><div class="loading">Đang tải...</div></div>
|
| 84 |
<div id="view-cat" class="view"></div>
|
|
|
|
| 95 |
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;}
|
| 96 |
function incS(id){let v=(LS.get('s_'+id)||0)+1;LS.set('s_'+id,v);return v;}
|
| 97 |
function getS(id){return LS.get('s_'+id)||0}
|
| 98 |
+
// Share uses /share/ route for SEO (server renders og:image)
|
| 99 |
+
function doShare(title,id,img){
|
| 100 |
+
const url=SPACE+'/share/'+id+'?title='+encodeURIComponent(title)+'&img='+encodeURIComponent(img||'');
|
| 101 |
+
incS(id);
|
| 102 |
+
if(navigator.share)navigator.share({title,url}).catch(()=>{});
|
| 103 |
+
else navigator.clipboard.writeText(url).then(()=>alert('Đã sao chép!')).catch(()=>{});
|
| 104 |
+
}
|
| 105 |
+
// Save URL mapping for hash routing
|
| 106 |
+
function saveUrl(aid,url){LS.set('u_'+aid,url);}
|
| 107 |
+
function getUrl(aid){return LS.get('u_'+aid);}
|
| 108 |
|
| 109 |
async function init(){
|
| 110 |
_cats=await fetch('/api/categories').then(r=>r.json());
|
|
|
|
| 113 |
document.getElementById('cat-bar').innerHTML=bar;
|
| 114 |
document.querySelectorAll('.cat').forEach(t=>{t.onclick=()=>switchCat(t.dataset.cat);});
|
| 115 |
await loadHome();
|
|
|
|
| 116 |
handleHash();
|
| 117 |
}
|
| 118 |
function handleHash(){
|
| 119 |
const h=location.hash;if(!h||h.length<4)return;
|
| 120 |
+
const aid=h.replace('#/','');
|
| 121 |
+
const url=getUrl(aid);
|
| 122 |
+
if(url){
|
| 123 |
+
// Determine source from URL
|
| 124 |
+
let src='vne';
|
| 125 |
+
if(url.includes('bbc.com'))src='bbc';
|
| 126 |
+
else if(url.includes('bongdaplus'))src='bdp';
|
| 127 |
+
else if(url.includes('24h.com'))src='24h';
|
| 128 |
+
readArticle(url,src);
|
| 129 |
+
}
|
| 130 |
}
|
| 131 |
+
window.addEventListener('hashchange',handleHash);
|
| 132 |
+
|
| 133 |
function switchCat(id){
|
| 134 |
document.querySelectorAll('.cat').forEach(x=>x.classList.remove('active'));
|
| 135 |
document.querySelector(`[data-cat="${id}"]`)?.classList.add('active');
|
|
|
|
| 144 |
async function loadHome(){
|
| 145 |
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())]);
|
| 146 |
let h='';
|
|
|
|
| 147 |
if(sh&&sh.length){
|
| 148 |
h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">📱 Shorts 24h</span></div><div class="slider-track">';
|
| 149 |
sh.forEach((a,i)=>{h+=`<div class="slider-item shorts-item" onclick="openTikTok('shorts',${i})"><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>`;});
|
| 150 |
h+='</div></div>';
|
| 151 |
}
|
|
|
|
| 152 |
if(hl&&hl.length){
|
| 153 |
+
h+='<div class="slider-wrap"><div class="slider-header"><span class="slider-label">🎬 Highlight</span></div><div class="slider-track">';
|
| 154 |
hl.forEach((a,i)=>{h+=`<div class="slider-item" onclick="openTikTok('highlights',${i})"><div class="slider-thumb">${a.img?`<img src="${a.img}">`:''}<div class="card-play">▶</div></div><div class="slider-title">${a.title}</div></div>`;});
|
| 155 |
h+='</div></div>';
|
| 156 |
}
|
|
|
|
| 157 |
const groups={};news.forEach(a=>{if(!groups[a.group])groups[a.group]=[];groups[a.group].push(a);});
|
| 158 |
for(const[g,arts] of Object.entries(groups)){
|
| 159 |
h+=`<div class="section-title">${g}</div><div class="grid">`;
|
|
|
|
| 169 |
async function readArticle(url,source){
|
| 170 |
if(source!=='vne'&&source!=='bbc'){window.open(url,'_blank');return;}
|
| 171 |
showView('view-article');const el=document.getElementById('view-article');el.innerHTML='<div class="loading">Đang tải...</div>';
|
| 172 |
+
const aid=hid(url);incV(aid);saveUrl(aid,url);location.hash='#/'+aid;
|
| 173 |
const data=await fetch('/api/article?url='+encodeURIComponent(url)).then(r=>r.json());
|
| 174 |
if(!data||data.error){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;}
|
| 175 |
let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view"><h1 class="article-title">${data.title}</h1>`;
|
| 176 |
if(data.summary)h+=`<div class="article-summary">${data.summary}</div>`;
|
| 177 |
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>`;});
|
| 178 |
+
h+=`<div class="article-actions"><button onclick="doShare('${data.title.replace(/'/g,"\\'")}','${aid}','')">📤 Chia sẻ (${getS(aid)})</button><button>👁 ${getV(aid)}</button><button>💬 ${getCmts(aid).length}</button></div>`;
|
| 179 |
h+=renderCmtSection(aid);
|
| 180 |
h+='</div>';el.innerHTML=h;window.scrollTo(0,0);
|
| 181 |
}
|
| 182 |
|
| 183 |
+
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;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
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;}
|
| 185 |
|
| 186 |
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',${i})"><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',${i})"><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';}
|
|
|
|
| 194 |
if(!vids.length){el.innerHTML='<div class="loading">Không tìm thấy video</div>';return;}
|
| 195 |
const ti=vids.findIndex(v=>v._idx===startIdx);const ordered=ti>0?[...vids.slice(ti),...vids.slice(0,ti)]:vids;_tikData=ordered;
|
| 196 |
let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="tiktok-container"><div class="tiktok-feed" id="tiktok-feed">`;
|
| 197 |
+
ordered.forEach((v,i)=>{
|
| 198 |
+
const aid=hid(v.link||v.title);const isHLS=v.src.includes('.m3u8');const poster=v.poster?` poster="${v.poster}"`:'';
|
| 199 |
+
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>`;
|
| 200 |
+
const bg=v.source==='bdp'?'badge-bdp':'badge-24h';const lb=v.source==='bdp'?'BDP':'24h';
|
| 201 |
+
h+=`<div class="tiktok-slide" id="tslide-${i}" data-aid="${aid}">
|
| 202 |
+
${vtag}
|
| 203 |
+
<div class="tiktok-bottom"><span class="badge ${bg}">${lb}</span><p class="tiktok-title">${v.title}</p>
|
| 204 |
+
<div class="tiktok-seek"><button onclick="seekV(${i},-10)">⏪ 10s</button><button onclick="seekV(${i},10)">10s ⏩</button><button onclick="toggleContain(this)">⬇ Contain</button></div></div>
|
| 205 |
+
<div class="tiktok-right">
|
| 206 |
+
<button class="tiktok-right-btn" onclick="event.stopPropagation();incV('${aid}');this.querySelector('.count').textContent=getV('${aid}')"><div class="icon">👁</div><div class="count">${getV(aid)}</div></button>
|
| 207 |
+
<button class="tiktok-right-btn" onclick="event.stopPropagation();toggleCmtPanel(${i})"><div class="icon">💬</div><div class="count">${getCmts(aid).length}</div></button>
|
| 208 |
+
<button class="tiktok-right-btn" onclick="event.stopPropagation();doShare('${v.title.replace(/'/g,"\\'")}','${aid}','${v.poster||''}');this.querySelector('.count').textContent=getS('${aid}')"><div class="icon">📤</div><div class="count">${getS(aid)}</div></button>
|
| 209 |
+
</div>
|
| 210 |
+
<div class="tiktok-unmute" onclick="toggleMute()">🔇</div>
|
| 211 |
+
<span class="tiktok-counter">${i+1}/${ordered.length}</span>
|
| 212 |
+
<div class="cmt-panel" id="cpanel-${i}">
|
| 213 |
+
<div class="cmt-panel-header"><h4>💬 Bình luận</h4><button class="cmt-panel-close" onclick="toggleCmtPanel(${i})">✕</button></div>
|
| 214 |
+
<div id="vcl-${i}"></div>
|
| 215 |
+
<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>
|
| 216 |
+
</div>
|
| 217 |
+
</div>`;
|
| 218 |
});
|
| 219 |
h+='</div></div>';
|
| 220 |
h+=`<div class="topbar"><span>📋 Danh sách (${ordered.length})</span></div><div class="grid">`;
|
| 221 |
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>`;});
|
| 222 |
h+='</div>';el.innerHTML=h;initFeed();
|
| 223 |
+
// Render comments for all slides
|
| 224 |
+
ordered.forEach((v,i)=>{const aid=hid(v.link||v.title);renderVCmts(i,aid);});
|
| 225 |
}
|
| 226 |
|
| 227 |
+
function toggleCmtPanel(i){const p=document.getElementById('cpanel-'+i);p.classList.toggle('open');}
|
| 228 |
+
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;}
|
| 229 |
+
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);}
|
| 230 |
+
|
| 231 |
+
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;}});let cur=-1;function act(idx){if(idx===cur)return;slides.forEach((sl,i)=>{const v=sl.querySelector('video');if(i===idx){v.currentTime=0;v.play().catch(()=>setTimeout(()=>v.play().catch(()=>{}),500));incV(sl.dataset.aid||'');}else v.pause();});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)act(best);},150);});setTimeout(()=>act(0),500);slides.forEach(sl=>{const v=sl.querySelector('video');v.addEventListener('click',e=>{e.preventDefault();v.paused?v.play().catch(()=>{}):v.pause();});});}
|
| 232 |
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?'🔇':'🔊');}
|
| 233 |
+
function toggleContain(btn){const sl=btn.closest('.tiktok-slide');sl.classList.toggle('contain-mode');btn.textContent=sl.classList.contains('contain-mode')?'⤢ 1:1':'⬇ Contain';}
|
| 234 |
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));}}
|
| 235 |
|
| 236 |
init();
|