xssbook/public/js/people.js

68 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-01-26 22:29:16 +00:00
function parseUser(user) {
const html = `
2023-01-30 23:55:36 +00:00
<a class="person" href="/profile?id=${user.user_id}">
2023-01-26 22:29:16 +00:00
<div class="profile">
</div>
<div class="info">
<span class="bold ltext">${user.firstname + ' ' + user.lastname}</span>
<span class="gtext">Joined ${parseDate(new Date(user.date))}</span>
<span class="gtext">Gender: ${user.gender}</span>
<span class="gtext">Birthday: ${parseMonth(user.month) + ' ' + user.day + ', ' + user.year}</span>
2023-01-26 22:29:16 +00:00
<span class="gtext" style="margin-bottom: -100px;">User ID: ${user.user_id}</span>
</div>
</a>
`
return html
}
function render() {
const html = `
<div id="users">
${data.users.map(u => parseUser(u)).join('')}
</div>
`
append(html)
2023-01-26 22:29:16 +00:00
const load = `
<div id="load">
<a class="bold gtext" onclick="loadMore()">Load more users</a>
2023-01-26 22:29:16 +00:00
</div>
`
append(load)
2023-01-26 22:29:16 +00:00
}
var page = 0
var data = {
users: []
}
async function loadMore() {
let users = await load()
const users_block = document.getElementById("users")
for (user of users) {
append(parseUser(user), users_block)
}
}
2023-01-26 22:29:16 +00:00
async function load() {
const users = (await loaduserspage(page)).json
if (users.length === 0) {
page = -1
remove('load')
2023-01-26 22:29:16 +00:00
} else {
page++
}
return users
}
async function init() {
let users = await load()
2023-01-26 22:29:16 +00:00
data.users.push(... users)
render()
}
header(false, true)
init()