How vibinex/chrome-extension works
Project type and purpose
• This is a browser extension (Chrome) that enhances code reviews on GitHub and Bitbucket by injecting personalized highlighting into the PR UI.
• Key purpose: intercept DOM in PR pages, compute/apply highlights based on user preferences, offer a popup UI for settings/triggers.
File structure
• manifest.json: declares extension metadata, permissions, content scripts, background scripts, popup.
• backgroundScript.js: persistent background page that listens for messages, manages state, possibly triggers API calls.
• popup/ (popup.html, popup.js, popup_css.css): UI layer for user interactions (initialization, settings, manual triggers).
• scripts/ : content scripts injected into GitHub/Bitbucket pages:
• init.js – detects the PR page and bootstraps orchestration
• orchestrator.js – central coordinator for incoming events (page load, user actions)
• api.js – communicates with external Vibinex services or local storage for user preferences
• highlighting.js – applies CSS classes or inline styles to code diffs
• repoHandlers.js – platform-specific logic for GitHub vs Bitbucket DOM structures
• triggerButton.js – inserts UI controls into the page
• signedOutIndicator.js – displays state if user isn’t logged in
• utilities.js, main.css – shared helper functions and styling
README for additional insights
• Technologies: pure JavaScript, Chrome Extension APIs, DOM manipulation, optional remote API.
Components & Interactions
a. Main components
• Browser (Chrome)
• Extension manifest (registration)
• Background script (backgroundScript.js)
• Content scripts (init.js, orchestrator.js, repoHandlers.js, highlighting.js, etc.)
• Popup UI (popup.html/js)
• External Vibinex API or storage (optional remote service)
• Target web pages (GitHub PR, Bitbucket PR)
b. Relationships & data flow
1. Browser loads the extension via manifest.json
2. On page navigation to a PR: content scripts are injected
3. init.js detects PR URLs and notifies orchestrator.js
4. orchestrator.js requests user preferences via api.js (Chrome.storage or remote API through background script)
5. api.js (in content or via message to backgroundScript.js) fetches config
6. orchestrator.js calls repoHandlers.js to map DOM elements
7. highlighting.js applies CSS/styling to code diffs
8. triggerButton.js optionally adds manual trigger controls
9. User opens popup → popup.js communicates with backgroundScript.js → may update preferences
10. backgroundScript.js persists settings to Chrome.storage or relays to remote API
c. Architectural patterns / design principles
• Event-driven: relies on Chrome runtime messaging and DOM events
• Separation of concerns:
• Manifest defines “what” to inject / run
• Background script handles persistent state, cross-origin API calls
• Content scripts handle DOM detection & manipulation
• Popup UI is isolated web UI communicating via messages
• Platform adapters (repoHandlers.js) abstract GitHub vs Bitbucket differences
d. Relevant technologies / frameworks
• Chrome Extension APIs (runtime, storage, tabs)
• Vanilla JavaScript and CSS
• External REST API (if user preferences are stored remotely)