-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (24 loc) · 889 Bytes
/
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
// variable declare
let themeScreen = document.querySelector('.theme-screen');
let toggleSwitch = document.querySelector('.toggle-switch');
let switchIcon = document.querySelector('.material-icons');
let getStorageKey = localStorage.getItem('themeScreen');
// dark functionality
function darkMode() {
switchIcon.innerHTML = 'brightness_4';
themeScreen.classList.add('dark-mode');
localStorage.setItem('themeScreen', 'darkMode');
}
// light functionality
function lightMode() {
switchIcon.innerHTML = 'brightness_5'
themeScreen.classList.remove('dark-mode');
localStorage.setItem('themeScreen', 'lightMode');
}
// page load condition
if(getStorageKey === 'darkMode') { darkMode(); }
// toggle switch event
toggleSwitch.addEventListener('click', () => {
if(localStorage.getItem('themeScreen') !== 'darkMode') { darkMode(); }
else { lightMode(); }
});