-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
43 lines (40 loc) · 1.45 KB
/
script.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
const themeSelector = document.querySelector('#themeSelector');
const themeStyleSheet = document.querySelector('#themeStyleSheet');
let themeValue = 1;
function lastSelectedTheme(){
themeValue = localStorage.getItem('selectedTheme');
if(themeValue === '1'){
themeStyleSheet.href = 'styles/themes/theme-1.css';
themeSelector.value = localStorage.getItem('toggleValue');
}
else if(themeValue === '2'){
themeStyleSheet.href = 'styles/themes/theme-2.css';
themeSelector.value = localStorage.getItem('toggleValue');
}
else if(themeValue === '3'){
themeStyleSheet.href = 'styles/themes/theme-3.css';
themeSelector.value = localStorage.getItem('toggleValue');
}
}
function selectTheme(){
lastSelectedTheme();
themeSelector.addEventListener('input',function(){
themeValue = themeSelector.value;
if(themeValue === '1'){
themeStyleSheet.href = 'styles/themes/theme-1.css';
}
else if(themeValue === '2'){
themeStyleSheet.href = 'styles/themes/theme-2.css';
}
else if(themeValue === '3'){
themeStyleSheet.href = 'styles/themes/theme-3.css';
}
if (typeof(Storage) !== 'undefined') {
localStorage.setItem('selectedTheme', themeValue);
localStorage.setItem('toggleValue', themeValue);
}else {
console.log('Sorry! No Web Storage support');
}
})
}
selectTheme();