-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththeme-switcher.js
More file actions
32 lines (29 loc) · 1.08 KB
/
theme-switcher.js
File metadata and controls
32 lines (29 loc) · 1.08 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
// Theme switcher functionality
document.addEventListener('DOMContentLoaded', function() {
// Create theme switcher button
const navbar = document.querySelector('.navbar-right');
const themeButton = document.createElement('button');
themeButton.innerHTML = '🌙';
themeButton.className = 'theme-switcher';
themeButton.style.cssText = `
background: none;
border: none;
font-size: 1.2em;
cursor: pointer;
padding: 0.5em;
margin-left: 1em;
`;
navbar.appendChild(themeButton);
// Theme switching logic
let isDark = true;
const darkTheme = 'darkly';
const lightTheme = 'cosmo';
function switchTheme() {
const currentTheme = document.documentElement.getAttribute('data-bs-theme');
const newTheme = currentTheme === darkTheme ? lightTheme : darkTheme;
document.documentElement.setAttribute('data-bs-theme', newTheme);
themeButton.innerHTML = newTheme === darkTheme ? '🌙' : '☀️';
isDark = !isDark;
}
themeButton.addEventListener('click', switchTheme);
});