From f778826847895a3bea0e31eb577204646fd20469 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 19 Dec 2021 17:03:16 +0100 Subject: Prettier logs with formatting and colors. --- ui.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'ui.js') diff --git a/ui.js b/ui.js index 41fe99e..a39553d 100644 --- a/ui.js +++ b/ui.js @@ -50,6 +50,34 @@ let ui = { present: new Set(), } +create_log_entry = function (text) { + let p = document.createElement("div"); + text = text.replace(/&/g, "&"); + text = text.replace(//g, ">"); + + text = text.replace(/\u2192 /g, "\u2192\xa0"); + + text = text.replace(/^([A-Z]):/, ' $1 '); + + if (text.match(/^~ .* ~$/)) + p.className = 'br', text = text.substring(2, text.length-2); + else if (text.match(/^Start Frank turn/)) + p.className = 'F'; + else if (text.match(/^Start Saracen turn/)) + p.className = 'S'; + else if (text.match(/^Start /)) + p.className = 'st'; + else if (text.match(/^(Battle in)/)) + p.className = 'bs'; + + if (text.match(/^Start /)) + text = text.substring(6); + + p.innerHTML = text; + return p; +} + function on_focus_town(evt) { let where = evt.target.town; let text = where; -- cgit v1.2.3