bep40 commited on
Commit
0084efd
·
verified ·
1 Parent(s): 5b64cea

Upload static/hot_ai_prepend.js

Browse files
Files changed (1) hide show
  1. static/hot_ai_prepend.js +41 -0
static/hot_ai_prepend.js ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Prepend AI topics to hot topics list - ensures they're always visible first
2
+ (function(){
3
+ const AI_TOPICS = [
4
+ 'Công nghệ AI',
5
+ 'World Cup 2026',
6
+ 'Kinh tế Việt Nam',
7
+ 'Bóng đá châu Âu'
8
+ ];
9
+
10
+ // Override loadHotTopics to prepend AI topics
11
+ const origLoadHotTopics = window.loadHotTopics;
12
+ window.loadHotTopics = async function() {
13
+ try {
14
+ const r = await fetch('/api/hot_topics');
15
+ const j = await r.json();
16
+ const topics = j.topics || [];
17
+
18
+ // Prepend AI topics that aren't already in the list
19
+ const prependTopics = AI_TOPICS.filter(ai =>
20
+ !topics.some(t => (t.topic || '').toLowerCase().includes(ai.toLowerCase()))
21
+ ).map(ai => ({
22
+ label: '#' + ai.replace(/\s+/g, ''),
23
+ topic: ai,
24
+ count: 0
25
+ }));
26
+
27
+ const finalTopics = [...prependTopics, ...topics].slice(0, 24);
28
+
29
+ const el = document.getElementById('hot-topics');
30
+ if (el) {
31
+ el.innerHTML = finalTopics.map(t => {
32
+ const topicText = t.topic || t.label.replace(/^#/, '');
33
+ return `<button class="hot-chip" onclick="searchTopic('${topicText.replace(/'/g, "\\'")}')">${esc(t.label)}</button>`;
34
+ }).join('');
35
+ }
36
+ } catch(e) {
37
+ // Fallback to original
38
+ if (origLoadHotTopics) origLoadHotTopics.apply(this, arguments);
39
+ }
40
+ };
41
+ })();