diff options
Diffstat (limited to 'src/modules/helpers.ts')
| -rw-r--r-- | src/modules/helpers.ts | 41 |
1 files changed, 41 insertions, 0 deletions
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 */ ` + <div class="text-center" style="margin: 45vh auto; font-size: 3em;">${msg}</div> + `; + 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; + } +} |
