How devloker/theme-switcher works
Project type and purpose
• This is a browser extension (specifically a Chrome extension) named “Dark Light Mode Switcher.”
File structure
• Top-level files:
• package.json, package-lock.json, tsconfig*.json, vite.config.ts (build & config)
• index.html (extension’s popup host)
• src/: main code
• src/Popup.tsx + src/main.tsx — React-based popup UI
• src/scripts/injection/content.ts — content script injected into every page
• src/scripts/service-worker/background.ts — persistent background/service worker script
• src/constants, src/types, src/utils, src/styles — shared assets & type definitions
• Build output (dist/) is generated by Vite via npm run build.
README for additional insights
• Architecture overview is implicit:
• React popup for user interaction
• Background script to coordinate state or messaging
• Key tech: Vite, React, TypeScript, Chrome extension APIs, CSS filter hack.
a. Main components
• Browser (Chrome)
• Extension Popup (React UI)
• Background Service Worker (event-driven script)
• Content Script (injected into web pages)
• Chrome Extension APIs (messaging, storage)
b. Relationships & interactions
2. Popup UI sends a message to Background (chrome.runtime.sendMessage)
3. Background script receives toggle request → stores state (optional) → broadcasts to all tabs or current tab
4. Content script listens for messages → applies or removes CSS filter: invert on document.body
c. Architectural patterns & design principles
• Event-driven / message-passing between components
• Separation of concerns: UI logic (popup) vs page logic (content script) vs orchestration (background)
• Modular code: shared constants/types/utils imported by multiple components
d. Relevant technologies & libraries
• Chrome Extension Manifest v3 (service worker)
• React + TypeScript + Vite for building the popup
• CSS filter inversion hack
• Chrome runtime messaging & storage APIs