summaryrefslogtreecommitdiffstats
path: root/src/modules/helpers.ts
diff options
context:
space:
mode:
authorMaks Jopek <maksymilian.jopek@prym-soft.pl>2021-05-26 08:38:37 +0200
committerMaks Jopek <maksymilian.jopek@prym-soft.pl>2021-05-26 08:38:37 +0200
commit28497b06e208cd8fd4aa94756c7a5626c18d9878 (patch)
tree1b44a0f30c7844ed2069a4b5bb06f2925e2b964e /src/modules/helpers.ts
parentc7b3012c7aba9cdbe90932c9d37057f26b3a1e33 (diff)
downloadIRC-28497b06e208cd8fd4aa94756c7a5626c18d9878.tar.gz
IRC-28497b06e208cd8fd4aa94756c7a5626c18d9878.tar.zst
IRC-28497b06e208cd8fd4aa94756c7a5626c18d9878.zip
Added all features
Diffstat (limited to 'src/modules/helpers.ts')
-rw-r--r--src/modules/helpers.ts41
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;
+ }
+}