Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions books.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,8 @@
font-size: 0.9rem;
}
</style>
<script src="js/theme.js"></script>
<script>
// 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';
}

// Helper: Normalize ISBN (remove hyphens/spaces)
function normalizeIsbn(isbn) {
return (isbn || '').toString().replace(/[^0-9X]/gi, '').toUpperCase();
Expand Down Expand Up @@ -184,12 +169,8 @@
attemptNext();
}

// Set initial icon on page load and resolve book covers
// Resolve book covers 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';

// Resolve covers with fallbacks/alternates
document.querySelectorAll('.book-cover img[data-isbn]').forEach(img => {
tryLoadCover(img);
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
font-size: 0.9rem;
}
</style>
<script src="js/theme.js"></script>
<script>
// Check for saved theme preference or default to light mode
const currentTheme = localStorage.getItem('theme') || 'light';
Expand Down
24 changes: 24 additions & 0 deletions js/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Theme toggle functionality shared across pages

// 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';
});