summaryrefslogtreecommitdiff
path: root/scripts/theme.js
blob: 886a3a16b8a418263daf4c7642d4a4a9158ab06f (plain)
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
'use strict';

const BASE_THEMES = [[
	"styles/themes/colors-base.css",
	"styles/themes/colors-dark.css"
],
[
	"Light",
	"Dark"
]];

class Theme{
	static theme = document.getElementById("theme");
	static UserThemes = [[],[]];

	static init()
	{
		let uth = Cookies.getCookie("userThemes").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") == ""){
			Cookies.setYearCookie("theme", "styles/themes/colors-base.css");
		}
	}

	static restore()
	{
		Theme.init();
		Theme.theme.setAttribute("href", Cookies.getCookie("theme") + "?v=" + Date.now());
	}

	static set(sheet)
	{
		Cookies.setYearCookie("theme", sheet);
		Theme.theme.setAttribute("href", sheet + "?v=" + Date.now());
	}

	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", 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.restore();