-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.js
59 lines (40 loc) · 1.62 KB
/
index.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
// initialization
const tabs = document.querySelectorAll(".tab-content")
const tabButtons = document.querySelectorAll(".tab-btn")
function openTab(evt, tabName){
tabs.forEach((tab) => {
tab.style.display = 'none'
})
tabButtons.forEach((btn) => btn.classList.remove("tab-active"))
document.querySelector(`[data-tab-name=${tabName}]`).style.display = 'block'
evt.target.classList.add("tab-active") // set current button to be active
}
function switchTheme(){
const themeSelector = document.querySelector("#theme-selector")
document.querySelector("html").setAttribute("data-theme", themeSelector.value)
}
if (localStorage.getItem('color-mode') === 'dark' || (!('color-mode' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('tw-dark')
updateToggleModeBtn()
} else {
document.documentElement.classList.remove('tw-dark')
updateToggleModeBtn()
}
function toggleMode(){
//toggle between dark and light mode
document.documentElement.classList.toggle("tw-dark")
updateToggleModeBtn()
}
function updateToggleModeBtn(){
const toggleIcon = document.querySelector("#toggle-mode-icon")
if (document.documentElement.classList.contains("tw-dark")){
// dark mode
toggleIcon.classList.remove("bi-sun-fill")
toggleIcon.classList.add("bi-moon-fill")
localStorage.setItem("color-mode", "dark")
}else{
toggleIcon.classList.add("bi-sun-fill")
toggleIcon.classList.remove("bi-moon-fill")
localStorage.setItem("color-mode", "light")
}
}