fix: frontend - view once per session, share URL with og:image, pending article from share
Browse files- static/index.html +53 -106
static/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 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
|
| 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">
|
|
@@ -23,58 +23,41 @@
|
|
| 23 |
.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}
|
| 24 |
.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}
|
| 25 |
.card-meta{display:flex;gap:8px;margin-top:3px;font-size:9px;color:#666}
|
| 26 |
-
.badge{font-size:8px;padding:1px 5px;border-radius:3px;font-weight:700;display:inline-block;margin-bottom:2px}
|
| 27 |
-
.
|
| 28 |
-
.slider-wrap{margin:6px 4px;background:#1a1a1a;border-radius:8px;overflow:hidden;border:1px solid #2a2a2a}
|
| 29 |
-
.slider-header{padding:7px 10px}.slider-label{color:#f0c040;font-size:13px;font-weight:700}
|
| 30 |
.slider-track{display:flex;overflow-x:auto;gap:8px;padding:4px 10px 10px;scrollbar-width:none}.slider-track::-webkit-scrollbar{display:none}
|
| 31 |
-
.slider-item{flex:0 0 160px;scroll-snap-align:start;cursor:pointer;flex-shrink:0}
|
| 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:
|
| 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 |
-
.
|
| 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}
|
| 64 |
.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}
|
| 65 |
a.card-link{text-decoration:none;color:inherit}
|
| 66 |
-
.article-view{padding:12px 8px 40px;max-width:700px;margin:0 auto}
|
| 67 |
-
.article-title{font-size:18px;font-weight:800;color:#f0f0f0;line-height:1.3;margin-bottom:8px}
|
| 68 |
.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}
|
| 69 |
-
.article-p{font-size:14px;line-height:1.7;color:#ccc;margin-bottom:10px}
|
| 70 |
-
.article-
|
| 71 |
-
.
|
| 72 |
-
.article-actions button{background:#1a1a1a;border:1px solid #333;color:#ccc;padding:6px 12px;border-radius:14px;font-size:11px;cursor:pointer}
|
| 73 |
-
.cmt-section{margin-top:14px;border-top:1px solid #333;padding-top:10px}
|
| 74 |
-
.cmt-section h3{font-size:13px;color:#eee;margin-bottom:6px}
|
| 75 |
.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}
|
| 76 |
-
.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}
|
| 77 |
-
.cmt-form button{background:#2d8659;color:#fff;border:none;padding:6px 12px;border-radius:6px;font-size:11px;cursor:pointer}
|
| 78 |
</style>
|
| 79 |
</head>
|
| 80 |
<body>
|
|
@@ -86,25 +69,23 @@ a.card-link{text-decoration:none;color:inherit}
|
|
| 86 |
<div id="view-tiktok" class="view"></div>
|
| 87 |
<div id="view-article" class="view"></div>
|
| 88 |
<script>
|
| 89 |
-
const SPACE=location.origin;let _cats=[],_tikData=[];
|
| 90 |
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{}}};
|
| 91 |
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);}
|
| 92 |
-
|
|
|
|
| 93 |
function getV(id){return LS.get('v_'+id)||0}
|
| 94 |
function getCmts(id){return LS.get('c_'+id)||[]}
|
| 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 /
|
| 99 |
-
function doShare(title,
|
| 100 |
-
const
|
| 101 |
-
incS(
|
| 102 |
-
if(navigator.share)navigator.share({title,url}).catch(()=>{});
|
| 103 |
-
else navigator.clipboard.writeText(
|
| 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,73 +94,37 @@ async function init(){
|
|
| 113 |
document.getElementById('cat-bar').innerHTML=bar;
|
| 114 |
document.querySelectorAll('.cat').forEach(t=>{t.onclick=()=>switchCat(t.dataset.cat);});
|
| 115 |
await loadHome();
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 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');
|
| 136 |
-
document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));
|
| 137 |
-
document.querySelectorAll('video').forEach(v=>v.pause());
|
| 138 |
-
if(id==='home')document.getElementById('view-home').classList.add('active');
|
| 139 |
-
else if(id==='video'){document.getElementById('view-video').classList.add('active');loadVideos();}
|
| 140 |
-
else{document.getElementById('view-cat').classList.add('active');loadCat(id);}
|
| 141 |
}
|
|
|
|
| 142 |
function showView(id){document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.getElementById(id).classList.add('active');}
|
| 143 |
|
| 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 |
-
|
| 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">`;
|
| 160 |
-
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);
|
| 161 |
-
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>`;});
|
| 162 |
-
h+='</div>';
|
| 163 |
-
}
|
| 164 |
document.getElementById('view-home').innerHTML=h;
|
| 165 |
}
|
| 166 |
-
|
| 167 |
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;}
|
| 168 |
|
| 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);
|
| 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,"\\'")}','${
|
| 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 |
|
|
@@ -192,45 +137,47 @@ async function openTikTok(type,startIdx){
|
|
| 192 |
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){}}));
|
| 193 |
vids.sort((a,b)=>a._idx-b._idx||a._part-b._part);
|
| 194 |
if(!vids.length){el.innerHTML='<div class="loading">Không tìm thấy video</div>';return;}
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
| 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)">⬇
|
| 205 |
<div class="tiktok-right">
|
| 206 |
-
<button class="tiktok-right-btn"
|
| 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();
|
| 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){
|
| 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;}});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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')?'⤢
|
| 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();
|
|
|
|
| 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. Video highlight bóng đá.">
|
| 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">
|
|
|
|
| 23 |
.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}
|
| 24 |
.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}
|
| 25 |
.card-meta{display:flex;gap:8px;margin-top:3px;font-size:9px;color:#666}
|
| 26 |
+
.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}
|
| 27 |
+
.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}
|
|
|
|
|
|
|
| 28 |
.slider-track{display:flex;overflow-x:auto;gap:8px;padding:4px 10px 10px;scrollbar-width:none}.slider-track::-webkit-scrollbar{display:none}
|
| 29 |
+
.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}
|
|
|
|
| 30 |
.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}
|
| 31 |
.shorts-item{flex:0 0 110px!important}.shorts-thumb{aspect-ratio:3/4!important;border-radius:8px!important}
|
|
|
|
| 32 |
.tiktok-container{width:100%;height:80vh;max-height:680px;min-height:400px;background:#000}
|
| 33 |
.tiktok-feed{height:100%;overflow-y:scroll;scroll-snap-type:y mandatory;scrollbar-width:none}.tiktok-feed::-webkit-scrollbar{display:none}
|
| 34 |
.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}
|
| 35 |
.tiktok-slide video{width:100%;height:100%;object-fit:cover}.tiktok-slide.contain-mode video{object-fit:contain}
|
| 36 |
.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}
|
| 37 |
.tiktok-title{color:#fff;font-size:12px;font-weight:600;margin:3px 0 5px;line-height:1.3}
|
| 38 |
+
.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}
|
|
|
|
| 39 |
.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}
|
| 40 |
.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}
|
|
|
|
| 41 |
.tiktok-right{position:absolute;right:8px;bottom:100px;display:flex;flex-direction:column;align-items:center;gap:14px;z-index:5}
|
| 42 |
.tiktok-right-btn{display:flex;flex-direction:column;align-items:center;gap:2px;cursor:pointer;background:none;border:none;color:#fff}
|
| 43 |
+
.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}
|
| 44 |
.tiktok-right-btn .count{font-size:10px;color:#ddd}
|
|
|
|
| 45 |
.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}
|
| 46 |
.cmt-panel.open{transform:translateY(0)}
|
| 47 |
+
.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}
|
|
|
|
| 48 |
.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}
|
| 49 |
+
.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}
|
| 50 |
+
.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}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
.section-title{font-size:13px;font-weight:700;color:#5cb87a;margin:8px 0 4px;padding-left:8px;border-left:3px solid #5cb87a}
|
| 52 |
.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}
|
| 53 |
a.card-link{text-decoration:none;color:inherit}
|
| 54 |
+
.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}
|
|
|
|
| 55 |
.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}
|
| 56 |
+
.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}
|
| 57 |
+
.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}
|
| 58 |
+
.cmt-section{margin-top:14px;border-top:1px solid #333;padding-top:10px}.cmt-section h3{font-size:13px;color:#eee;margin-bottom:6px}
|
|
|
|
|
|
|
|
|
|
| 59 |
.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}
|
| 60 |
+
.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}
|
|
|
|
| 61 |
</style>
|
| 62 |
</head>
|
| 63 |
<body>
|
|
|
|
| 69 |
<div id="view-tiktok" class="view"></div>
|
| 70 |
<div id="view-article" class="view"></div>
|
| 71 |
<script>
|
| 72 |
+
const SPACE=location.origin;let _cats=[],_tikData=[],_viewed=new Set();
|
| 73 |
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{}}};
|
| 74 |
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);}
|
| 75 |
+
// View: only count ONCE per video per page session
|
| 76 |
+
function incV(id){if(_viewed.has(id))return getV(id);_viewed.add(id);let v=(LS.get('v_'+id)||0)+1;LS.set('v_'+id,v);return v;}
|
| 77 |
function getV(id){return LS.get('v_'+id)||0}
|
| 78 |
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 |
+
// Share: uses /s?url=...&title=...&img=... for SEO og:image
|
| 83 |
+
function doShare(title,articleUrl,img){
|
| 84 |
+
const shareUrl=SPACE+'/s?url='+encodeURIComponent(articleUrl)+'&title='+encodeURIComponent(title)+'&img='+encodeURIComponent(img||'');
|
| 85 |
+
const aid=hid(articleUrl||title);incS(aid);
|
| 86 |
+
if(navigator.share)navigator.share({title,url:shareUrl}).catch(()=>{});
|
| 87 |
+
else navigator.clipboard.writeText(shareUrl).then(()=>alert('Đã sao chép link!')).catch(()=>{});
|
| 88 |
}
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
async function init(){
|
| 91 |
_cats=await fetch('/api/categories').then(r=>r.json());
|
|
|
|
| 94 |
document.getElementById('cat-bar').innerHTML=bar;
|
| 95 |
document.querySelectorAll('.cat').forEach(t=>{t.onclick=()=>switchCat(t.dataset.cat);});
|
| 96 |
await loadHome();
|
| 97 |
+
// Check if redirected from share link
|
| 98 |
+
const pending=localStorage.getItem('pending_article');
|
| 99 |
+
if(pending){localStorage.removeItem('pending_article');let src='vne';if(pending.includes('bbc.com'))src='bbc';readArticle(pending,src);}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
}
|
| 101 |
+
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);}}
|
| 102 |
function showView(id){document.querySelectorAll('.view').forEach(x=>x.classList.remove('active'));document.getElementById(id).classList.add('active');}
|
| 103 |
|
| 104 |
async function loadHome(){
|
| 105 |
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())]);
|
| 106 |
let h='';
|
| 107 |
+
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',${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>`;});h+='</div></div>';}
|
| 108 |
+
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',${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>`;});h+='</div></div>';}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
const groups={};news.forEach(a=>{if(!groups[a.group])groups[a.group]=[];groups[a.group].push(a);});
|
| 110 |
+
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>';}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
document.getElementById('view-home').innerHTML=h;
|
| 112 |
}
|
|
|
|
| 113 |
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;}
|
| 114 |
|
| 115 |
async function readArticle(url,source){
|
| 116 |
if(source!=='vne'&&source!=='bbc'){window.open(url,'_blank');return;}
|
| 117 |
showView('view-article');const el=document.getElementById('view-article');el.innerHTML='<div class="loading">Đang tải...</div>';
|
| 118 |
+
const aid=hid(url);incV(aid);
|
| 119 |
const data=await fetch('/api/article?url='+encodeURIComponent(url)).then(r=>r.json());
|
| 120 |
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;}
|
| 121 |
+
const ogImg=data.og_image||'';
|
| 122 |
let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="article-view"><h1 class="article-title">${data.title}</h1>`;
|
| 123 |
if(data.summary)h+=`<div class="article-summary">${data.summary}</div>`;
|
| 124 |
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>`;});
|
| 125 |
+
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>`;
|
| 126 |
+
h+=renderCmtSection(aid);h+='</div>';el.innerHTML=h;window.scrollTo(0,0);
|
|
|
|
| 127 |
}
|
|
|
|
| 128 |
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;}
|
| 129 |
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;}
|
| 130 |
|
|
|
|
| 137 |
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){}}));
|
| 138 |
vids.sort((a,b)=>a._idx-b._idx||a._part-b._part);
|
| 139 |
if(!vids.length){el.innerHTML='<div class="loading">Không tìm thấy video</div>';return;}
|
| 140 |
+
// Put clicked video first: find first vid with matching _idx
|
| 141 |
+
const ti=vids.findIndex(v=>v._idx===startIdx);
|
| 142 |
+
const ordered=ti>0?[...vids.slice(ti),...vids.slice(0,ti)]:vids;
|
| 143 |
+
_tikData=ordered;
|
| 144 |
let h=`<button class="back-btn" onclick="switchCat('home')">← Quay lại</button><div class="tiktok-container"><div class="tiktok-feed" id="tiktok-feed">`;
|
| 145 |
ordered.forEach((v,i)=>{
|
| 146 |
const aid=hid(v.link||v.title);const isHLS=v.src.includes('.m3u8');const poster=v.poster?` poster="${v.poster}"`:'';
|
| 147 |
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>`;
|
| 148 |
const bg=v.source==='bdp'?'badge-bdp':'badge-24h';const lb=v.source==='bdp'?'BDP':'24h';
|
| 149 |
+
h+=`<div class="tiktok-slide" id="tslide-${i}" data-aid="${aid}" data-link="${v.link||''}" data-img="${v.poster||v.img||''}">
|
| 150 |
${vtag}
|
| 151 |
<div class="tiktok-bottom"><span class="badge ${bg}">${lb}</span><p class="tiktok-title">${v.title}</p>
|
| 152 |
+
<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>
|
| 153 |
<div class="tiktok-right">
|
| 154 |
+
<button class="tiktok-right-btn"><div class="icon">👁</div><div class="count" id="vc-${i}">${getV(aid)}</div></button>
|
| 155 |
+
<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>
|
| 156 |
+
<button class="tiktok-right-btn" onclick="event.stopPropagation();shareVid(${i})"><div class="icon">📤</div><div class="count" id="sc-${i}">${getS(aid)}</div></button>
|
| 157 |
</div>
|
| 158 |
<div class="tiktok-unmute" onclick="toggleMute()">🔇</div>
|
| 159 |
<span class="tiktok-counter">${i+1}/${ordered.length}</span>
|
| 160 |
+
<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>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
</div>`;
|
| 162 |
});
|
| 163 |
h+='</div></div>';
|
| 164 |
h+=`<div class="topbar"><span>📋 Danh sách (${ordered.length})</span></div><div class="grid">`;
|
| 165 |
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>`;});
|
| 166 |
h+='</div>';el.innerHTML=h;initFeed();
|
|
|
|
| 167 |
ordered.forEach((v,i)=>{const aid=hid(v.link||v.title);renderVCmts(i,aid);});
|
| 168 |
}
|
| 169 |
+
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);}
|
| 170 |
+
function toggleCmtPanel(i){document.getElementById('cpanel-'+i).classList.toggle('open');}
|
| 171 |
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;}
|
| 172 |
+
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;}
|
| 173 |
|
| 174 |
+
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;}});
|
| 175 |
+
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));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;}
|
| 176 |
+
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);});
|
| 177 |
+
setTimeout(()=>act(0),500);
|
| 178 |
+
slides.forEach(sl=>{const v=sl.querySelector('video');v.addEventListener('click',e=>{e.preventDefault();v.paused?v.play().catch(()=>{}):v.pause();});});}
|
| 179 |
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?'🔇':'🔊');}
|
| 180 |
+
function toggleContain(btn){const sl=btn.closest('.tiktok-slide');sl.classList.toggle('contain-mode');btn.textContent=sl.classList.contains('contain-mode')?'⤢':'⬇';}
|
| 181 |
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));}}
|
| 182 |
|
| 183 |
init();
|