Nfs117 commited on
Commit
b9edc57
·
verified ·
1 Parent(s): b20d12e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +611 -18
index.html CHANGED
@@ -1,19 +1,612 @@
1
  <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <!doctype html>
2
+ <html lang="id">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>CosmicApp v1.0 — Standalone</title>
7
+ <meta name="description" content="Prototype aplikasi sosial media client-side dengan penyimpanan lokal, like, komentar, pencarian, hashtag, chat global, dan tema gelap/terang." />
8
+ <style>
9
+ :root{
10
+ --bg:#000; /* dark */
11
+ --panel:#0a0a0a;
12
+ --text:#fff;
13
+ --muted:rgba(255,255,255,.12);
14
+ --subtle:rgba(255,255,255,.6);
15
+ --brand1:#0015ff;
16
+ --brand2:#00ffff;
17
+ --accent:linear-gradient(135deg,var(--brand1),var(--brand2));
18
+ --glass:linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
19
+ --shadow: 0 10px 30px rgba(0,0,0,.35);
20
+ font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
21
+ }
22
+ .light{
23
+ --bg:#f6f7fb;
24
+ --panel:#ffffff;
25
+ --text:#0b1020;
26
+ --muted:rgba(13,23,55,.12);
27
+ --subtle:rgba(13,23,55,.7);
28
+ --shadow: 0 10px 24px rgba(28,34,66,.12);
29
+ }
30
+ *{box-sizing:border-box}
31
+ html,body{height:100%;margin:0;background:var(--bg);color:var(--text)}
32
+ img,video{max-width:100%;height:auto;border-radius:12px}
33
+ a{color:var(--brand2);text-decoration:none}
34
+
35
+ /* Layout */
36
+ .app{display:grid;grid-template-columns:88px 1fr 340px;gap:16px;padding:16px;min-height:100vh}
37
+ @media (max-width:1024px){.app{grid-template-columns:72px 1fr 320px}}
38
+ @media (max-width:900px){.app{grid-template-columns:1fr}}
39
+
40
+ .panel{background:var(--panel);border-radius:16px;border:1px solid var(--muted);box-shadow:var(--shadow)}
41
+
42
+ /* Sidebar */
43
+ .sidebar{padding:12px;display:flex;flex-direction:column;gap:12px;align-items:center}
44
+ .logo{font-weight:800;font-size:14px;letter-spacing:0.6px}
45
+ .nav-btn{width:100%;display:flex;align-items:center;justify-content:center;gap:8px;padding:10px;border-radius:12px;border:1px solid transparent;cursor:pointer}
46
+ .nav-btn:hover{background:rgba(255,255,255,0.05)}
47
+ .icon-circle{width:48px;height:48px;border-radius:12px;background:var(--accent);display:flex;align-items:center;justify-content:center;font-weight:800;color:#000}
48
+ .sep{height:1px;width:100%;background:var(--muted);margin:4px 0}
49
+
50
+ /* Main */
51
+ .main{display:flex;flex-direction:column;gap:16px}
52
+
53
+ .toolbar{display:flex;gap:8px;align-items:center}
54
+ .search{flex:1;display:flex;gap:8px}
55
+ .input{flex:1;background:transparent;border:1px solid var(--muted);padding:10px 12px;border-radius:12px;color:var(--text)}
56
+ .btn{background:linear-gradient(90deg,var(--brand1),var(--brand2));color:#fff;border:none;padding:10px 12px;border-radius:12px;font-weight:700;cursor:pointer}
57
+ .btn.ghost{background:transparent;border:1px solid var(--muted);color:var(--text)}
58
+
59
+ /* Composer */
60
+ .composer{padding:12px;display:flex;flex-direction:column;gap:10px}
61
+ textarea{resize:none;padding:12px;border-radius:12px;border:1px solid var(--muted);background:transparent;color:var(--text);min-height:84px}
62
+ .composer-foot{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
63
+ .avatar{width:56px;height:56px;border-radius:12px;flex-shrink:0;background:var(--accent);display:flex;align-items:center;justify-content:center;font-weight:800;color:#000}
64
+ .composer-row{display:flex;gap:12px;align-items:flex-start}
65
+ .chips{display:flex;gap:8px;flex-wrap:wrap}
66
+ .pill{padding:6px 10px;border-radius:999px;border:1px solid var(--muted);font-size:13px;color:var(--subtle)}
67
+
68
+ .dropzone{border:1px dashed var(--muted);border-radius:12px;padding:10px;display:flex;gap:10px;align-items:center;justify-content:center}
69
+ .media-preview{display:flex;gap:8px;flex-wrap:wrap}
70
+ .media-preview > *{max-width:120px;max-height:96px;border-radius:10px}
71
+
72
+ /* Feed */
73
+ .feed{display:flex;flex-direction:column;gap:12px}
74
+ .post{padding:12px;display:flex;gap:12px}
75
+ .post-body{flex:1;display:flex;flex-direction:column;gap:8px}
76
+ .meta{display:flex;gap:8px;align-items:center;font-size:13px;color:var(--subtle)}
77
+ .post-actions{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
78
+ .small-btn{padding:8px 10px;border-radius:12px;border:1px solid var(--muted);background:transparent;color:var(--text);font-weight:700;cursor:pointer}
79
+ .tag{display:inline-block;padding:2px 6px;border-radius:6px;border:1px solid var(--muted);font-size:12px;margin-right:6px;cursor:pointer}
80
+ .post-media{max-height:480px;overflow:hidden;border-radius:12px}
81
+ .comment{background:rgba(255,255,255,.05);padding:8px;border-radius:10px}
82
+ .comments{display:flex;flex-direction:column;gap:8px}
83
+
84
+ /* Right */
85
+ .right{padding:12px;display:flex;flex-direction:column;gap:12px}
86
+ .row{display:flex;gap:8px;align-items:center}
87
+ .kv{display:flex;justify-content:space-between;align-items:center}
88
+
89
+ /* Chat */
90
+ .chat{display:flex;flex-direction:column;height:360px;border-radius:12px;overflow:hidden}
91
+ .chat-messages{flex:1;padding:8px;overflow:auto;display:flex;flex-direction:column;gap:8px;background:rgba(0,0,0,.06)}
92
+ .chat-input{display:flex;gap:8px;padding:8px;border-top:1px solid var(--muted)}
93
+
94
+ /* Utilities */
95
+ .muted{color:var(--subtle);font-size:13px}
96
+ .hidden{display:none!important}
97
+ </style>
98
+ </head>
99
+ <body>
100
+ <div class="app">
101
+ <!-- SIDEBAR -->
102
+ <aside class="sidebar panel" aria-label="Sidebar">
103
+ <div class="logo">CosmicApp</div>
104
+ <div class="nav-btn" id="homeBtn" title="Beranda"><div class="icon-circle">CA</div></div>
105
+ <button class="nav-btn" id="exploreBtn" title="Explore">🔎</button>
106
+ <button class="nav-btn" id="notifBtn" title="Notifikasi">🔔</button>
107
+ <div class="sep"></div>
108
+ <button class="nav-btn" id="themeBtn" title="Ganti Tema">🌓</button>
109
+ <div class="sep"></div>
110
+ <div class="pill muted">Tema: <span id="themeLabel">Gelap</span></div>
111
+ </aside>
112
+
113
+ <!-- MAIN -->
114
+ <main class="main">
115
+ <!-- Toolbar -->
116
+ <div class="toolbar">
117
+ <div class="search">
118
+ <input id="searchInput" class="input" placeholder="Cari postingan, #hashtag, atau @user" />
119
+ <button id="clearSearch" class="btn ghost" aria-label="Bersihkan pencarian">Clear</button>
120
+ </div>
121
+ <button id="newPostBtn" class="btn">Posting</button>
122
+ </div>
123
+
124
+ <!-- Composer -->
125
+ <section class="panel composer" aria-label="Buat postingan">
126
+ <div class="composer-row">
127
+ <div class="avatar" id="composerAvatar">UA</div>
128
+ <textarea id="postText" placeholder="Apa yang sedang terjadi? (teks, #hashtag, @mention)" maxlength="2000"></textarea>
129
+ </div>
130
+ <div class="dropzone" id="dropzone">Tarik & letakkan media di sini atau
131
+ <label class="small-btn" for="mediaInput">Pilih Media</label>
132
+ <input id="mediaInput" type="file" accept="image/*,video/*,audio/*" multiple hidden />
133
+ </div>
134
+ <div id="mediaPreview" class="media-preview"></div>
135
+ <div class="composer-foot">
136
+ <div class="chips">
137
+ <span class="pill">Maks 4 media</span>
138
+ <span class="pill">Gambar diperkecil otomatis</span>
139
+ <span class="pill">Video/Audio tidak tersimpan permanen (demo)</span>
140
+ </div>
141
+ <div style="flex:1"></div>
142
+ <button id="postBtn" class="btn">Kirim</button>
143
+ </div>
144
+ </section>
145
+
146
+ <!-- Feed -->
147
+ <section class="feed" id="feed" aria-live="polite"></section>
148
+ </main>
149
+
150
+ <!-- RIGHT COLUMN -->
151
+ <aside class="right panel">
152
+ <div class="kv"><strong>Profil</strong><button class="small-btn" id="resetProfileBtn">Reset</button></div>
153
+ <div class="row">
154
+ <div class="avatar" id="profileAvatar">UA</div>
155
+ <div style="flex:1;display:flex;flex-direction:column;gap:6px">
156
+ <input class="input" id="displayName" placeholder="Nama (max 30)" maxlength="30" />
157
+ <input class="input" id="avatarInitials" placeholder="Inisial (max 3)" maxlength="3" />
158
+ </div>
159
+ </div>
160
+ <div class="row">
161
+ <button class="btn" id="saveProfileBtn">Simpan</button>
162
+ <button class="small-btn" id="newIdBtn" title="Buat ID lokal baru">Ganti ID</button>
163
+ </div>
164
+
165
+ <div>
166
+ <div class="kv"><strong>Chat Global</strong><span class="muted" id="chatCount">0</span></div>
167
+ <div class="chat panel" style="border:none">
168
+ <div class="chat-messages" id="chatMessages"></div>
169
+ <div class="chat-input">
170
+ <input class="input" id="chatInput" placeholder="Ketik pesan..." />
171
+ <button class="btn" id="chatSend">Kirim</button>
172
+ </div>
173
+ </div>
174
+ </div>
175
+
176
+ <div>
177
+ <div class="kv"><strong>Aktivitas</strong><button class="small-btn" id="clearActivity">Bersihkan</button></div>
178
+ <div id="activityLog" class="muted">Tidak ada aktivitas</div>
179
+ </div>
180
+
181
+ <div>
182
+ <div class="kv"><strong>Notifikasi</strong><button class="small-btn" id="clearNotif">Bersihkan</button></div>
183
+ <div id="notifList" class="muted">Belum ada notifikasi</div>
184
+ </div>
185
+ </aside>
186
+ </div>
187
+
188
+ <!-- Templates -->
189
+ <template id="postTemplate">
190
+ <article class="panel post">
191
+ <div class="avatar post-avatar">XX</div>
192
+ <div class="post-body">
193
+ <div class="meta"><strong class="post-name">Nama</strong><span class="muted">•</span><span class="muted post-time">Baru saja</span></div>
194
+ <div class="post-text">Teks</div>
195
+ <div class="post-tags"></div>
196
+ <div class="post-media"></div>
197
+ <div class="post-actions">
198
+ <button class="small-btn likeBtn">👍 <span class="likeCount">0</span></button>
199
+ <button class="small-btn replyBtn">💬</button>
200
+ <button class="small-btn editPostBtn">✏️</button>
201
+ <button class="small-btn deletePostBtn">🗑️</button>
202
+ </div>
203
+ <div class="comments"></div>
204
+ <div class="add-comment" style="display:flex;gap:8px;margin-top:8px">
205
+ <input class="input commentInput" placeholder="Tulis komentar..." />
206
+ <button class="small-btn postCommentBtn">Kirim</button>
207
+ </div>
208
+ </div>
209
+ </article>
210
+ </template>
211
+
212
+ <script>
213
+ // =====================
214
+ // UTIL & STORAGE LAYER
215
+ // =====================
216
+ const store = {
217
+ get(k, def){ try{ return JSON.parse(localStorage.getItem(k)) ?? def }catch{ return def } },
218
+ set(k, v){ localStorage.setItem(k, JSON.stringify(v)) },
219
+ del(k){ localStorage.removeItem(k) }
220
+ }
221
+ const uid = () => Math.random().toString(36).slice(2)+Date.now().toString(36);
222
+ const nowText = () => new Date().toLocaleString();
223
+ const el = sel => document.querySelector(sel);
224
+
225
+ function escapeHTML(str){ return str.replace(/[&<>"']/g, m=>({"&":"&amp;","<":"&lt;",
226
+ ">":"&gt;","\"":"&quot;","'":"&#39;"}[m])) }
227
+
228
+ // very light bad-words filter (demo only)
229
+ const BAD_WORDS = [/\b(kontol|anjing|goblok|tolol)\b/gi];
230
+ function filterBadWords(text){ let t=text; BAD_WORDS.forEach(rx=>{ t=t.replace(rx, m=>"*".repeat(m.length)) }); return t }
231
+
232
+ // ==============
233
+ // APP STATE
234
+ // ==============
235
+ const STATE = {
236
+ user: store.get('cosmic.user', { id: uid(), name:'User Astro', initials:'UA' }),
237
+ theme: store.get('cosmic.theme', 'dark'),
238
+ posts: store.get('cosmic.posts', []),
239
+ chat: store.get('cosmic.chat', []),
240
+ notif: store.get('cosmic.notif', [])
241
+ }
242
+
243
+ // =====================
244
+ // THEME
245
+ // =====================
246
+ function applyTheme(){
247
+ if(STATE.theme==='light') document.body.classList.add('light'); else document.body.classList.remove('light');
248
+ el('#themeLabel').textContent = STATE.theme==='light' ? 'Terang' : 'Gelap';
249
+ store.set('cosmic.theme', STATE.theme);
250
+ }
251
+
252
+ // =====================
253
+ // PROFILE
254
+ // =====================
255
+ function applyProfileUI(){
256
+ el('#profileAvatar').textContent = STATE.user.initials;
257
+ el('#composerAvatar').textContent = STATE.user.initials;
258
+ el('#displayName').value = STATE.user.name;
259
+ el('#avatarInitials').value = STATE.user.initials;
260
+ }
261
+ function saveProfile(){
262
+ STATE.user.name = (el('#displayName').value || 'User Astro').slice(0,30);
263
+ STATE.user.initials = (el('#avatarInitials').value || 'UA').toUpperCase().slice(0,3);
264
+ store.set('cosmic.user', STATE.user);
265
+ applyProfileUI();
266
+ setActivity('Profil diperbarui — '+nowText());
267
+ renderAll();
268
+ }
269
+
270
+ // =====================
271
+ // POSTS
272
+ // =====================
273
+ const MAX_MEDIA = 4;
274
+
275
+ function parseTagsAndMentions(text){
276
+ const tags = Array.from(text.matchAll(/#([a-z0-9_]{1,32})/gi)).map(m=>m[1].toLowerCase());
277
+ const mentions = Array.from(text.matchAll(/@([a-z0-9_]{1,32})/gi)).map(m=>m[1]);
278
+ return {tags:[...new Set(tags)], mentions:[...new Set(mentions)]};
279
+ }
280
+
281
+ function fileToImageDataURL(file, maxDim=1280){
282
+ return new Promise((resolve)=>{
283
+ const fr = new FileReader();
284
+ fr.onload = () => {
285
+ const img = new Image();
286
+ img.onload = () => {
287
+ const canvas = document.createElement('canvas');
288
+ let {width, height} = img;
289
+ const scale = Math.min(1, maxDim/Math.max(width,height));
290
+ width = Math.round(width*scale); height=Math.round(height*scale);
291
+ canvas.width = width; canvas.height = height;
292
+ const ctx = canvas.getContext('2d');
293
+ ctx.drawImage(img,0,0,width,height);
294
+ resolve(canvas.toDataURL('image/jpeg', .85));
295
+ };
296
+ img.src = fr.result;
297
+ };
298
+ fr.readAsDataURL(file);
299
+ });
300
+ }
301
+
302
+ async function collectMedia(files){
303
+ const out=[]; const fs = Array.from(files).slice(0,MAX_MEDIA);
304
+ for(const f of fs){
305
+ if(f.type.startsWith('image/')){
306
+ const data = await fileToImageDataURL(f);
307
+ out.push({kind:'image', data, name:f.name});
308
+ } else if(f.type.startsWith('video/')){
309
+ // for demo, keep only name+type; will not persist across reload
310
+ const url = URL.createObjectURL(f);
311
+ out.push({kind:'video', url, name:f.name});
312
+ } else if(f.type.startsWith('audio/')){
313
+ const url = URL.createObjectURL(f);
314
+ out.push({kind:'audio', url, name:f.name});
315
+ }
316
+ }
317
+ return out;
318
+ }
319
+
320
+ function persistPosts(){ store.set('cosmic.posts', STATE.posts) }
321
+
322
+ function addPost(text, media){
323
+ const safeText = filterBadWords(text).slice(0,2000);
324
+ const {tags, mentions} = parseTagsAndMentions(safeText);
325
+ const post = {
326
+ id: uid(),
327
+ authorId: STATE.user.id,
328
+ name: STATE.user.name,
329
+ initials: STATE.user.initials,
330
+ time: nowText(),
331
+ text: safeText,
332
+ tags, mentions,
333
+ media, // images persisted; video/audio session-only
334
+ likes: [],
335
+ comments: []
336
+ };
337
+ STATE.posts.unshift(post);
338
+ persistPosts();
339
+ setActivity('Postingan dikirim — '+nowText());
340
+ notifyMentions(post);
341
+ renderAll();
342
+ }
343
+
344
+ function updatePost(id, newText){
345
+ const p = STATE.posts.find(p=>p.id===id); if(!p) return;
346
+ const safeText = filterBadWords(newText).slice(0,2000);
347
+ const {tags, mentions} = parseTagsAndMentions(safeText);
348
+ p.text=safeText; p.tags=tags; p.mentions=mentions; p.time=nowText();
349
+ persistPosts();
350
+ setActivity('Postingan diedit — '+nowText());
351
+ renderAll();
352
+ }
353
+
354
+ function deletePost(id){
355
+ STATE.posts = STATE.posts.filter(p=>p.id!==id);
356
+ persistPosts();
357
+ setActivity('Postingan dihapus — '+nowText());
358
+ renderAll();
359
+ }
360
+
361
+ function toggleLike(post){
362
+ const i = post.likes.indexOf(STATE.user.id);
363
+ if(i===-1) post.likes.push(STATE.user.id); else post.likes.splice(i,1);
364
+ persistPosts();
365
+ }
366
+
367
+ function addComment(post, text){
368
+ const safe = filterBadWords(text).slice(0,1000);
369
+ post.comments.push({ id: uid(), authorId: STATE.user.id, author: STATE.user.name, text: safe, time: nowText() });
370
+ persistPosts();
371
+ if(post.authorId!==STATE.user.id){
372
+ STATE.notif.unshift({ id: uid(), time: nowText(), text: `${STATE.user.name} mengomentari postinganmu: "${safe.slice(0,60)}"`});
373
+ store.set('cosmic.notif', STATE.notif);
374
+ renderNotif();
375
+ }
376
+ }
377
+
378
+ // ==============
379
+ // NOTIFICATIONS
380
+ // ==============
381
+ function notifyMentions(post){
382
+ if(post.mentions.length){
383
+ STATE.notif.unshift({ id: uid(), time: nowText(), text: `${post.name} menyebut ${post.mentions.map(m=>"@"+m).join(', ')} di sebuah postingan.` });
384
+ store.set('cosmic.notif', STATE.notif);
385
+ }
386
+ }
387
+ function renderNotif(){
388
+ const list = el('#notifList');
389
+ if(!STATE.notif.length){ list.textContent='Belum ada notifikasi'; return }
390
+ list.innerHTML='';
391
+ STATE.notif.slice(0,30).forEach(n=>{
392
+ const div=document.createElement('div');
393
+ div.className='comment';
394
+ div.textContent = `${n.time} — ${n.text}`;
395
+ list.appendChild(div);
396
+ })
397
+ }
398
+
399
+ // ==============
400
+ // RENDER FEED
401
+ // ==============
402
+ const feedEl = el('#feed');
403
+
404
+ function renderFeed(){
405
+ const q = el('#searchInput').value.trim().toLowerCase();
406
+ let filtered = STATE.posts;
407
+ if(q){
408
+ if(q.startsWith('#')){
409
+ const tag = q.slice(1);
410
+ filtered = filtered.filter(p=>p.tags.includes(tag));
411
+ } else if(q.startsWith('@')){
412
+ const who = q.slice(1);
413
+ filtered = filtered.filter(p=>p.mentions.includes(who) || p.name.toLowerCase().includes(who));
414
+ } else {
415
+ filtered = filtered.filter(p=>p.text.toLowerCase().includes(q) || p.name.toLowerCase().includes(q));
416
+ }
417
+ }
418
+
419
+ feedEl.innerHTML='';
420
+ if(filtered.length===0){
421
+ const empty = document.createElement('div');
422
+ empty.className='muted';
423
+ empty.textContent = 'Belum ada postingan. Buat postingan pertama!';
424
+ feedEl.appendChild(empty);
425
+ return;
426
+ }
427
+
428
+ const tpl = el('#postTemplate');
429
+ filtered.forEach(post=>{
430
+ const node = tpl.content.cloneNode(true);
431
+ const art = node.querySelector('.post');
432
+ art.dataset.id = post.id;
433
+ node.querySelector('.post-avatar').textContent = post.initials;
434
+ node.querySelector('.post-name').textContent = post.name;
435
+ node.querySelector('.post-time').textContent = post.time;
436
+
437
+ // text with simple linkify for tags/mentions (safe)
438
+ const ptext = node.querySelector('.post-text');
439
+ ptext.innerHTML = escapeHTML(post.text)
440
+ .replace(/#([a-z0-9_]{1,32})/gi, '<span class="tag" data-tag="$1">#$1</span>')
441
+ .replace(/@([a-z0-9_]{1,32})/gi, '<span class="tag" data-mention="$1">@$1</span>');
442
+
443
+ // tags list (clickable)
444
+ const tagWrap = node.querySelector('.post-tags');
445
+ post.tags.forEach(t=>{ const s=document.createElement('span'); s.className='tag'; s.textContent = '#'+t; s.addEventListener('click', ()=>{el('#searchInput').value='#'+t; renderFeed()}); tagWrap.appendChild(s) });
446
+
447
+ // media
448
+ const mediaWrap = node.querySelector('.post-media');
449
+ post.media.forEach(m=>{
450
+ let elx;
451
+ if(m.kind==='image'){ elx = document.createElement('img'); elx.src = m.data }
452
+ else if(m.kind==='video'){ elx = document.createElement('video'); elx.src=m.url; elx.controls=true }
453
+ else { elx = document.createElement('audio'); elx.src=m.url; elx.controls=true }
454
+ mediaWrap.appendChild(elx);
455
+ })
456
+
457
+ // likes
458
+ const likeBtn = node.querySelector('.likeBtn');
459
+ const likeCount = node.querySelector('.likeCount');
460
+ likeCount.textContent = post.likes.length;
461
+ const refreshLikeState = ()=>{
462
+ const liked = post.likes.includes(STATE.user.id);
463
+ likeBtn.style.borderColor = liked? 'transparent' : 'var(--muted)';
464
+ likeBtn.style.background = liked? 'var(--accent)' : 'transparent';
465
+ likeBtn.style.color = liked? '#000' : 'var(--text)';
466
+ }
467
+ refreshLikeState();
468
+ likeBtn.addEventListener('click', ()=>{ toggleLike(post); likeCount.textContent = post.likes.length; refreshLikeState(); })
469
+
470
+ // comments
471
+ const commentsWrap = node.querySelector('.comments');
472
+ post.comments.forEach(c=>{
473
+ const cdiv=document.createElement('div'); cdiv.className='comment';
474
+ cdiv.textContent = `${c.author}: ${c.text}`;
475
+ commentsWrap.appendChild(cdiv);
476
+ })
477
+
478
+ // actions
479
+ node.querySelector('.replyBtn').addEventListener('click', ()=>{ art.querySelector('.commentInput').focus() })
480
+ node.querySelector('.postCommentBtn').addEventListener('click', ()=>{
481
+ const input = art.querySelector('.commentInput');
482
+ if(!input.value.trim()) return;
483
+ addComment(post, input.value.trim());
484
+ input.value='';
485
+ renderFeed();
486
+ setActivity('Komentar ditambahkan — '+nowText());
487
+ })
488
+ node.querySelector('.deletePostBtn').addEventListener('click', ()=>{
489
+ if(post.authorId!==STATE.user.id){ alert('Hanya pembuat postingan yang bisa menghapus.'); return }
490
+ if(confirm('Hapus postingan?')) deletePost(post.id);
491
+ })
492
+ node.querySelector('.editPostBtn').addEventListener('click', ()=>{
493
+ if(post.authorId!==STATE.user.id){ alert('Hanya pembuat postingan yang bisa mengedit.'); return }
494
+ const nt = prompt('Edit postingan:', post.text);
495
+ if(nt!==null) updatePost(post.id, nt);
496
+ })
497
+
498
+ // clickable tag/mention inside text
499
+ ptext.querySelectorAll('[data-tag]').forEach(s=> s.addEventListener('click', ()=>{ el('#searchInput').value = '#'+s.dataset.tag; renderFeed() }))
500
+ ptext.querySelectorAll('[data-mention]').forEach(s=> s.addEventListener('click', ()=>{ el('#searchInput').value = '@'+s.dataset.mention; renderFeed() }))
501
+
502
+ feedEl.appendChild(node);
503
+ })
504
+ }
505
+
506
+ // ==============
507
+ // COMPOSER & MEDIA
508
+ // ==============
509
+ const mediaPreview = el('#mediaPreview');
510
+ const mediaInput = el('#mediaInput');
511
+ const dropzone = el('#dropzone');
512
+ let pendingFiles = [];
513
+
514
+ function showPreview(items){
515
+ mediaPreview.innerHTML='';
516
+ items.forEach(m=>{
517
+ let v;
518
+ if(m.kind==='image'){ v=document.createElement('img'); v.src=m.data }
519
+ else if(m.kind==='video'){ v=document.createElement('video'); v.src=m.url; v.controls=true }
520
+ else { v=document.createElement('audio'); v.src=m.url; v.controls=true }
521
+ mediaPreview.appendChild(v);
522
+ })
523
+ }
524
+
525
+ mediaInput.addEventListener('change', async ()=>{
526
+ const media = await collectMedia(mediaInput.files);
527
+ pendingFiles = media.slice(0,MAX_MEDIA);
528
+ showPreview(pendingFiles);
529
+ })
530
+
531
+ ;['dragenter','dragover'].forEach(ev=> dropzone.addEventListener(ev, (e)=>{ e.preventDefault(); dropzone.style.background='rgba(255,255,255,.06)' }))
532
+ ;['dragleave','drop'].forEach(ev=> dropzone.addEventListener(ev, (e)=>{ e.preventDefault(); dropzone.style.background='transparent' }))
533
+ dropzone.addEventListener('drop', async (e)=>{
534
+ const dt = e.dataTransfer; if(!dt) return;
535
+ const media = await collectMedia(dt.files);
536
+ pendingFiles = media.slice(0,MAX_MEDIA);
537
+ showPreview(pendingFiles);
538
+ })
539
+
540
+ el('#postBtn').addEventListener('click', ()=>{
541
+ const text = el('#postText').value.trim();
542
+ if(!text && pendingFiles.length===0){ alert('Isi teks atau tambahkan media.'); return }
543
+ addPost(text, pendingFiles);
544
+ el('#postText').value=''; pendingFiles=[]; showPreview([]); mediaInput.value='';
545
+ })
546
+
547
+ // new-post shortcut
548
+ el('#newPostBtn').addEventListener('click', ()=> el('#postText').focus());
549
+
550
+ // ==============
551
+ // SEARCH
552
+ // ==============
553
+ el('#searchInput').addEventListener('input', renderFeed);
554
+ el('#clearSearch').addEventListener('click', ()=>{ el('#searchInput').value=''; renderFeed() })
555
+
556
+ // ==============
557
+ // CHAT
558
+ // ==============
559
+ const chatMessages = el('#chatMessages');
560
+ const chatInput = el('#chatInput');
561
+ function renderChat(){
562
+ chatMessages.innerHTML='';
563
+ STATE.chat.slice(-100).forEach(m=>{
564
+ const div=document.createElement('div'); div.className='comment';
565
+ div.textContent = `${m.time} — ${m.name}: ${m.text}`;
566
+ chatMessages.appendChild(div);
567
+ });
568
+ el('#chatCount').textContent = STATE.chat.length;
569
+ chatMessages.scrollTop = chatMessages.scrollHeight;
570
+ }
571
+ function sendChat(){
572
+ const t = chatInput.value.trim(); if(!t) return;
573
+ const safe = filterBadWords(t).slice(0,500);
574
+ STATE.chat.push({ id: uid(), user: STATE.user.id, name: STATE.user.name, text: safe, time: nowText() });
575
+ store.set('cosmic.chat', STATE.chat);
576
+ chatInput.value='';
577
+ renderChat();
578
+ setActivity('Pesan chat dikirim — '+nowText());
579
+ }
580
+ el('#chatSend').addEventListener('click', sendChat);
581
+ chatInput.addEventListener('keydown', e=>{ if(e.key==='Enter'){ e.preventDefault(); sendChat() } })
582
+
583
+ // ==============
584
+ // NOTIF UI & ACTIVITY
585
+ // ==============
586
+ function setActivity(text){ el('#activityLog').textContent = text }
587
+ el('#clearActivity').addEventListener('click', ()=> el('#activityLog').textContent='Tidak ada aktivitas')
588
+ el('#clearNotif').addEventListener('click', ()=>{ STATE.notif=[]; store.set('cosmic.notif', STATE.notif); renderNotif(); })
589
+
590
+ // ==============
591
+ // THEME & NAV
592
+ // ==============
593
+ el('#themeBtn').addEventListener('click', ()=>{ STATE.theme = STATE.theme==='light' ? 'dark' : 'light'; applyTheme() })
594
+ el('#homeBtn').addEventListener('click', ()=>{ el('#searchInput').value=''; renderFeed() })
595
+ el('#notifBtn').addEventListener('click', ()=>{ el('#notifList').scrollIntoView({behavior:'smooth'}) })
596
+ el('#exploreBtn').addEventListener('click', ()=>{ el('#searchInput').value='#'; el('#searchInput').focus(); renderFeed() })
597
+
598
+ // ==============
599
+ // PROFILE UI
600
+ // ==============
601
+ el('#saveProfileBtn').addEventListener('click', saveProfile)
602
+ el('#resetProfileBtn').addEventListener('click', ()=>{ STATE.user={ id:STATE.user.id, name:'User Astro', initials:'UA' }; store.set('cosmic.user', STATE.user); applyProfileUI(); renderAll(); setActivity('Profil direset — '+nowText()) })
603
+ el('#newIdBtn').addEventListener('click', ()=>{ if(confirm('Buat ID lokal baru? Data postingan lama tetap tersimpan, namun like/kepemilikan mengikuti ID baru.')){ STATE.user.id=uid(); store.set('cosmic.user', STATE.user); setActivity('ID diganti — '+nowText()) }})
604
+
605
+ // ==============
606
+ // INIT
607
+ // ==============
608
+ function renderAll(){ applyProfileUI(); renderFeed(); renderChat(); renderNotif(); }
609
+ (function init(){ applyTheme(); applyProfileUI(); renderAll(); setActivity('Siap — '+nowText()) })();
610
+ </script>
611
+ </body>
612
+ </html>