diff --git a/views/includes/navbar.ejs b/views/includes/navbar.ejs
index 69a9a3e9..c7e76a71 100644
--- a/views/includes/navbar.ejs
+++ b/views/includes/navbar.ejs
@@ -202,27 +202,33 @@
function toggleDarkMode() {
- const body = document.body;
- const navbar = document.querySelector(".navbar");
- const aboutSection = document.querySelector(".about");
- const darkModeToggle = document.querySelector(".dark-mode-toggle");
-
- const darkModeIcon = document.getElementsByClassName("dark-mode-icon");
- var darkModeIconCollection = Array.from(darkModeIcon);
-
- body.classList.toggle("dark-mode");
- navbar.classList.toggle("dark-mode");
- aboutSection.classList.toggle("dark-mode");
- // darkModeToggle.classList.toggle("dark");
-
- darkModeIconCollection.map((darkIcon) => {
- if (darkIcon.innerHTML === '') {
- darkIcon.innerHTML = '';
- } else {
- darkIcon.innerHTML = '';
- }
- });
+ const body = document.body;
+ const navbar = document.querySelector(".navbar");
+ const sections = document.querySelectorAll("main ,section, .about");
+ const darkModeIcon = document.querySelectorAll(".dark-mode-icon i");
+
+ body.classList.toggle("dark-mode");
+ navbar.classList.toggle("dark-mode");
+ sections.forEach(section => {
+ section.classList.toggle("dark-mode");
+ });
+
+ darkModeIcon.forEach(icon => {
+ icon.classList.toggle("fa-sun");
+ icon.classList.toggle("fa-moon");
+ });
+
+ // Store dark mode preference in local storage
+ localStorage.setItem('darkMode', body.classList.contains('dark-mode'));
+ }
+
+ // On page load, apply the theme based on local storage
+ document.addEventListener("DOMContentLoaded", () => {
+ const isDarkMode = JSON.parse(localStorage.getItem('darkMode'));
+ if (isDarkMode) {
+ toggleDarkMode(); // Apply dark mode if it was enabled
}
+ });