2022-05-03 11:19:25 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
displayUserList();
|
|
|
|
})
|
|
|
|
|
|
|
|
function kickUser(username) {
|
|
|
|
const payload = `/kick ${username}`;
|
2022-05-03 10:26:36 +00:00
|
|
|
|
|
|
|
sendCommand(payload);
|
2022-05-03 11:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function displayUserList() {
|
2022-05-04 20:12:44 +00:00
|
|
|
const resp = await sendCommand('/list', 'invoke', true);
|
2022-05-03 11:19:25 +00:00
|
|
|
|
|
|
|
// Do some funky string stuff
|
|
|
|
const dataArr = resp.payload.split('\n').map(x => x.trim()).filter(x => x.length > 0);
|
|
|
|
|
|
|
|
// Number of users online
|
|
|
|
const amountOnline = parseInt(dataArr[0].split('are ')[1].split('p')[0]);
|
|
|
|
|
|
|
|
// Player name list
|
|
|
|
const players = dataArr.slice(1, dataArr.length);
|
|
|
|
|
|
|
|
let zebra = true;
|
|
|
|
|
|
|
|
for (const player of players) {
|
|
|
|
const playerList = document.getElementById('playerList');
|
|
|
|
const playerSection = document.createElement('div')
|
|
|
|
playerSection.className = zebra ? 'playerSection' : 'playerSection zebra';
|
|
|
|
playerSection.innerHTML = `<span class="playerName">${player}</span>`;
|
|
|
|
|
|
|
|
// Kick and ban buttons
|
|
|
|
const buttons = document.createElement('div');
|
|
|
|
buttons.className = 'buttons';
|
|
|
|
buttons.innerHTML = `<button class="kickButton" onclick="kickUser('${player}')">Kick</button>`;
|
|
|
|
buttons.innerHTML += `<button class="banButton" onclick="banUser('${player}')">Ban</button>`;
|
|
|
|
|
|
|
|
playerSection.appendChild(buttons);
|
|
|
|
|
|
|
|
playerList.appendChild(playerSection);
|
|
|
|
|
|
|
|
zebra = !zebra;
|
|
|
|
}
|
2022-05-03 10:26:36 +00:00
|
|
|
}
|