Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
3kh0
GitHub Repository: 3kh0/3kh0.github.io-replit
Path: blob/main/js/settings.js
617 views
1
var tab = localStorage.getItem("tab");
2
if (tab) {
3
try {
4
var tabData = JSON.parse(tab);
5
} catch {
6
var tabData = {};
7
}
8
} else {
9
var tabData = {};
10
}
11
if (tabData.title) {
12
document.getElementById("title").value = tabData.title;
13
}
14
if (tabData.icon) {
15
document.getElementById("icon").value = tabData.icon;
16
}
17
18
var settingsDefaultTab = {
19
title: "Settings | 3kh0",
20
icon: "./images/logo.png",
21
};
22
23
function setTitle(title = "") {
24
if (title) {
25
document.title = title;
26
} else {
27
document.title = settingsDefaultTab.title;
28
}
29
30
var tab = localStorage.getItem("tab");
31
if (tab) {
32
try {
33
var tabData = JSON.parse(tab);
34
} catch {
35
var tabData = {};
36
}
37
} else {
38
var tabData = {};
39
}
40
if (title) {
41
tabData.title = title;
42
} else {
43
delete tabData.title;
44
}
45
localStorage.setItem("tab", JSON.stringify(tabData));
46
}
47
48
function setFavicon(icon) {
49
if (icon) {
50
document.querySelector("link[rel='icon']").href = icon;
51
} else {
52
document.querySelector("link[rel='icon']").href = settingsDefaultTab.icon;
53
}
54
55
var tab = localStorage.getItem("tab");
56
if (tab) {
57
try {
58
var tabData = JSON.parse(tab);
59
} catch {
60
var tabData = {};
61
}
62
} else {
63
var tabData = {};
64
}
65
if (icon) {
66
tabData.icon = icon;
67
} else {
68
delete tabData.icon;
69
}
70
localStorage.setItem("tab", JSON.stringify(tabData));
71
}
72
73
function resetTab() {
74
document.title = settingsDefaultTab.title;
75
document.querySelector("link[rel='icon']").href = settingsDefaultTab.icon;
76
document.getElementById("title").value = "";
77
document.getElementById("icon").value = "";
78
localStorage.setItem("tab", JSON.stringify({}));
79
}
80
81
function setTheme(theme) {
82
localStorage.setItem("theme", theme);
83
document.body.setAttribute("theme", theme);
84
document.body.style = '';
85
localStorage.removeItem('theme_color');
86
87
themes.forEach(palette => {
88
if (palette.theme == theme) {
89
document.querySelector('#theme_color').value = palette.color;
90
}
91
});
92
}
93
94
function setThemeColor(theme) {
95
localStorage.setItem('theme', 'custom');
96
localStorage.setItem('theme_color', theme);
97
document.body.setAttribute('theme', 'custom');
98
document.body.style = `--theme: ${theme}; --background: ${getContrastHex(theme)}; --text: ${getColorHex(theme)}; --text-secondary: ${getColorHex(theme)};`;
99
}
100
101