Skip to content

Conversation

@gupsammy
Copy link
Owner

Summary

This PR consolidates duplicated code across the extension by extracting shared modules for settings management, file helpers, and injection scripts. This improves maintainability and reduces the burden of future updates.

Changes

  • Extract settings management (STORAGE_KEY, DEFAULT_SETTINGS, loadSettings, saveSettings) into a centralized settings.js module
  • Extract file/path utilities (sanitizeImageFilename, generatePageSubfolder, rewriteImagePaths) into file-helpers.js
  • Extract the list of content scripts to inject into injection-files.js to avoid duplication between background.js and popup.js
  • Update background.js, popup.js, and lib/platform.js to use these shared modules

Commits

  • b66e33b - refactor: extract injection scripts list into shared module
  • 2f21d7a - refactor: extract shared settings and file helpers into modules

Files Changed

  • background.js: Simplified by removing duplicated settings and file helper logic
  • popup.js: Simplified by removing duplicated settings and injection script list
  • lib/platform.js: Simplified by removing duplicated file helper logic
  • settings.js: New centralized settings management module
  • file-helpers.js: New centralized file/path utilities module
  • injection-files.js: New module for shared injection scripts list

gupsammy and others added 2 commits November 28, 2025 21:43
Extract duplicated settings and file handling logic from background.js, popup.js,
and lib/platform.js into two new shared modules:

- settings.js: Centralized settings management (STORAGE_KEY, DEFAULT_SETTINGS,
  loadSettings, saveSettings) used by background.js and popup.js
- file-helpers.js: Unified file/path utilities (sanitizeImageFilename,
  generatePageSubfolder, rewriteImagePaths, folder constants) accessible in
  service worker, content scripts, and popup contexts

This reduces code duplication and improves maintainability by consolidating
shared logic in a single location.
Extract the list of content scripts to inject into a centralized module (injection-files.js) to avoid duplication and reduce maintenance burden. Both background.js and popup.js now reference this shared list through EzyCopyInjection.CONTENT_SCRIPTS, ensuring consistent script injection across different trigger paths.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
@claude
Copy link
Contributor

claude bot commented Nov 28, 2025

Claude finished @gupsammy's task —— View job


Code Review Complete ✓

Todo List

  • Read all changed files
  • Verify module imports and usage
  • Check manifest.json for module declarations
  • Look for critical/high priority issues
  • Post review feedback

Review Summary

This refactoring looks good to ship. The module consolidation is clean and doesn't introduce any functional issues.

What I Verified

Module structure: All three new modules use proper IIFE patterns with redeclaration guards
Import contexts: Correct loading mechanisms for each context (importScripts for service worker, script tags for popup, injection for content scripts)
Injection order: file-helpers.js loads before lib/platform.js as required
Backward compatibility: lib/platform.js maintains global function references
No manifest changes needed: Modules are loaded contextually, not declared

Code Quality

The refactoring successfully:

  • Eliminates ~46 net lines of duplicated code
  • Centralizes settings management to a single source of truth
  • Makes the injection script list DRY between background.js and popup.js
  • Maintains all existing functionality

No critical or high-priority issues found. The code is ready to merge.


@gupsammy gupsammy merged commit 9adc88d into main Nov 29, 2025
3 checks passed
@gupsammy gupsammy deleted the refactor/shared-modules branch November 29, 2025 05:39
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