From e45a35ed1109e62f5ddcaf8c19d9531d5ec4ddcb Mon Sep 17 00:00:00 2001 From: sD Date: Fri, 20 Mar 2020 22:34:59 +0100 Subject: add text decoding magic --- webAO/master.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'webAO') diff --git a/webAO/master.js b/webAO/master.js index f2711d2..72ce833 100644 --- a/webAO/master.js +++ b/webAO/master.js @@ -10,6 +10,22 @@ const options = {fonts: {extendedJsFonts: true, userDefinedFonts: ["Ace Attorney let oldLoading = false; +const server_description = []; +server_description[-1] = "This is your computer on port 50001"; +const online_counter = []; + +/** + * Unescapes a string to AO1 escape codes. + * @param {string} estring the string to be unescaped + */ +function unescapeChat(estring) { + return estring + .replace(//g, "#") + .replace(//g, "&") + .replace(//g, "%") + .replace(//g, "$"); +} + if (window.requestIdleCallback) { requestIdleCallback(function () { Fingerprint2.get(options, function (components) { @@ -40,10 +56,6 @@ if (window.requestIdleCallback) { }, 500); } -const server_description = []; -server_description[-1] = "This is your computer on port 50001"; -const online_counter = []; - export function setServ(ID) { console.log(server_description[ID]); if (server_description[ID] !== undefined) { @@ -154,4 +166,12 @@ function onMessage(e) { const args = msg.split("#").slice(1); document.getElementById("serverinfo").innerHTML = `Master server version: ${args[0]}`; } + else if (header === "CT") { + const args = msg.split("#").slice(1); + const msChat = document.getElementById("masterchat"); + msChat.innerHTML += `${unescapeChat(args[0])}: ${unescapeChat(args[1])}\r\n`; + if (msChat.scrollTop > msChat.scrollHeight - 600) { + msChat.scrollTop = msChat.scrollHeight; + } + } } -- cgit