bep40 commited on
Commit
2ef06e7
·
verified ·
1 Parent(s): 36390e5

Upload static/wall_24h_patch.js

Browse files
Files changed (1) hide show
  1. static/wall_24h_patch.js +83 -0
static/wall_24h_patch.js ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Wall 24h Patch - Fix missing Short AI/Tường AI
3
+ * Load after app_v2.js
4
+ */
5
+ (function() {
6
+ const MAX_AGE_MS = 86400000; // 24h
7
+
8
+ function filter24h(posts) {
9
+ const now = Date.now();
10
+ return posts.filter(p => {
11
+ const created = p.created || 0;
12
+ const ts = created > 1000000000000 ? created : created * 1000;
13
+ return (now - ts) <= MAX_AGE_MS;
14
+ });
15
+ }
16
+
17
+ function renderWall24h() {
18
+ if (!window._wallPosts || !window._wallPosts.length) return;
19
+
20
+ const posts = filter24h(window._wallPosts).slice(0, 20);
21
+ if (!posts.length) return;
22
+
23
+ const homeEl = document.getElementById('view-home');
24
+ if (!homeEl) return;
25
+
26
+ // Short AI section
27
+ const aiShorts = posts.filter(p => p.video);
28
+ if (aiShorts.length) {
29
+ let wrap = document.getElementById('short-ai-section');
30
+ if (wrap) wrap.remove();
31
+
32
+ wrap = document.createElement('div');
33
+ wrap.className = 'slider-wrap';
34
+ wrap.id = 'short-ai-section';
35
+ let h = '<div class="slider-header"><span class="slider-label">🎬 Short AI (24h)</span></div><div class="slider-track">';
36
+ aiShorts.forEach((p, i) => {
37
+ h += `<div class="slider-item shorts-item" onclick="openShortAIFeed(${i})"><div class="slider-thumb shorts-thumb"><video src="${p.video}" muted preload="metadata"></video><div class="card-play">▶</div></div><div class="slider-title">${p.title}</div></div>`;
38
+ });
39
+ h += '</div>';
40
+ wrap.innerHTML = h;
41
+ homeEl.insertBefore(wrap, homeEl.firstChild);
42
+ }
43
+
44
+ // AI Wall section
45
+ wrap = document.getElementById('ai-wall-wrap');
46
+ if (wrap) wrap.remove();
47
+
48
+ wrap = document.createElement('div');
49
+ wrap.className = 'slider-wrap';
50
+ wrap.id = 'ai-wall-wrap';
51
+ let h = '<div class="slider-header"><span class="slider-label">🧱 Tường AI (24h)</span></div><div class="slider-track" id="ai-wall-track">';
52
+ posts.forEach((p, i) => {
53
+ h += `<div class="wall-item" id="wall-item-${p.id}"><div class="wall-thumb">${p.img ? `<img src="${p.img}">` : (p.video ? `<video src="${p.video}" muted></video>` : '')}</div><div class="wall-title">${p.title}</div></div>`;
54
+ });
55
+ h += '</div>';
56
+ wrap.innerHTML = h;
57
+ homeEl.appendChild(wrap);
58
+ }
59
+
60
+ // Hook into prependWallPost
61
+ const origPrepend = window.prependWallPost;
62
+ if (origPrepend) {
63
+ window.prependWallPost = function(post) {
64
+ const ts = post.created > 1000000000000 ? post.created : (post.created || Date.now()) * 1000;
65
+ if ((Date.now() - ts) > MAX_AGE_MS) return;
66
+ origPrepend.call(this, post);
67
+ };
68
+ }
69
+
70
+ // Run periodically to catch wall updates
71
+ let wallPatched = false;
72
+ const wallObserver = setInterval(() => {
73
+ if (window._wallPosts && window._wallPosts.length > 0 && !wallPatched) {
74
+ renderWall24h();
75
+ wallPatched = true;
76
+ }
77
+ }, 2000);
78
+
79
+ // Stop after 2 minutes
80
+ setTimeout(() => clearInterval(wallObserver), 120000);
81
+
82
+ console.log('[Wall 24h Patch] Loaded');
83
+ })();