-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdark_mode.js
More file actions
18 lines (17 loc) · 1.16 KB
/
dark_mode.js
File metadata and controls
18 lines (17 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
document.getElementById('darkModeToggle').addEventListener('click', function() {
const currentLink = document.querySelector('link[rel="stylesheet"]');
const currentButton = document.querySelector('#darkModeToggle');
if (currentLink.href === 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css' && currentButton.textContent === 'Disable Dark Mode') {
currentLink.remove();
document.head.insertAdjacentHTML('beforeend', '<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">');
document.head.insertAdjacentHTML('beforeend', '<link rel="stylesheet" href="style.css">');
const styleLink = document.querySelector('link[href="style_dark.css"]');
styleLink.remove();
currentButton.textContent = 'Enable Dark Mode';
} else {
currentLink.remove();
document.head.insertAdjacentHTML('beforeend', '<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">');
document.head.insertAdjacentHTML('beforeend', '<link rel="stylesheet" href="style_dark.css">');
currentButton.textContent = 'Disable Dark Mode';
}
});