-
Notifications
You must be signed in to change notification settings - Fork 1
/
ThemeSwitcher.js
54 lines (37 loc) · 1.35 KB
/
ThemeSwitcher.js
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
var color = 'red'
function loadSettings() {
$("#settings").show(500);
$("#cardContainer").toggleClass("parentDisable");
}
$("#cardContainer").click(function() {
if ($('#cardContainer').hasClass('parentDisable')) {
$("#settings").hide(500);
$("#cardContainer").toggleClass("parentDisable");
}
});
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return "" + parseInt(result[1], 16) + ", " + parseInt(result[2], 16) + ", " + parseInt(result[3], 16);
}
function themeChange(color) {
var rgbColor = hexToRgb(color.value);
document.querySelector(":root").style.setProperty(color.name, rgbColor);
localStorage.setItem(color.name, rgbColor);
}
function swapStyleSheet() {
var bg = localStorage.getItem('--bg-color');
var logo = localStorage.getItem('--logo-color');
var accent = localStorage.getItem('--accent-color');
if (bg) {
document.querySelector(":root").style.setProperty("--bg-color", bg);
}
if (logo) {
document.querySelector(":root").style.setProperty("--logo-color", logo);
}
if (accent) {
document.querySelector(":root").style.setProperty("--accent-color", accent);
}
}
document.addEventListener("DOMContentLoaded", function() {
swapStyleSheet();
});