MS

MOB SOCIALTY THE YOUTUBER FT. MESSY MOB

not signed in

Sign in to the Mob

Timeline

Loading…
let toastTimer; function toast(msg) { const t = document.getElementById("toast"); t.textContent = msg; t.dataset.on = "1"; clearTimeout(toastTimer); toastTimer = setTimeout(() => t.dataset.on = "0", 2400); } function initials(name) { return String(name || "?").trim().split(/\s+/).slice(0,2).map(w => w[0] || "").join("").toUpperCase(); } function ago(iso) { const s = Math.max(0, (Date.now() - new Date(iso).getTime()) / 1000); if (s < 60) return "just now"; if (s < 3600) return Math.floor(s/60) + "m"; if (s < 86400) return Math.floor(s/3600) + "h"; return Math.floor(s/86400) + "d"; } async function loadProfile() { try { const r = await fetch(`${API}/api/mob/profile?id=${encodeURIComponent(ME)}`, {cache:"no-store"}); const j = await r.json(); if (j.profile) { document.getElementById("name").value = j.profile.displayName || ""; document.getElementById("bio").value = j.profile.bio || ""; document.getElementById("whoami").textContent = j.profile.displayName || "Mob Member"; document.getElementById("joinstamp").textContent = "joined " + new Date(j.profile.joinedAt).toLocaleDateString(); } } catch { document.getElementById("whoami").textContent = "offline"; } } async function loadFeed() { const host = document.getElementById("feed"); try { const r = await fetch(`${API}/api/mob/feed?limit=20`, {cache:"no-store"}); const j = await r.json(); if (!j.items || !j.items.length) { host.innerHTML = '
No posts yet. Be the first.
'; return; } host.innerHTML = j.items.map(p => { const mine = p.reactions || {}; const btn = (kind, label) => ``; return `
${initials(p.authorName)}
${escapeHtml(p.authorName)}
${ago(p.createdAt)}
${escapeHtml(p.text)}
${btn("like","👍")} ${btn("fire","🔥")} ${btn("laugh","😂")} ${btn("wow","😮")}
`; }).join(""); host.querySelectorAll("button.react").forEach(b => { b.onclick = () => react(b.dataset.post, b.dataset.kind); }); } catch { host.innerHTML = '
Could not load the timeline.
'; } } function escapeHtml(s) { return String(s == null ? "" : s).replace(/[&<>"']/g, c => ({ "&":"&", "<":"<", ">":">", '"':""", "'":"'" }[c])); } async function react(postId, kind) { try { const r = await fetch(`${API}/api/mob/react`, { method:"POST", headers:{"content-type":"application/json"}, body: JSON.stringify({ id: ME, postId, kind }) }); if (r.status === 429) return toast("Slow down a moment."); await loadFeed(); } catch { toast("Could not react."); } } document.getElementById("text").addEventListener("input", e => { document.getElementById("charcount").textContent = e.target.value.length + " / 600"; }); document.getElementById("saveProfile").onclick = async () => { const body = { id: ME, displayName: document.getElementById("name").value.trim(), bio: document.getElementById("bio").value.trim() }; try { const r = await fetch(`${API}/api/mob/profile`, { method:"POST", headers:{"content-type":"application/json"}, body: JSON.stringify(body) }); const j = await r.json(); if (j.ok) { document.getElementById("whoami").textContent = j.profile.displayName; toast("Profile saved"); } else toast(j.error || "Could not save."); } catch { toast("Could not save."); } }; document.getElementById("post").onclick = async () => { const el = document.getElementById("text"); const text = el.value.trim(); if (!text) return toast("Write something first."); const btn = document.getElementById("post"); btn.disabled = true; try { const r = await fetch(`${API}/api/mob/post`, { method:"POST", headers:{"content-type":"application/json"}, body: JSON.stringify({ id: ME, text }) }); if (r.status === 429) { toast("Give it a moment before posting again."); return; } const j = await r.json(); if (j.ok) { el.value = ""; document.getElementById("charcount").textContent = "0 / 600"; toast("Posted"); await loadFeed(); } else toast(j.error || "Could not post."); } catch { toast("Could not post."); } finally { btn.disabled = false; } }; loadProfile(); loadFeed(); setInterval(loadFeed, 15000);