blob: 047c154af96088d94a90c2697d215067915e7985 [file] [log] [blame]
Adrià Vilanova Martínez5dd7a6f2023-03-04 18:32:27 +01001import UserModel from './User.js';
2
3export default class StartupDataModel {
4 constructor(data) {
5 this.data = data ?? {};
6 }
7
8 static buildFromCCDOM() {
9 const startupData =
10 document.querySelector('html')?.getAttribute?.('data-startup');
11 if (!startupData) {
12 console.warn('Haven\'t found CC startup data.');
13 return null;
14 }
15
16 let startup;
17 try {
18 startup = JSON.parse(startupData);
19 } catch (error) {
20 console.warn('Haven\'t been able to parse CC startup data.');
21 }
22
23 return new StartupDataModel(startup);
24 }
25
26 getRawUser() {
27 return this.data[1]?.[1] ?? null;
28 }
29
30 getAuthUser() {
31 return this.data[2]?.[1] ?? '0';
32 }
33
34 getRawForumsInfo() {
35 return this.data[1]?.[2] ?? null;
36 }
37
38 getCurrentUserModel() {
39 return new UserModel(this.getRawUser(), this);
40 }
41}