aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/console.ts
blob: 313fd0aea3e3ce1a870a619713cd3cde03a9c144 (plain) (blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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
    ],
  );
}