88 lines
2.6 KiB
JavaScript
88 lines
2.6 KiB
JavaScript
|
function render() {
|
||
|
const html = `
|
||
|
<div id="top">
|
||
|
<div id="banner">
|
||
|
<div>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
<div id="info">
|
||
|
<div class="face">
|
||
|
|
||
|
</div>
|
||
|
<div class="infodata">
|
||
|
<span class="bold ltext">${data.user.first + ' ' + data.user.last}</span>
|
||
|
<span class="gtext">Joined ${parseDate(new Date(data.user.date))}</span>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="fullline" style="width: 80em; margin-bottom: 0;"></div>
|
||
|
<div class="profilebuttons">
|
||
|
<button class="${posts ? 'selected' : ''}" onclick="posts = true; render()">
|
||
|
Posts
|
||
|
</button>
|
||
|
<button class="${posts ? '' : 'selected'}" onclick="posts = false; render()">
|
||
|
About
|
||
|
</button>
|
||
|
</div>
|
||
|
</div>
|
||
|
`
|
||
|
|
||
|
add(html, 'top')
|
||
|
|
||
|
const postsh = `
|
||
|
<div id="posts" class="${posts ? '' : 'hidden'}">
|
||
|
${data.posts.map(p => parsePost(p)).join('')}
|
||
|
</div>
|
||
|
`
|
||
|
|
||
|
add(postsh, 'posts')
|
||
|
|
||
|
const about = `
|
||
|
<div id="about" class="post ${posts ? 'hidden' : ''}">
|
||
|
<span class="bold ltext">About</span>
|
||
|
<div class="data">
|
||
|
<span class="gtext bold">Name: ${data.user.first + ' ' + data.user.last}</span>
|
||
|
<span class="gtext bold">Email: ${data.user.email}</span>
|
||
|
<span class="gtext bold">Gender: ${data.user.gender}</span>
|
||
|
<span class="gtext bold">Birthday: ${data.user.month + ' ' + data.user.day + ', ' + data.user.year}</span>
|
||
|
<span class="gtext bold">User ID: ${data.user.id}</span>
|
||
|
</div>
|
||
|
</div>
|
||
|
`
|
||
|
|
||
|
add(about, 'about')
|
||
|
}
|
||
|
|
||
|
var posts = true
|
||
|
|
||
|
async function load() {
|
||
|
header(false, false)
|
||
|
|
||
|
var params = {};
|
||
|
for (const [key, value] of new URLSearchParams(location.search)) {
|
||
|
params[key] = value
|
||
|
}
|
||
|
|
||
|
const id = params.id !== undefined && !isNaN(params.id) ? parseInt(params.id) : (await loadself()).json.id
|
||
|
const posts = (await loadusersposts(id)).json
|
||
|
data.posts.push(... posts)
|
||
|
const batch = [id]
|
||
|
for (const post of posts) {
|
||
|
for(const comment of post.comments) {
|
||
|
if (data.users[comment.user] !== undefined) continue
|
||
|
if (batch.includes(comment.user)) continue
|
||
|
batch.push(comment.user)
|
||
|
}
|
||
|
if (data.users[post.user] !== undefined) continue
|
||
|
if (batch.includes(post.user)) continue
|
||
|
batch.push(post.user)
|
||
|
}
|
||
|
const users = (await loadusers(batch)).json
|
||
|
for (const id in users) {
|
||
|
data.users[id] = users[id]
|
||
|
}
|
||
|
data.user = data.users[id]
|
||
|
render()
|
||
|
}
|
||
|
|
||
|
load()
|