1
0
This repository has been archived on 2024-07-09. You can view files and clone it, but cannot push or open issues or pull requests.
fist-attemp-bds-Maneger/page/players.html

90 lines
3.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="/assents/index.css">
<link rel="stylesheet" href="/assents/Players.css">
<link rel="icon" href="https://github.com/The-Bds-Maneger/Bds-Maneger-Electron/raw/main/bds_pages/assents/mcpe.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bds Maneger - Players</title>
</head>
<body>
<div class="Players_Root">
<div class="PlayersHead">
<p><a href="index">Return to Home</a></p>
<p><h2>Players List</h2></p>
</div>
<div id="ListPlayers" class="ListPlayers"></div>
</div>
<script>
fetch("api/token").then(res => res.json()).then(res => globalThis.ApiToken = res.token).catch(()=>globalThis.ApiToken = "ErroGetToken")
async function ControlPlayer(mode = "kick", player = "2333aa", text = "You Kicked") {
try {
return (await (await fetch(`/api/players/actions/${mode}/${ApiToken}/${player}?text=${text}`)).json())
} catch (err) {
console.info(err);
alert(`sorry, there was an error on our part`)
return {};
}
}
fetch("/api/players").then(res => res.json()).then(res => {
const ArrayPLayers = Object.getOwnPropertyNames(res);
const divPlayers = document.getElementById("ListPlayers")
for (let players of ArrayPLayers) {
const _p = document.createElement("p")
const DivDoc = document.createElement("div");
DivDoc.classList.add("players")
DivDoc.innerHTML = `Player: ${players}`
// Ban Button
const ButtonBan = document.createElement("button")
ButtonBan.classList.add("BanUser", "buttomMainStyle")
ButtonBan.innerHTML = "Ban"
ButtonBan.onclick = async () => {
const res = await ControlPlayer("ban", players)
if (res.ok) DivDoc.remove()
}
_p.appendChild(ButtonBan)
// Kick Player
const KickPlayer = document.createElement("button")
KickPlayer.classList.add("KickUser", "buttomMainStyle")
KickPlayer.innerHTML = "Kick"
KickPlayer.onclick = async () => {
const text = prompt(`Text to kick ${players}`, `you kicked`)
const res = await ControlPlayer("kick", players, text)
if (res.ok) DivDoc.remove()
}
_p.appendChild(KickPlayer)
// op Player
const OPPlayer = document.createElement("button")
OPPlayer.classList.add("opUser", "buttomMainStyle")
OPPlayer.innerHTML = "OP"
OPPlayer.onclick = async () => {
const res = await ControlPlayer("op", players)
if (res.ok) DivDoc.remove()
}
_p.appendChild(OPPlayer)
// deop Player
const DeopPlayer = document.createElement("button")
DeopPlayer.classList.add("DeopUser", "buttomMainStyle")
DeopPlayer.innerHTML = "Deop"
DeopPlayer.onclick = async () => {
const res = await ControlPlayer("deop", players)
if (res.ok) DivDoc.remove()
}
_p.appendChild(DeopPlayer)
// Publish
DivDoc.appendChild(_p)
divPlayers.appendChild(DivDoc)
}
})
</script>
</body>
</html>