53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
|
async function apiRequest(type, req){
|
||
|
let A = await fetch("/api/" + type,
|
||
|
{method: 'POST', body: JSON.stringify(req)});
|
||
|
let B = await A.json();
|
||
|
if (B.status !== 0)
|
||
|
throw Error("Server returned non-zero status");
|
||
|
return B;
|
||
|
}
|
||
|
|
||
|
/* Framework for pages with mainloop (it can be npt only polling, but also literally anything else */
|
||
|
let __mainloopDelayMs = 3000;
|
||
|
let mainloopTimeout = null;
|
||
|
let mainloopPoller = null;
|
||
|
let __guestMainloopPollerAction = null;
|
||
|
function setMainloopTimeout(){
|
||
|
mainloopTimeout = setTimeout(mainloopPoller, __mainloopDelayMs);
|
||
|
}
|
||
|
function cancelMainloopTimeout(){
|
||
|
clearTimeout(mainloopTimeout);
|
||
|
}
|
||
|
mainloopPoller = function(){
|
||
|
try {
|
||
|
console.log("Hello, World!");
|
||
|
__guestMainloopPollerAction();
|
||
|
} catch (error){
|
||
|
console.log(error)
|
||
|
}
|
||
|
setMainloopTimeout();
|
||
|
}
|
||
|
|
||
|
// 1
|
||
|
const userChatRoleAdmin = "admin";
|
||
|
// 2
|
||
|
const userChatRoleRegular = "regular";
|
||
|
// 3
|
||
|
const userChatRoleReadOnly = "read-only";
|
||
|
// 4
|
||
|
const userChatRoleDeleted = "not-a-member";
|
||
|
|
||
|
function roleToColor(role) {
|
||
|
if (role === userChatRoleAdmin) {
|
||
|
return "#aafff3";
|
||
|
} else if (role === userChatRoleRegular){
|
||
|
return "#ffffff";
|
||
|
|
||
|
} else if (role === userChatRoleReadOnly){
|
||
|
return "#bfb2b2";
|
||
|
} else if (role === userChatRoleDeleted) {
|
||
|
return "#fb4a4a";
|
||
|
}
|
||
|
return "#286500" // Bug
|
||
|
}
|