forked from 3kh0/3kh0.github.io-replit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
99 lines (90 loc) · 2.29 KB
/
settings.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
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
var tab = localStorage.getItem("tab");
if (tab) {
try {
var tabData = JSON.parse(tab);
} catch {
var tabData = {};
}
} else {
var tabData = {};
}
if (tabData.title) {
document.getElementById("title").value = tabData.title;
}
if (tabData.icon) {
document.getElementById("icon").value = tabData.icon;
}
var settingsDefaultTab = {
title: "Settings | 3kh0",
icon: "./images/logo.png",
};
function setTitle(title = "") {
if (title) {
document.title = title;
} else {
document.title = settingsDefaultTab.title;
}
var tab = localStorage.getItem("tab");
if (tab) {
try {
var tabData = JSON.parse(tab);
} catch {
var tabData = {};
}
} else {
var tabData = {};
}
if (title) {
tabData.title = title;
} else {
delete tabData.title;
}
localStorage.setItem("tab", JSON.stringify(tabData));
}
function setFavicon(icon) {
if (icon) {
document.querySelector("link[rel='icon']").href = icon;
} else {
document.querySelector("link[rel='icon']").href = settingsDefaultTab.icon;
}
var tab = localStorage.getItem("tab");
if (tab) {
try {
var tabData = JSON.parse(tab);
} catch {
var tabData = {};
}
} else {
var tabData = {};
}
if (icon) {
tabData.icon = icon;
} else {
delete tabData.icon;
}
localStorage.setItem("tab", JSON.stringify(tabData));
}
function resetTab() {
document.title = settingsDefaultTab.title;
document.querySelector("link[rel='icon']").href = settingsDefaultTab.icon;
document.getElementById("title").value = "";
document.getElementById("icon").value = "";
localStorage.setItem("tab", JSON.stringify({}));
}
function setTheme(theme) {
localStorage.setItem("theme", theme);
document.body.setAttribute("theme", theme);
document.body.style = '';
localStorage.removeItem('theme_color');
themes.forEach(palette => {
if (palette.theme == theme) {
document.querySelector('#theme_color').value = palette.color;
}
});
}
function setThemeColor(theme) {
localStorage.setItem('theme', 'custom');
localStorage.setItem('theme_color', theme);
document.body.setAttribute('theme', 'custom');
document.body.style = `--theme: ${theme}; --background: ${getContrastHex(theme)}; --text: ${getColorHex(theme)}; --text-secondary: ${getColorHex(theme)};`;
}