blob: a29fc5df1f7a062ac080520047a41818fe3dbc19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import { API_ROOT } from "./global.js"
const {team: TEAM, username: USERNAME} = getUserInfo()
const PROMPT_POLL = 30000
const element = (e) => document.querySelector(e)
async function increment() {
const response = await fetch(`${API_ROOT}/increment/${TEAM}/${USERNAME}`, {"method": "POST"})
const {points} = await response.json()
return points
}
function getUserInfo() {
const urlParams = new URLSearchParams(window.location.search);
return {"team": urlParams.get("team"), "username": urlParams.get("username")}
}
// async function getUserPoints() {
// const response = await fetch(`${API_ROOT}/points/${TEAM}/${USERNAME}`)
// const {points} = await response.json()
// return points
// }
async function getPrompt() {
const response = await fetch(`${API_ROOT}/prompt/`, { "method": "GET" })
const { prompt } = await response.json()
return prompt
}
async function fillPrompt() {
element("button").innerHTML = await getPrompt()
}
element("#increment").addEventListener("click", increment)
document.addEventListener("DOMContentLoaded", async () => {
// element(".username").innerHTML = USERNAME
console.log("sdfsdf")
fillPrompt()
const polling = setInterval(fillPrompt, PROMPT_POLL)
});
|