aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/console.ts
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-01-23 02:11:44 +0100
committerLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-01-23 02:11:44 +0100
commit2d2e1f52afaf1eb142e391c00450bc379c745f2f (patch)
treefe193c22a28bf2af89716fe4acb753c5aff2ee5b /src/lib/console.ts
parent1bce06b615b44dbd5fd3d3c57d1ab6567451e680 (diff)
downloadmem-estrogen-zone-2d2e1f52afaf1eb142e391c00450bc379c745f2f.tar.gz
mem-estrogen-zone-2d2e1f52afaf1eb142e391c00450bc379c745f2f.tar.bz2
mem-estrogen-zone-2d2e1f52afaf1eb142e391c00450bc379c745f2f.tar.lz
mem-estrogen-zone-2d2e1f52afaf1eb142e391c00450bc379c745f2f.zip

feat: cutely wrap console logging functions, etc

Diffstat (limited to 'src/lib/console.ts')
-rw-r--r--src/lib/console.ts191
1 files changed, 191 insertions, 0 deletions
diff --git a/src/lib/console.ts b/src/lib/console.ts
new file mode 100644
index 0000000..313fd0a
--- /dev/null
+++ b/src/lib/console.ts
@@ -0,0 +1,191 @@
+import { browser } from "$app/environment";
+import { dev } from "$app/environment";
+
+if (browser) {
+ for (const v of [
+ "debug",
+ "log",
+ "info",
+ "warn",
+ "error",
+ "trace",
+ ] satisfies (keyof typeof console)[]) {
+ const old = ((globalThis as any)['_oldconsole_' + v] ?? console[v]) as typeof console[typeof v];
+ (globalThis as any)['_oldconsole_' + v] = old;
+ console[v] = (a, ...b) => {
+ if (typeof a === "string") {
+ const tags_unparsed = a.match(/^(\s*\[[\w\s]+\])*/mu)?.[0];
+ const pre: string[] = [];
+ const styles: string[] = [];
+ if (tags_unparsed) {
+ let tag_unparsed = null as null | string;
+ while ((tag_unparsed = a.match(/^(\s*\[[^\]\r\n]+\])/mu)?.[0])) {
+ a = a.substring(tag_unparsed.length);
+ tag_unparsed = tag_unparsed.trim();
+ let tag = tag_unparsed.substring(1, tag_unparsed.length - 1);
+ let colour = "#aa99ffcc";
+ switch (tag) {
+ case "vite":
+ colour =
+ "linear-gradient(-45deg, #41D1FF -50%, #BD34FE 150%)";
+ break;
+ case "w":
+ case "warn":
+ colour = "#FFEA83";
+ break;
+ case "i":
+ case "inf":
+ case "info":
+ colour = "#99AAFF";
+ break;
+ case "e":
+ case "err":
+ case "error":
+ colour = "#FF99AA";
+ break;
+ case "success":
+ case "succ":
+ colour = "#AAFF99";
+ break;
+ case "motd":
+ case "devmotd":
+ colour =
+ "linear-gradient(-75deg, #99AAFF -90%, #BD34FE 150%)";
+ break;
+ case "uwu":
+ colour = "#BBAAFF";
+ break;
+ case 'keystore':
+ colour = '#CC99FF';
+ break;
+ case 'globalState':
+ colour = '#E699FF';
+ break;
+ }
+ let baseMainStyles = `
+background: ${colour};
+color: #1a1a1a;
+font-width: bold;
+font-family: Inter, sans-serif;
+padding-top: 4px;
+padding-bottom: 4px;
+`
+ if (tag.includes('=')) {
+ const v = tag.split('=');
+ pre.push(`%c${v.shift() ?? ''}: %c${v.join('=')}%c`)
+ baseMainStyles += `background: #667;
+`
+ styles.push(`${baseMainStyles}
+border-top-left-radius: 4px;
+border-bottom-left-radius: 4px;
+padding-left: 4px;
+color: #3a3a3a;
+`, `${baseMainStyles}
+border-top-right-radius: 4px;
+border-bottom-right-radius: 4px;
+padding-right: 4px;
+margin-right: 4px;
+`, '')
+ } else {
+ pre.push(`%c${tag}%c`);
+ styles.push(
+ `
+${baseMainStyles}
+padding-left: 4px;
+padding-right: 4px;
+border-radius: 4px;
+margin-right: 4px;
+`,
+ "",
+ );
+ }
+ }
+ }
+ a = `​\n${pre.join("")}${(a as string).trimStart()}`;
+ if (b.length) b.push("\n​");
+ else a += "\n​";
+ return old(a, ...styles, ...b);
+ } else return old(a, ...b);
+ };
+ }
+
+ const s = [
+ [`CALL THE FIRE DEPARTMENT, WE JUST NUKED THE BUILDING`],
+ [`RIP Terry`],
+ [`WARNING, NUKING IS NOW LEGAL... WORLDWIDE!!! >~<`],
+ [`Welcome back, Anon`],
+ [`when you suckin on her nuts`],
+ [`wait.. nuking's actually kinda hot......`],
+ [`you know what happens after a nuke? smoke %c#3`, "color: #ff0000;"],
+ [`Fucking the industry's transfems since 20xx`],
+ [
+ `%c"How many Bitcoin?"%c I prefer my coin count in bytes.`,
+ "color: #99aaff;",
+ "color: undo;",
+ ],
+ [`Lesbians are hot %c<3`, "color: #ff99aa;"],
+ [
+ `Astolfo didn't kill %chim%c- herself`,
+ "text-decoration: line-through;",
+ "text-decoration: none;",
+ ],
+ ] as [string, ...string[]][];
+ const strs = s.map(([v0, ...vn]) => [
+ `[${dev ? "dev" : ""}motd]%c${v0}`,
+ ...[
+ // Base Styles
+ `
+color: #12488B;
+font-family: "Courier New", Courier, monospace;
+`,
+ // Additional Styles
+ ...vn,
+ ]
+ // Parse Declarations
+ .map((_, i, a) =>
+ a[i]
+ .split(";")
+ .filter((v) => v.trim().length !== 0)
+ .map((v) => v.split(":"))
+ .map(
+ ([k, ...v]) =>
+ [k.trim(), v.join(":").trim()] as [key: string, value: string],
+ ),
+ )
+ // Inherit from previous values
+ .map((_, i, a) => {
+ const props = {} as Record<string, string[]>;
+ for (let i2 = 0; i2 <= i; i2++) {
+ for (const [k, v] of a[i2]) {
+ if (v === "undo") (props[k] ?? []).pop();
+ else (props[k] = props[k] ?? []).push(v);
+ }
+ }
+ return Object.fromEntries(
+ Object.entries(props).map(([k, v]) => [k, v[v.length - 1]]),
+ );
+ })
+ // Join into strings
+ .map((v) => {
+ return Object.entries(v)
+ .map((v) => v.join(": ") + ";")
+ .join("\n");
+ }),
+ ]);
+ console.debug(
+ ...strs[
+ dev
+ ? Math.floor(Math.random() * strs.length)
+ : (Date.now() /
+ // millis in a second
+ 1000 /
+ // secs in a min
+ 60 /
+ // mins in an hour
+ 60 /
+ // hours in a day
+ 24) %
+ strs.length
+ ],
+ );
+}