Spaces:
Running
Running
Delete static/_hotfix_topics.js
Browse files- static/_hotfix_topics.js +0 -70
static/_hotfix_topics.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
| 1 |
-
let _htPage=0,_htTopic='';
|
| 2 |
-
async function loadHotTopics(){
|
| 3 |
-
const j=await fetch('/api/hot_topics').then(r=>r.json()).catch(()=>({topics:[]}));
|
| 4 |
-
const el=document.getElementById('hot-topics');if(!el)return;
|
| 5 |
-
const topics=j.topics||[];
|
| 6 |
-
el.innerHTML=topics.slice(0,18).map(t=>{
|
| 7 |
-
const topicText=t.topic||t.label.replace(/^#/,'');
|
| 8 |
-
return`<button class="hot-chip" onclick="searchTopic('${topicText.replace(/'/g,"\\'")}')">${esc(t.label)}</button>`;
|
| 9 |
-
}).join('');
|
| 10 |
-
// AUTO-LOAD: Tổng hợp tin HOT từ TOP 3 hashtag nóng nhất
|
| 11 |
-
if(topics.length>=2){
|
| 12 |
-
loadMultiHashtag(topics.slice(0,3).map(t=>t.topic||t.label.replace(/^#/,'')));
|
| 13 |
-
}else if(topics.length){
|
| 14 |
-
searchTopic(topics[0].topic||topics[0].label.replace(/^#/,''));
|
| 15 |
-
}
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
async function loadMultiHashtag(topicList){
|
| 19 |
-
const box=document.getElementById('hashtag-box');if(!box)return;
|
| 20 |
-
box.innerHTML=`<div class="hashtag-sources"><h3>🔥 Tin HOT tổng hợp</h3><div class="hashtag-loading"><div class="hashtag-spinner"></div>Đang tổng hợp từ ${topicList.length} chủ đề nóng...</div></div>`;
|
| 21 |
-
|
| 22 |
-
// Fetch from multiple hashtags in parallel
|
| 23 |
-
try{
|
| 24 |
-
const results=await Promise.all(topicList.map(topic=>
|
| 25 |
-
fetch(`/api/hashtag/sources?topic=${encodeURIComponent(topic)}&page=0`).then(r=>r.json()).catch(()=>({sources:[]}))
|
| 26 |
-
));
|
| 27 |
-
|
| 28 |
-
// Interleave results from all topics
|
| 29 |
-
const allSources=[];const seen=new Set();
|
| 30 |
-
const maxLen=Math.max(...results.map(r=>(r.sources||[]).length));
|
| 31 |
-
for(let i=0;i<maxLen;i++){
|
| 32 |
-
for(let j=0;j<results.length;j++){
|
| 33 |
-
const src=(results[j].sources||[])[i];
|
| 34 |
-
if(src&&src.url&&!seen.has(src.url)){
|
| 35 |
-
seen.add(src.url);
|
| 36 |
-
src._topic=topicList[j];
|
| 37 |
-
allSources.push(src);
|
| 38 |
-
}
|
| 39 |
-
}
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
if(!allSources.length){box.innerHTML=`<div class="hashtag-sources"><h3>🔥 Tin HOT</h3><div style="color:#888;padding:8px">Đang cập nhật...</div></div>`;return;}
|
| 43 |
-
|
| 44 |
-
let h=`<div class="hashtag-sources"><h3>🔥 Tin HOT tổng hợp <span style="font-size:10px;color:#888">(${allSources.length} bài từ ${topicList.length} chủ đề)</span></h3><div id="ht-list">`;
|
| 45 |
-
allSources.slice(0,12).forEach((s,i)=>{
|
| 46 |
-
h+=`<div class="hashtag-src-item" onclick="readArticle('${esc(s.url)}')"><div class="hashtag-src-img" id="ht-img-${i}"></div><div class="hashtag-src-text"><div class="hashtag-src-title">${esc(s.title)}</div><div class="hashtag-src-via">${esc(s.via||'')} · <span style="color:#f0c040">#${esc(s._topic||'')}</span></div></div></div>`;
|
| 47 |
-
});
|
| 48 |
-
h+=`</div>`;
|
| 49 |
-
// Add individual hashtag buttons
|
| 50 |
-
h+=`<div style="display:flex;gap:4px;flex-wrap:wrap;margin-top:8px">`;
|
| 51 |
-
topicList.forEach(t=>{h+=`<button class="hot-chip" onclick="searchTopic('${t.replace(/'/g,"\\'")}')" style="font-size:10px">#${esc(t)}</button>`;});
|
| 52 |
-
h+=`</div></div>`;
|
| 53 |
-
box.innerHTML=h;
|
| 54 |
-
|
| 55 |
-
// Lazy load images
|
| 56 |
-
allSources.slice(0,12).forEach((s,i)=>{
|
| 57 |
-
if(!s.url)return;
|
| 58 |
-
fetch('/api/article?url='+encodeURIComponent(s.url)).then(r=>r.json()).then(d=>{
|
| 59 |
-
if(d&&(d.og_image||d.img)){const el=document.getElementById('ht-img-'+i);if(el)el.innerHTML=`<img src="${esc(d.og_image||d.img)}" onerror="this.style.display='none'">`;}
|
| 60 |
-
}).catch(()=>{});
|
| 61 |
-
});
|
| 62 |
-
|
| 63 |
-
// Set topic for refresh
|
| 64 |
-
_htTopic=topicList[0];
|
| 65 |
-
}catch(e){
|
| 66 |
-
box.innerHTML=`<div class="hashtag-sources"><h3>🔥 Tin HOT</h3><div style="color:#e74c3c;padding:8px">Lỗi</div></div>`;
|
| 67 |
-
}
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
function searchTopic(topic){if(!topic){topic=document.getElementById('topic-input')?.value.trim();if(!topic){alert('Nhập chủ đề');return;}}document.getElementById('topic-input').value='';_htTopic=topic;_htPage=0;showHashtagSources(topic,0);}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|