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
|
'use strict';
const BASE_THEMES = [[
"/styles/themes/colors-base.css",
"/styles/themes/colors-dark.css"
],
[
"Light",
"Dark"
]];
const APP_NAME = "cshift-net";
class Theme{
static theme = document.getElementById("theme");
static UserThemes = [[],[]];
static init()
{
let uth = Cookies.getCookie("userThemes-" + APP_NAME).split(',');
for (let i = 1; i < uth.length; i += 2)
{
this.UserThemes[0].push(uth[i - 1]);
this.UserThemes[1].push(uth[i]);
}
if(Cookies.getCookie("theme-" + APP_NAME) == ""){
Cookies.setYearCookie("theme-" + APP_NAME, BASE_THEMES[0][0]);
}
Theme.theme.setAttribute("href", Cookies.getCookie("theme-" + APP_NAME) + "?v=" + Date.now());
}
static set(sheet)
{
Cookies.setYearCookie("theme-" + APP_NAME, sheet);
Theme.theme.setAttribute("href", sheet + "?v=" + Date.now());
}
static get() {
return Cookies.getCookie("theme-" + APP_NAME);
}
static setUserThemes() {
let out = "";
for (let i = 0; i < this.UserThemes[0].length; i++)
{
if(i !== 0)
out = out + ",";
out = out + this.UserThemes[0][i] + "," + this.UserThemes[1][i];
}
Cookies.setYearCookie("userThemes-" + APP_NAME, out);
}
static removeUserTheme (index) {
this.UserThemes[0].splice(index, 1);
this.UserThemes[1].splice(index, 1);
this.setUserThemes();
}
static addUserTheme (name, value) {
this.UserThemes[0].push(name);
this.UserThemes[1].push(value);
this.setUserThemes();
}
}
Theme.init();
|