blob: 4f2857e2f6ce45d9bac3b1218ab489295e54afcf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import queryParser from "../../utils/queryParser";
import { unescapeChat } from "../../encoding";
const { mode } = queryParser();
/**
* Handles an out-of-character chat message.
* @param {Array} args packet arguments
*/
export const handleCT = (args: string[]) => {
if (mode !== "replay") {
const oocLog = document.getElementById("client_ooclog")!;
const username = unescapeChat(args[1]);
let message = addLinks(unescapeChat(args[2]));
const line = document.createElement("div");
line.className = "ooc-line";
line.textContent = `${username}: ${message}`;
oocLog.appendChild(line);
if (oocLog.scrollTop + oocLog.offsetHeight + 120 > oocLog.scrollHeight)
oocLog.scrollTo(0, oocLog.scrollHeight);
}
};
// If the incoming message contains a link, add a href hyperlink to it
function addLinks(message: string) {
const urlRegex = /(https?:\/\/[^\s]+)/g;
return message.replace(
urlRegex,
(url) => `<a href="${url}" target="_blank">${url}</a>`,
);
}
|