How bengmoh/filter-video works
Main Components
• Browser Extension Core: This is the overall client-side extension that manifests in the browser. It consists of multiple parts:
• Manifest (src/manifest.json and firefox/manifest.json): Declares the extension’s permissions, scripts, and settings.
• Background Script (src/background.js): Manages long-running background processes (e.g., listening for events, managing state).
• Content Script (src/content.js): Injected into web pages; responsible for detecting video elements and applying filters.
• Popup/Interaction UI:
• Popup UI (src/popup folder with popup.html, popup.js, and popup.scss): The front-end interface that the user interacts with from the browser toolbar.
• Utilities and Services:
• Key Mapping (src/utils/KeyMapping.js): Handles customizable shortcut keys including the special mapping between English and Arabic keyboards.
• Video Detection (src/utils/VideoDetection.js): Contains logic to detect videos within a web page and even handle iframe cases.
• Testing Layer:
• Test Scripts (tests folder): Used to validate extension functionality (e.g., extension.test.js and test setup).
Relationships and Interactions
• The manifest files dictate that when the extension is loaded, the background script and content script are activated.
• The background script may manage extension-wide state (for enabling/disabling, persisting settings using storage, etc.).
• The content script communicates directly with webpage DOM elements, leveraging the VideoDetection utility to identify video elements. When a video is detected, it might signal to the background or directly to the popup UI.
• The popup UI offers controls like filtering intensities and keyboard customization. The popup interacts with the background through messaging or reads/writes persistent settings.
• Utility modules (KeyMapping and VideoDetection) are shared across components to ensure consistent behavior when toggling filters based on key events.
• The build configuration files (webpack, babel) and test configurations (jest) drive the build and validate the code but are outside the runtime architecture.
Important Architectural Patterns and Principles to Capture
• Separation of Concerns: Clearly divide the extension’s functionality into presentation (popup), background processing, and webpage manipulation (content script).
• Event-Driven Architecture: Emphasize that the design is event-based – triggered by user keyboard shortcuts, video detections, or browser events (like tab updates).
• Modular Design: Illustrate that utility modules (KeyMapping, VideoDetection) encapsulate core logic shared across components.
• Cross-Platform Considerations: Note the dual manifest setup and handling differences between Chrome and Firefox.