aboutsummaryrefslogtreecommitdiff
path: root/webAO/client.js
diff options
context:
space:
mode:
authoroldmud0 <oldmud0@users.noreply.github.com>2018-05-22 21:57:02 -0500
committeroldmud0 <oldmud0@users.noreply.github.com>2018-05-22 21:57:02 -0500
commit9f7f070be3d0ded8e6a9e3eae8aa55e5c6958df8 (patch)
tree1fb4498e6c11d264bf771fefd89880d4f88eb913 /webAO/client.js
parent385b42a84ad52280ae9e209e543562f52c34d9e5 (diff)
Enhance IC log and add timestamps
Diffstat (limited to 'webAO/client.js')
-rw-r--r--webAO/client.js35
1 files changed, 32 insertions, 3 deletions
diff --git a/webAO/client.js b/webAO/client.js
index a62d307..41a5916 100644
--- a/webAO/client.js
+++ b/webAO/client.js
@@ -27,6 +27,7 @@ if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phon
}
let selectedShout = 0;
+let lastICMessageTime = new Date(0);
class Client {
constructor(address) {
@@ -71,6 +72,8 @@ class Client {
"CharsCheck": (args) => this.handleCharsCheck(args),
"PV": (args) => this.handlePV(args)
}
+
+ this._lastTimeICReceived = new Date(0);
}
/**
@@ -591,7 +594,7 @@ class Viewport {
*/
say(chatmsg) {
this.chatmsg = chatmsg;
- appendICLog(`${chatmsg.nameplate}: ${chatmsg.content}`);
+ appendICLog(chatmsg.content, chatmsg.nameplate);
changeBackground(chatmsg.side);
this.textnow = '';
this.sfxplayed = 0;
@@ -908,9 +911,35 @@ window.RetryButton = RetryButton;
/**
* Appends a message to the in-character chat log.
* @param {string} toadd the string to be added
+ * @param {string} name the name of the sender
*/
-function appendICLog(toadd) {
- document.getElementById("client_log").appendChild(document.createTextNode(toadd));
+function appendICLog(toadd, name = "", time = new Date()) {
+ const entry = document.createElement("p");
+ const nameField = document.createElement("span");
+ nameField.id = "iclog_name";
+ nameField.appendChild(document.createTextNode(name));
+ entry.appendChild(nameField);
+ entry.appendChild(document.createTextNode(toadd));
+
+ // Only put a timestamp if the minute has changed.
+ if (lastICMessageTime.getMinutes() !== time.getMinutes()) {
+ const timeStamp = document.createElement("span");
+ timeStamp.id = "iclog_time";
+ timeStamp.innerText = time.toLocaleTimeString(undefined, {
+ hour: "numeric",
+ minute: "2-digit"
+ });
+ entry.appendChild(timeStamp);
+ }
+
+ const clientLog = document.getElementById("client_log");
+ clientLog.appendChild(entry);
+
+ if (clientLog.scrollTop > clientLog.scrollHeight - 600) {
+ clientLog.scrollTop = clientLog.scrollHeight;
+ }
+
+ lastICMessageTime = new Date();
}
/**