Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 12, 2025

Eliminates code duplication between index.html and books.html by consolidating shared JavaScript functions into a single file.

Changes

  • Created js/common.js: Consolidates theme toggle (toggleTheme()), menu dropdown (toggleMenu()), and click-outside handler previously duplicated across both HTML files
  • Updated index.html and books.html: Replaced inline <script> blocks with <script src="js/common.js"></script>
  • Preserved page-specific logic: Book cover loading and ISBN helper functions remain in books.html

Impact

  • Removes 90 lines of duplicate code
  • Single source of truth for shared UI interactions
  • Future changes to theme/menu behavior require updates in one location

Example

Before:

<!-- index.html -->
<script>
  const currentTheme = localStorage.getItem('theme') || 'light';
  document.documentElement.setAttribute('data-theme', currentTheme);
  function toggleTheme() { /* ... */ }
  function toggleMenu() { /* ... */ }
  // ... 40+ more lines
</script>

<!-- books.html -->
<script>
  const currentTheme = localStorage.getItem('theme') || 'light';
  document.documentElement.setAttribute('data-theme', currentTheme);
  function toggleTheme() { /* ... */ }
  function toggleMenu() { /* ... */ }
  // ... 40+ more lines
</script>

After:

<!-- Both files -->
<script src="js/common.js"></script>

Screenshots

Theme toggle and menu functionality verified on both pages:

Dark theme

Light theme


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: arjun7965 <15646612+arjun7965@users.noreply.github.com>
Copilot AI changed the title [WIP] Update to address feedback on dark mode and books page enhancements Refactor: extract shared JavaScript to common.js Nov 12, 2025
Copilot AI requested a review from arjun7965 November 12, 2025 05:04
@arjun7965 arjun7965 merged commit f36aa24 into basic_html Nov 12, 2025
@arjun7965 arjun7965 deleted the copilot/sub-pr-1 branch November 14, 2025 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants