function swap(value) { let postsb = document.getElementById("profilepostbutton"); let aboutb = document.getElementById("profileaboutbutton"); let posts = document.getElementById("posts"); let about = document.getElementById("about"); if (value) { postsb.classList.add("selected") aboutb.classList.remove("selected") about.classList.add("hidden") posts.classList.remove("hidden") } else { postsb.classList.remove("selected") aboutb.classList.add("selected") about.classList.remove("hidden") posts.classList.add("hidden") } } function render() { const html = `
${pfp(data.user.user_id)}
${data.user.firstname + ' ' + data.user.lastname} Joined ${parseDate(new Date(data.user.date))}
${ isself ? `` : ''}
` append(html) const postsh = `
${data.posts.map(p => parsePost(p)).join('')}
` append(postsh) const about = `
About
Name: ${data.user.firstname + ' ' + data.user.lastname} Email: ${data.user.email} Gender: ${data.user.gender} Birthday: ${parseMonth(data.user.month) + ' ' + data.user.day + ', ' + data.user.year} User ID: ${data.user.user_id}
` append(about) } async function logout_button() { const response = await logout() if (response.status != 200) return; location.href = '/login' } var posts = true var isself = false async function load() { var params = {}; for (const [key, value] of new URLSearchParams(location.search)) { params[key] = value } let request = await loadself() if (request.status === 429) { header(false, false) throw new Error("Rate limited"); } data.self = request.json; data.users[data.self.user_id] = data.self let id; header(false, false, data.self.user_id) if (params.id !== undefined && !isNaN(params.id)) { id = parseInt(params.id); } else { id = data.self.user_id } isself = id === data.self.user_id const posts = (await loadusersposts(id)).json data.posts.push(... posts) const batch = [] if (!isself) { batch.push(id) } for (const post of posts) { for(const comment of post.comments) { if (data.users[comment[0]] !== undefined) continue if (batch.includes(comment[0])) continue batch.push(comment[0]) } if (data.users[post.user_id] !== undefined) continue if (batch.includes(post.user_id)) continue batch.push(post.user_id) } const users = batch.length == 0 ? [] : (await loadusers(batch)).json for (const user of users) { data.users[user.user_id] = user } data.user = data.users[id] render() } load()