game/adminion/oltest.js

66 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2024-12-17 08:40:25 +00:00
const img = '//img.new-combats.com/i';
const gett = async () => {
let response = await fetch('/api/onlinelist.php');
if (response.ok) {
document.getElementById('onlinelist').innerHTML = '';
const list = await response.json();
list.forEach((user) => {
console.log(user);
document.getElementById('onlinelist').insertAdjacentHTML('beforeend', `${ol.makelogin(user)}<br>`);
});
} else {
document.getElementById('onlinelist').insertAdjacentHTML('beforeend', `Все ушли.<br>`);
}
};
window.addEventListener('load', () => {
const fetchInterval = 10000; // 10 секунд.
gett;
//(get)(); // почему get; или get(); - неправильно?? 🤬😭
setInterval(gett, fetchInterval);
});
ol = {
tochat (login) {
const input = document.getElementById('tochat');
if (input.value === `private [${login}]`) {
return;
}
if (input.value === `to [${login}]`) {
input.value = `private [${login}]`;
return;
}
input.value = `to [${login}]`;
},
makelogin ({id, login, level, align, clan, inbattle, isadmin}) {
let style = '';
if (isadmin) {
//align = 2.9;
style = `color: crimson;`;
}
if (!level || level < 0 || level > 21 && !isadmin || typeof level !== 'number') {
level = '??';
}
let inficon = `<a href="/info/${id}" target="_blank"><img src="${img}/inf.gif" alt="Информация про ${login}"></a>`;
let html = `<span style="${style}; cursor: pointer;" onclick="ol.tochat('${login}');">${login}[${level}]</span>` + inficon;
if (clan) {
html = `<img src="${img}/clan/${clan}.gif" alt="Клан"> ` + html;
}
if (align) {
html = `<img src="${img}/align/align${align}.gif" alt="Склонность"> ` + html;
}
let battleyes = '', battlealt = '';
if (inbattle) {
battleyes = 1;
battlealt = ' (персонаж в поединке)'
}
html = `<img src="${img}/lock${battleyes}.gif" alt="Приват${battlealt}" onclick="ol.tochat('${login}')">` + html;
return html;
}
};