How iitc-ce/iitc-button works
Main Components
• Browser Extension Core:
• Background Scripts: Located in “src/background” which handle core background tasks (e.g., network requests, script injection, and utilities).
• Content Scripts: Found in “src/content-scripts” that interact with the webpage, injecting UI or bridging communications.
• Manifest File: “src/manifest.json” defining the extension’s permissions, scripts, and configuration for the browser.
• User Interface (UI) Components:
• Popup UI: Components, views, and supporting data in “src/popup” include Vue components like Alert.vue, Header.vue, and others for the popup interface.
• In-Page/UI Overlays: “src/jsview” (with App.vue, Header.vue, etc.) and “src/settings” housing additional UI components for the settings and advanced features.
• Assets and Localization:
• Public Assets: “public” folder contains static HTML files (e.g., browser-extension.html, index.html), images, and font assets.
• Localization: “public/_locales/…” directory holds translations and locale-specific JSON files.
• Build, Configuration, and Integration:
• Build Files & Scripts: Various npm scripts (build_mv2, build_mv3_firefox, build_mv3_chrome, build_mv3_safari) as defined in package.json, along with Babel, ESLint, and vue.config.js.
• GitHub Workflows: The “.github/workflows” folder shows CI/CD pipelines that build, test, and publish the extension.
• Safari-Specific Implementation:
• Safari: Separate directory with an Xcode project (for both macOS and iOS), shared source files, and pre-build scripts to tailor the extension for Safari environments.
Relationships and Interactions
• Data Flow & Communication:
• The background scripts are at the core, managing logic and network communications.
• Content scripts serve as the bridge between the extension and the web page, interacting with the DOM and routing messages to/from background scripts.
• The popup and settings UIs (composed in Vue.js) interact with the background layer through messaging APIs.
• Build & Deployment Flow:
• The project configuration files, along with the npm scripts and GitHub actions, define the build pipelines for various targets (Chrome, Firefox, Safari).
• For Safari, the Xcode project is used to compile and deploy the native-like extension bundle, highlighting platform-specific adjustments.
• Internationalization:
• Localization files (in “public/_locales”) ensure that messages and UI text are available in multiple languages.
Architectural Patterns and Design Principles
• Modular Separation:
• Clear separation of concerns: background scripts vs. content scripts vs. UI components.
• Distinct directories for platform-specific code (Safari) and common code.
• MVVM for UI Components:
• Use of Vue.js components suggests a Model-View-ViewModel approach to manage state and view logic in the popup, settings, and in-page elements.
• Build and CI/CD Pipeline:
• The presence of detailed GitHub workflows indicates an automated build, focus on manifest-based differentiations, and continuous integration for quality assurance.
• Localization and Internationalization:
• A dedicated structure for managing file-based translations supports global usage.