From 28497b06e208cd8fd4aa94756c7a5626c18d9878 Mon Sep 17 00:00:00 2001 From: Maks Jopek Date: Wed, 26 May 2021 08:38:37 +0200 Subject: Added all features --- src/modules/helpers.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/modules/helpers.ts (limited to 'src/modules/helpers.ts') diff --git a/src/modules/helpers.ts b/src/modules/helpers.ts new file mode 100644 index 0000000..862f121 --- /dev/null +++ b/src/modules/helpers.ts @@ -0,0 +1,41 @@ +export default class Helpers { + //@ts-expect-error + readonly chatListScroll = $("#chatlist").tinyscrollbar(); + + isColor(strColor: string) { + const s = new Option().style; + s.color = strColor; + return s.color !== ""; + } + + suicide(msg: string): void { + document.body.innerHTML = /* html */ ` +
${msg}
+ `; + throw new Error( + "This page has committed suicide by design, that's a feature!" + ); + } + + updateScrollbar(update: string) { + $(this.chatListScroll).data().plugin_tinyscrollbar.update(update); + } + + get getRandomColor(): string { + return "#" + (Math.random().toString(16) + "000000").substring(2, 8); + } + + get getUsername(): string { + let username = prompt("Gimme your name: "); + if (username === null) { + this.suicide("You should give me your name!"); + throw new Error("NoNameError"); + } + username = username.trim(); + if (username === "Server") { + this.suicide("That name is illegal!"); + throw new Error("IllegalNameError"); + } + return username; + } +} -- cgit v1.3.1