"use strict"; // Nutzername aus dem Pfad /u/. const username = decodeURIComponent(location.pathname.split("/")[2] || ""); document.getElementById("rename-form").addEventListener("submit", async (e) => { e.preventDefault(); const res = await api.post("/user/rename", new FormData(e.target)); if (res.ok) { location.href = `/u/${encodeURIComponent(res.data.username)}`; } else { document.getElementById("rename-msg").textContent = res.data.error || "Umbenennen fehlgeschlagen."; } }); document.getElementById("delete-form").addEventListener("submit", async (e) => { e.preventDefault(); if (!confirm("Konto wirklich unwiderruflich löschen?")) return; const res = await api.post("/user/delete", new FormData(e.target)); if (res.ok) { location.href = "/"; } else { document.getElementById("delete-msg").textContent = res.data.error || "Löschen fehlgeschlagen."; } }); async function init() { const info = await api.get(`/u/${encodeURIComponent(username)}/info`); if (info.error) { document.getElementById("profile-name").textContent = "Nutzer nicht gefunden"; return; } document.getElementById("profile-name").textContent = info.username; const since = new Date(info.created_at * 1000).toLocaleDateString("de-DE"); document.getElementById("profile-info").textContent = `Mitglied seit ${since}`; // Eigene Seite? -> Einstellungen einblenden. const me = await api.get("/user/info"); const isOwner = me.username === info.username; document.getElementById("settings").hidden = !isOwner; createFeed( document.getElementById("feed"), document.getElementById("sentinel"), (page) => `/u/${encodeURIComponent(username)}/feed/${page}` ); } init();