How mibrahimy/focusguard-extension works
Project type and purpose
• This is a browser extension (Chrome / Edge Manifest V3) called “FocusGuard.”
• Its goal is to intercept visits to specified websites, prompt the user for an intention, run a timed focus session, track and store session data, and display analytics in a dashboard.
File structure
• manifest.json: core extension configuration (permissions, entry points).
• background/service-worker.js: the persistent worker that listens for tab/navigation events, schedules reminders, processes messages, and interfaces with chrome.storage.
• content/: scripts injected into monitored pages to render the overlay UI (focus prompt, timer, reminders) and communicate with the background.
• popup/: UI for quick settings (select sites, view recent intentions, start session manually).
• dashboard/: full analytics interface (session history, charts, exports).
README for additional insights
• Uses Chrome Storage API (chrome.storage.local) for private, on-device data.
• Relies on chrome.tabs, chrome.activeTab, chrome.scripting to detect and inject content scripts.
• Provides dark/light theme support and local-only data export.
a. Main components
• Browser Host (Chrome/Edge)
• Manifest V3 → declares component entry points and permissions
• Background Service Worker (background/service-worker.js)
• Content Scripts (injected into monitored web pages)
• Popup UI (popup/popup.html + popup.js + popup.css)
• Dashboard UI (dashboard/dashboard.html + dashboard.js + dashboard.css)
• Local Storage (chrome.storage.local)
• External Website Domains (monitored sites)
b. Relationships & interactions
1. User navigates to a monitored site → Browser triggers background “onUpdated”/“onActivated” → background checks URL pattern.
2. If matched, background.injects content-script into page via chrome.scripting.
3. Content-script renders intention overlay and timer UI, sends “session-start” / “intent-selected” messages back to background.
4. Background persists session metadata in chrome.storage.local.
5. Content-script handles reminders and sends “session-end” / “session-pause” events to background.
6. Popup UI and Dashboard UI retrieve and update settings & analytics by querying background or directly reading chrome.storage.local.
c. Architectural patterns & design principles
• Event-driven messaging between background and UI/content scripts
• Single source of truth in chrome.storage.local for session and settings data
• Separation of concerns:
• Background: orchestration, storage, event handling
• Content: in-page UI, user interaction hooks
• Popup / Dashboard: configuration & analytics presentation
d. Key technologies/frameworks
• HTML/CSS/JS for UI
• Chrome Extension Manifest V3 (service worker model)
• chrome.storage API, chrome.tabs & chrome.scripting
• Optional charting library (e.g., Chart.js) in dashboard