-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dark mode toggle feature with responsive styling and icon updates (…
…#33)
- Loading branch information
Showing
3 changed files
with
140 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,44 @@ | ||
const imageInput = document.getElementById('image-input'); | ||
const uploadButton = document.getElementById('upload-button'); | ||
const classificationResult = document.getElementById('classification-result'); | ||
const disposalInformation = document.getElementById('disposal-information'); | ||
|
||
uploadButton.addEventListener('click', () => { | ||
const image = imageInput.files[0]; | ||
const formData = new FormData(); | ||
formData.append('image', image); | ||
|
||
fetch('/classify', { | ||
method: 'POST', | ||
body: formData | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
classificationResult.textContent = data.classification; | ||
disposalInformation.textContent = data.disposalInformation; | ||
}) | ||
.catch(error => console.error(error)); | ||
const darkModeToggle = document.getElementById('dark-mode-toggle'); | ||
const body = document.body; | ||
const header = document.querySelector('header'); | ||
const footer = document.querySelector('footer'); | ||
const icon = document.getElementById('icon'); | ||
|
||
// Function to enable dark mode | ||
function enableDarkMode() { | ||
body.classList.add('dark-mode'); | ||
header.classList.add('dark-mode'); | ||
footer.classList.add('dark-mode'); | ||
icon.textContent = '☀️'; // Change icon to sun | ||
} | ||
|
||
// Function to disable dark mode | ||
function disableDarkMode() { | ||
body.classList.remove('dark-mode'); | ||
header.classList.remove('dark-mode'); | ||
footer.classList.remove('dark-mode'); | ||
icon.textContent = '🌙'; // Change icon to moon | ||
} | ||
|
||
// Event listener for dark mode toggle button | ||
darkModeToggle.addEventListener('click', () => { | ||
if (body.classList.contains('dark-mode')) { | ||
disableDarkMode(); // Switch to light mode | ||
} else { | ||
enableDarkMode(); // Switch to dark mode | ||
} | ||
}); | ||
|
||
// Optional: Check the initial mode on page load | ||
if (localStorage.getItem('dark-mode') === 'enabled') { | ||
enableDarkMode(); | ||
} | ||
|
||
// Save the mode in local storage | ||
darkModeToggle.addEventListener('click', () => { | ||
if (body.classList.contains('dark-mode')) { | ||
localStorage.setItem('dark-mode', 'enabled'); | ||
} else { | ||
localStorage.removeItem('dark-mode'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters