How rikilele/custom-dict-chrome works
Main components
• Manifest & Configuration: At the heart of the extension is the manifest.json file. It defines the extension’s permissions, background scripts, content scripts, popups, and settings pages.
• Background Script (background/background.js): This script runs in the background, manages events (such as browser actions or context menu triggers), and communicates with other components.
• Content Script (contentScript/contentScript.js and associated CSS): Injected into web pages to enable the highlighting feature; it detects words on pages and applies the custom definitions.
• Popup UI (popup/popup.html, popup/popup.js): Provides a user interface accessible via the browser toolbar for manual dictionary editing and quick interactions.
• Settings UI (settings/settings.html, settings/settings.js, settings/settings.css): Allows users to further manage their custom dictionary and allowlist.
Relationships and interactions
• The manifest.json serves as the extension's blueprint, linking the background script, content script, popup, and settings.
• The background script acts as the central hub that listens for events (like a right-click context menu or interactions from the popup) and passes information or commands between different components.
• The content script interacts directly with the web page. It receives instructions from the background or listens for user selections and then highlights matching words.
• Communication flows between the popup/settings UI and the background script using Chrome’s message-passing system, ensuring that user modifications to the dictionary data are synchronized across the extension.
• The popup and settings pages are independent UI layers that connect to the background script for configuration and data persistence (likely using the Chrome storage API).
Important architectural patterns/design principles
• Decoupled, event-driven architecture: The background script handles events and coordinates the interactions, keeping the UI and content script independent.
• Separation of concerns: Each directory encapsulates a specific responsibility (e.g., background processing, content injection, UI rendering), making it easy to extend or modify individual parts.
• A clear division between configuration (manifest), service logic (background), UI components (popup/settings), and page manipulation (content script).
Relevant technologies/frameworks
• Chrome Extension API: For managing background tasks, content injection, and messaging.
• Standard web technologies (HTML, CSS, JavaScript): For the user interfaces in popup and settings, and for dynamically modifying webpages via the content script.