2020-09-09 18:19:40 +02:00
|
|
|
// Keep this the same as on the server!
|
|
|
|
let max_messages = 200;
|
|
|
|
|
2020-09-08 18:52:38 +02:00
|
|
|
let paused = true;
|
|
|
|
let updaterID = null;
|
2020-08-16 04:16:36 +02:00
|
|
|
|
2020-09-09 18:19:40 +02:00
|
|
|
let serverID = "";
|
|
|
|
let newest_message_index = -1;
|
|
|
|
let messageTable = document.getElementById('message_table');
|
|
|
|
let header = document.getElementById("table_header").cloneNode(true);
|
|
|
|
|
2020-09-08 20:21:32 +02:00
|
|
|
let color_classes = {
|
|
|
|
"RESERVED TYPE": "error",
|
|
|
|
"controller": "controller",
|
|
|
|
"puzzle": "puzzle",
|
|
|
|
"needy": "needy",
|
|
|
|
}
|
|
|
|
|
2020-09-09 23:32:42 +02:00
|
|
|
function updateShowRaw() {
|
2020-09-09 14:44:12 +02:00
|
|
|
document.getElementById("message_table").classList.toggle("hide_raw", !document.getElementById('show_raw').checked);
|
2020-08-16 04:16:36 +02:00
|
|
|
}
|
|
|
|
|
2020-09-09 23:32:42 +02:00
|
|
|
function updateShowStates() {
|
|
|
|
document.getElementById("message_table").classList.toggle("hide_consecutive_states", !document.getElementById('show_consecutive_states').checked);
|
|
|
|
}
|
|
|
|
|
2020-08-16 04:16:36 +02:00
|
|
|
function updateMessages() {
|
2020-09-09 18:19:40 +02:00
|
|
|
fetch(`/${newest_message_index}/api.json`)
|
2020-08-16 04:16:36 +02:00
|
|
|
.then(
|
|
|
|
function(response) {
|
|
|
|
if (response.status !== 200) {
|
|
|
|
console.log('FAIL: ' + response.status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
response.json().then(function(data) {
|
2020-09-09 18:19:40 +02:00
|
|
|
if (serverID !== data.server_id) {
|
|
|
|
messageTable.textContent = '';
|
|
|
|
messageTable.append(header);
|
|
|
|
serverID = data.server_id;
|
|
|
|
newest_message_index = -1;
|
|
|
|
}
|
2020-09-09 13:57:16 +02:00
|
|
|
|
2020-09-09 18:19:40 +02:00
|
|
|
let new_messages = data.newest_msg - newest_message_index;
|
|
|
|
if (new_messages > 0) {
|
|
|
|
for (let message of data.messages) {
|
2020-09-08 18:52:38 +02:00
|
|
|
let row = messageTable.insertRow(1);
|
2020-09-09 13:57:16 +02:00
|
|
|
row.classList.add("fade");
|
2020-09-09 18:19:40 +02:00
|
|
|
let current = message;
|
2020-08-16 04:16:36 +02:00
|
|
|
|
2020-09-08 18:52:38 +02:00
|
|
|
let human_readable_type = row.insertCell(0)
|
2020-09-08 20:21:32 +02:00
|
|
|
let colorblock = document.createElement("div");
|
|
|
|
colorblock.classList.add("colorblock");
|
|
|
|
human_readable_type.append(colorblock);
|
|
|
|
|
|
|
|
human_readable_type.innerHTML += current['human_readable_type'];
|
|
|
|
|
|
|
|
human_readable_type.classList.add(color_classes[current['human_readable_type']]);
|
|
|
|
human_readable_type.classList.add('human_readable_type');
|
2020-08-16 04:16:36 +02:00
|
|
|
|
2020-09-08 18:52:38 +02:00
|
|
|
let sender_id = row.insertCell(-1)
|
|
|
|
sender_id.innerHTML = current['sender_id'];
|
2020-09-08 20:21:32 +02:00
|
|
|
sender_id.classList.add('sender_id');
|
2020-09-08 18:52:38 +02:00
|
|
|
let parsed = row.insertCell(-1)
|
|
|
|
if (current['parsed'].startsWith("PARSE ERROR")) {
|
2020-09-08 20:21:32 +02:00
|
|
|
parsed.classList.add("error");
|
2020-09-09 23:32:42 +02:00
|
|
|
} else if (current['parsed'].startsWith("STATE")) {
|
2020-09-11 18:26:58 +02:00
|
|
|
row.classList.add("staterow");
|
2020-09-08 18:52:38 +02:00
|
|
|
}
|
|
|
|
parsed.innerHTML = current['parsed'];
|
2020-09-08 20:21:32 +02:00
|
|
|
parsed.classList.add('parsed');
|
2020-08-16 04:16:36 +02:00
|
|
|
|
2020-09-08 18:52:38 +02:00
|
|
|
let time = row.insertCell(-1)
|
|
|
|
time.innerHTML = current['time'];
|
2020-09-08 20:21:32 +02:00
|
|
|
time.classList.add('time');
|
2020-08-16 04:16:36 +02:00
|
|
|
|
2020-09-08 18:52:38 +02:00
|
|
|
let raw_message = row.insertCell(-1);
|
|
|
|
raw_message.innerHTML = current['raw_message'];
|
|
|
|
raw_message.classList.add("raw");
|
|
|
|
raw_message.classList.add("raw_message");
|
2020-08-16 04:16:36 +02:00
|
|
|
|
2020-09-08 18:52:38 +02:00
|
|
|
let raw_id = row.insertCell(-1);
|
|
|
|
raw_id.innerHTML = current['pretty_raw_sender_id'];
|
|
|
|
raw_id.classList.add("raw");
|
|
|
|
raw_id.classList.add("raw_id");
|
|
|
|
}
|
2020-08-16 04:16:36 +02:00
|
|
|
}
|
2020-09-09 18:19:40 +02:00
|
|
|
|
|
|
|
// delete children if there are too many :O
|
|
|
|
// -1 so we don't delete the header :)
|
2022-01-25 21:29:21 +01:00
|
|
|
while (messageTable.children.length - 1 > max_messages) {
|
2020-09-09 18:19:40 +02:00
|
|
|
messageTable.removeChild(messageTable.lastChild);
|
|
|
|
}
|
|
|
|
newest_message_index = data.newest_msg;
|
|
|
|
|
2020-08-16 04:16:36 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:52:38 +02:00
|
|
|
function toggle_logging() {
|
|
|
|
if (paused) {
|
|
|
|
paused = false;
|
|
|
|
document.getElementById("toggle_button").innerHTML = "Pause";
|
|
|
|
updaterID = setInterval(updateMessages, 1000);
|
|
|
|
} else {
|
|
|
|
paused = true;
|
|
|
|
document.getElementById("toggle_button").innerHTML = "Start";
|
|
|
|
clearInterval(updaterID);
|
|
|
|
}
|
|
|
|
}
|
2020-09-09 14:44:12 +02:00
|
|
|
|
2022-01-25 21:29:21 +01:00
|
|
|
function clear_log() {
|
|
|
|
while (messageTable.children.length > 1) {
|
|
|
|
messageTable.removeChild(messageTable.lastChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-09 14:44:12 +02:00
|
|
|
window.onload = toggle_logging;
|