diff --git a/pages/players.html b/pages/players.html index adb2e2c..ccc1d5a 100644 --- a/pages/players.html +++ b/pages/players.html @@ -4,13 +4,10 @@ +
-
- Kick user: - - -
+
\ No newline at end of file diff --git a/scripts/console.js b/scripts/console.js index 37eea3f..b1e9894 100644 --- a/scripts/console.js +++ b/scripts/console.js @@ -1,25 +1,19 @@ -function sendCommand(payload){ - let client = new XMLHttpRequest(); +async function sendCommand(payload){ let key = new window.URLSearchParams(window.location.search).get("k"); let url = '/mojoplus/api'; + let data = JSON.stringify({ "k": key, "request": "invoke", "payload": payload }); - client.open("POST", url, true); - client.setRequestHeader("Content-Type", "application/json"); + let response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: data, + }) - client.onreadystatechange = () => { - if (client.readyState === 4 && client.status === 200) { - let result = document.getElementById("c2"); - - // Print received data from server - result.innerHTML = JSON.parse(this.responseText).payload.replace(/\n/g, "

"); - } - }; - - // Converting JSON data to string - var data = JSON.stringify({ "k": key, "request": "invoke", "payload": payload }); + let json = await response.json(); - // Sending data with the request - client.send(data); + return json } function switchPage(page) { diff --git a/scripts/parent.js b/scripts/parent.js new file mode 100644 index 0000000..38b89d4 --- /dev/null +++ b/scripts/parent.js @@ -0,0 +1,4 @@ +async function sendCommand(payload) { + const parent = window.parent + return await parent.sendCommand(payload) +} \ No newline at end of file diff --git a/scripts/players.js b/scripts/players.js index 8b9aec2..c11cc60 100644 --- a/scripts/players.js +++ b/scripts/players.js @@ -1,6 +1,43 @@ -function kickUser() { - const user = document.getElementById('kickInput').value; - const payload = `/kick ${user}`; +document.addEventListener('DOMContentLoaded', () => { + displayUserList(); +}) + +function kickUser(username) { + const payload = `/kick ${username}`; sendCommand(payload); +} + +async function displayUserList() { + const resp = await sendCommand('/list'); + + // 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 = `${player}`; + + // Kick and ban buttons + const buttons = document.createElement('div'); + buttons.className = 'buttons'; + buttons.innerHTML = ``; + buttons.innerHTML += ``; + + playerSection.appendChild(buttons); + + playerList.appendChild(playerSection); + + zebra = !zebra; + } } \ No newline at end of file diff --git a/styles/console.css b/styles/console.css index e9ec9cd..2ad7d06 100644 --- a/styles/console.css +++ b/styles/console.css @@ -17,6 +17,23 @@ iframe { margin: 20px; } +button { + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + font-size: 14px; + border: 1px solid #ccc; + background: none; + cursor: pointer; + padding: 5px 10px; + margin: 0; + border-radius: 3px; + + transition: background-color 0.2s ease-in-out; +} + +button:hover { + background-color: #eee; +} + #logo { height: 20px; } diff --git a/styles/players.css b/styles/players.css index 7b46ddb..4fef4e2 100644 --- a/styles/players.css +++ b/styles/players.css @@ -1,6 +1,26 @@ -#playerContent div { +#playerList { + display: flex; + flex-direction: column; + width: 50%; + margin: auto; +} + +.playerSection { display: flex; flex-direction: row; justify-content: space-between; - width: 20%; + width: 100%; + + padding: 6px; +} + +.buttons { + display: flex; + flex-direction: row; + justify-content: space-between; + width: 15%; +} + +.zebra { + background-color: #eee; } \ No newline at end of file