From 1446d5fb320c706f3f4d3375d9e15363d5d03bdf Mon Sep 17 00:00:00 2001
From: Carlos <28845529+mesacarlos@users.noreply.github.com>
Date: Tue, 20 Aug 2019 16:10:59 +0200
Subject: [PATCH] Client, revision 2: Console colors added. General
improvements.
---
client/index.html | 8 ++--
client/scripts/WebConsole.js | 47 ++++++++++++++++++++++-
client/scripts/WebConsoleJqueryHandler.js | 3 ++
client/styles/WebConsole.css | 4 ++
4 files changed, 56 insertions(+), 6 deletions(-)
diff --git a/client/index.html b/client/index.html
index dec73e6..c118cd0 100644
--- a/client/index.html
+++ b/client/index.html
@@ -93,13 +93,13 @@
-
@@ -198,7 +198,7 @@
diff --git a/client/scripts/WebConsole.js b/client/scripts/WebConsole.js
index 8f2adcd..6cb6087 100644
--- a/client/scripts/WebConsole.js
+++ b/client/scripts/WebConsole.js
@@ -96,9 +96,52 @@ function onWebSocketsMessage(message){
* Write to console
*/
function writeToWebConsole(msg){
- var isScrolledDown = document.getElementById("consoleTextArea").scrollHeight - document.getElementById("consoleTextArea").scrollTop - 12 == $("#consoleTextArea").height();
+ var isScrolledDown = document.getElementById("consoleTextArea").scrollHeight - document.getElementById("consoleTextArea").scrollTop - 40 == $("#consoleTextArea").height();
- $("#consoleTextArea").append(msg.replace("<", "<") + "\n");
+ //Write to div, replacing < to < (to avoid XSS) and replacing new line to br.
+ msg = msg.replace(/");
+
+ //Color filter for Windows (thanks to SuperPykkon)
+ msg = msg.replace(/\[0;30;22m/g, ""); //&0
+ msg = msg.replace(/\[0;34;22m/g, ""); //&1
+ msg = msg.replace(/\[0;32;22m/g, ""); //&2
+ msg = msg.replace(/\[0;36;22m/g, ""); //&3
+ msg = msg.replace(/\[0;31;22m/g, ""); //&4
+ msg = msg.replace(/\[0;35;22m/g, ""); //&5
+ msg = msg.replace(/\[0;33;22m/g, ""); //&6
+ msg = msg.replace(/\[0;37;22m/g, ""); //&7
+ msg = msg.replace(/\[0;30;1m/g, ""); //&8
+ msg = msg.replace(/\[0;34;1m/g, ""); //&9
+ msg = msg.replace(/\[0;32;1m/g, ""); //&a
+ msg = msg.replace(/\[0;36;1m/g, ""); //&b
+ msg = msg.replace(/\[0;31;1m/g, ""); //&c
+ msg = msg.replace(/\[0;35;1m/g, ""); //&d
+ msg = msg.replace(/\[0;33;1m/g, ""); //&e
+ msg = msg.replace(/\[0;37;1m/g, ""); //&f
+ msg = msg.replace(/\[m/g, ""); //&f
+
+ //Color filter for UNIX (This is easier!)
+ //span may not be closed every time but browsers will do for ourselves
+ msg = msg.replace(/§0/g, ""); //&0
+ msg = msg.replace(/§1/g, ""); //&1
+ msg = msg.replace(/§2/g, ""); //&2
+ msg = msg.replace(/§3/g, ""); //&3
+ msg = msg.replace(/§4/g, ""); //&4
+ msg = msg.replace(/§5/g, ""); //&5
+ msg = msg.replace(/§6/g, ""); //&6
+ msg = msg.replace(/§7/g, ""); //&7
+ msg = msg.replace(/§8/g, ""); //&8
+ msg = msg.replace(/§9/g, ""); //&9
+ msg = msg.replace(/§a/g, ""); //&a
+ msg = msg.replace(/§b/g, ""); //&b
+ msg = msg.replace(/§c/g, ""); //&c
+ msg = msg.replace(/§d/g, ""); //&d
+ msg = msg.replace(/§e/g, ""); //&e
+ msg = msg.replace(/§f/g, ""); //&f
+ msg = msg.replace(/§r/g, ""); //&r
+
+ $("#consoleTextArea").append(msg + "
");
if(isScrolledDown){
var textarea = document.getElementById('consoleTextArea');
diff --git a/client/scripts/WebConsoleJqueryHandler.js b/client/scripts/WebConsoleJqueryHandler.js
index 6276d40..1297993 100644
--- a/client/scripts/WebConsoleJqueryHandler.js
+++ b/client/scripts/WebConsoleJqueryHandler.js
@@ -103,6 +103,9 @@ $("#commandInput").on('keypress', function (e) {
//Enable the textbox again.
$(this).removeAttr("disabled");
+
+ //Focus again
+ $(this).focus();
}
});
diff --git a/client/styles/WebConsole.css b/client/styles/WebConsole.css
index c5643c2..124b34b 100644
--- a/client/styles/WebConsole.css
+++ b/client/styles/WebConsole.css
@@ -1,3 +1,7 @@
.flat-progressbar{
height: 10px;
+}
+
+.console{
+ height: 480px;
}
\ No newline at end of file