-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththemeswitcher.js
More file actions
23 lines (19 loc) · 949 Bytes
/
Copy paththemeswitcher.js
File metadata and controls
23 lines (19 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const themeIcon = document.getElementById('themeIcon');
// Add 'spacered' to the themes list
const themes = ['light', 'dark', 'terminalgreen', 'oceanblue', 'spacered'];
let currentThemeIndex = localStorage.getItem('themeIndex') || 0;
// Apply the initial theme from local storage or default
document.documentElement.setAttribute('data-theme', themes[currentThemeIndex]);
updateIcon(currentThemeIndex);
// Switch themes on icon click
themeIcon.addEventListener('click', () => {
currentThemeIndex = (parseInt(currentThemeIndex) + 1) % themes.length;
document.documentElement.setAttribute('data-theme', themes[currentThemeIndex]);
localStorage.setItem('themeIndex', currentThemeIndex);
updateIcon(currentThemeIndex);
});
// Update the theme icon based on the current theme
function updateIcon(themeIndex) {
const icons = ['fa-sun', 'fa-moon', 'fa-terminal', 'fa-water', 'fa-rocket'];
themeIcon.className = `fas ${icons[themeIndex]}`;
}