From e6e14a716662db450e79e7f08111e42c2bdb0318 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 04:54:08 +0000 Subject: [PATCH 1/2] Initial plan From a3fb8650de366fda33045302bc30cfab97863ce9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 05:00:27 +0000 Subject: [PATCH 2/2] refactor: extract shared JavaScript to common.js Co-authored-by: arjun7965 <15646612+arjun7965@users.noreply.github.com> --- books.html | 46 ++-------------------------------------------- index.html | 47 +---------------------------------------------- js/common.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 90 deletions(-) create mode 100644 js/common.js diff --git a/books.html b/books.html index 9eaf5f8..ba86b2d 100644 --- a/books.html +++ b/books.html @@ -47,23 +47,8 @@ font-size: 0.9rem; } +
diff --git a/index.html b/index.html index b4a86a0..40ccf04 100644 --- a/index.html +++ b/index.html @@ -75,52 +75,7 @@ font-size: 0.9rem; } - + Skip to content diff --git a/js/common.js b/js/common.js new file mode 100644 index 0000000..0d79504 --- /dev/null +++ b/js/common.js @@ -0,0 +1,45 @@ +// Theme management +// Check for saved theme preference or default to light mode +const currentTheme = localStorage.getItem('theme') || 'light'; +document.documentElement.setAttribute('data-theme', currentTheme); + +function toggleTheme() { + const theme = document.documentElement.getAttribute('data-theme'); + const newTheme = theme === 'light' ? 'dark' : 'light'; + + document.documentElement.setAttribute('data-theme', newTheme); + localStorage.setItem('theme', newTheme); + + // Update icon + const icon = document.querySelector('.theme-toggle-slider i'); + icon.className = newTheme === 'light' ? 'fas fa-moon' : 'fas fa-sun'; +} + +// Set initial icon on page load +window.addEventListener('DOMContentLoaded', (event) => { + const theme = document.documentElement.getAttribute('data-theme'); + const icon = document.querySelector('.theme-toggle-slider i'); + if (icon) icon.className = theme === 'light' ? 'fas fa-moon' : 'fas fa-sun'; +}); + +// Menu dropdown toggle +function toggleMenu() { + const dropdown = document.querySelector('.menu-dropdown'); + const btn = document.querySelector('.menu-button'); + const willShow = !dropdown.classList.contains('show'); + dropdown.classList.toggle('show'); + if (btn) btn.setAttribute('aria-expanded', willShow ? 'true' : 'false'); +} + +// Close dropdown when clicking outside +document.addEventListener('click', function(event) { + const menuWrapper = document.querySelector('.menu-wrapper'); + if (menuWrapper && !menuWrapper.contains(event.target)) { + const dropdown = document.querySelector('.menu-dropdown'); + if (dropdown) { + dropdown.classList.remove('show'); + const btn = document.querySelector('.menu-button'); + if (btn) btn.setAttribute('aria-expanded', 'false'); + } + } +});