-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
82 lines (67 loc) · 2.35 KB
/
Copy pathscript.js
File metadata and controls
82 lines (67 loc) · 2.35 KB
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
const themes = {
LIGHT: "light",
DARK: "dark"
}
window.onload = function(){
const theme = localStorage.getItem("theme");
const navbar = document.querySelector(".navbar");
const table = document.querySelector(".table");
const homeLogo = document.getElementById('home-logo');
const customSwitch = document.getElementById("customSwitch");
const collapse = document.querySelector('.navbar-collapse');
collapse.addEventListener('click', clickListener);
customSwitch.checked = theme === themes.DARK || theme === null;
customSwitch.addEventListener("change", toggleTheme);
if(theme === themes.DARK || theme === null){
setDarkTheme();
} else {
setLightTheme()
}
function toggleTheme(event){
customSwitch.checked = event.target.checked;
setTheme(customSwitch.checked);
}
function setTheme(switchChecked){
if(switchChecked){
setDarkTheme();
} else {
setLightTheme();
}
}
function setDarkTheme(){
try {
document.querySelector('link[href="/style-light.css"]')
.setAttribute("href", "/style-dark.css");
localStorage.setItem("theme", themes.DARK);
homeLogo.setAttribute('src', './images/SH DARK.png');
homeLogo.classList.add('dark');
navbar.classList.add("navbar-dark");
navbar.classList.remove("navbar-light");
if(table){
table.classList.add("table-dark");
table.classList.remove("table-light");
}
} catch(e){}
}
function setLightTheme(){
try {
document.querySelector('link[href="/style-dark.css"]')
.setAttribute("href", "/style-light.css");
localStorage.setItem("theme", themes.LIGHT);
homeLogo.setAttribute('src', './images/SH LIGHT.png');
homeLogo.classList.remove('dark');
navbar.classList.remove("navbar-dark");
navbar.classList.add("navbar-light");
if (table) {
table.classList.remove("table-dark");
table.classList.add("table-light");
}
} catch(e){}
}
function clickListener({target}) {
if (target.classList.contains('nav-link') || target.id === 'home-logo') {
// document.querySelector('.collapse').collapse('hide');
$('.collapse').collapse('hide');
}
}
}