2024-09-04 09:39:39 +00:00
|
|
|
let dopDopYesYes = (ign) => {};
|
|
|
|
|
|
|
|
function sleep(ms){
|
|
|
|
return new Promise(res => setTimeout(res, ms));
|
|
|
|
}
|
|
|
|
|
2024-09-01 19:24:55 +00:00
|
|
|
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 __guestMainloopPollerAction = null;
|
|
|
|
function setMainloopTimeout(){
|
|
|
|
mainloopTimeout = setTimeout(mainloopPoller, __mainloopDelayMs);
|
|
|
|
}
|
|
|
|
function cancelMainloopTimeout(){
|
|
|
|
clearTimeout(mainloopTimeout);
|
2024-09-04 09:39:39 +00:00
|
|
|
mainloopTimeout = null;
|
2024-09-01 19:24:55 +00:00
|
|
|
}
|
2024-09-04 09:39:39 +00:00
|
|
|
function mainloopPoller(){
|
2024-09-01 19:24:55 +00:00
|
|
|
try {
|
2024-09-04 09:39:39 +00:00
|
|
|
if (__guestMainloopPollerAction)
|
|
|
|
__guestMainloopPollerAction();
|
2024-09-01 19:24:55 +00:00
|
|
|
} 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
|
|
|
|
}
|
2024-09-04 09:39:39 +00:00
|
|
|
|
|
|
|
// todo: replace it with translation
|
|
|
|
const msgErased = "[ ERASED ]";
|
2024-09-04 21:17:33 +00:00
|
|
|
|
|
|
|
function hideHTMLElement(el){
|
|
|
|
el.style.display = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
function showHTMLElement(el){
|
|
|
|
el.style.display = "block";
|
|
|
|
}
|
|
|
|
|
|
|
|
function setElementVisibility(el, isVisible, howVisible = "block"){
|
|
|
|
el.style.display = isVisible ? howVisible : "none";
|
|
|
|
}
|