How vastnext/lexilayer-translator works
LexiLayer is a Chrome browser translation extension. A reader configures an engine and language in the popup, starts a page translation, and the content script scans and schedules text, sends batches to the background service worker, then renders returned translations in the page. The options page manages AI engines, expert prompts, preferences, and vocabulary. Separate branches support selection and input translation, video subtitles, local caching, and Anki synchronization. The README documents these capabilities; several subsystem connections are shown as unverified where sampled code did not expose their wiring.
Main entry points: background/index.ts Message and task coordinator · content/index.ts Page controller · provider-registry.ts Provider registry · VocabularySection.tsx Vocabulary manager
Components 30
Extension controls
- Translation controls
src/popup/PopupApp.tsx - Engine settings
src/options/OptionsApp.tsx - Options API
src/options/api.ts - Shared configuration
src/shared/config.ts - Expert prompts
src/shared/experts.ts
Page translation
- Content entry
src/content/main.ts - Page controller
src/content/index.ts - DOM scanner
src/content/dom-scanner.ts - Site rules
src/rules/catalog.ts - Visible scheduler
src/content/scheduler.ts - Paragraph state
src/content/paragraph-store.ts - Page renderers
src/content/dom-renderer.ts - Selection translation
src/content/selection-controller.ts
Translation services
- Message and task coordinator
src/background/index.ts - AI coordinator
src/background/ai-coordinator.ts - Provider registry
src/background/provider-registry.ts - Google client
src/background/google-translate-client.ts - Bing client
src/background/bing-translate-client.ts - OpenAI client
src/background/openai-client.ts - Translation cache
src/background/cache.ts
Vocabulary
- Vocabulary manager
src/options/VocabularySection.tsx - Vocabulary storage
src/background/vocabulary-storage.ts - Anki synchronization
src/background/anki-client.ts - Vocabulary model
src/shared/vocabulary.ts
Video subtitles
- YouTube subtitles
src/content/youtube/session.ts - Subtitle renderer
src/content/subtitles/renderer.ts - Bilibili subtitles
src/content/bilibili/index.ts
Other components
- Reader
- Translation providers
- AnkiConnect
Connections 35
- Reader → Translation controls: chooses translation
README.md - Translation controls → Content entry: commands page
- Reader → Engine settings: configures
README.md - Engine settings → Options API: updates settings
src/options/OptionsApp.tsx - Options API → Shared configuration: uses settings model
src/options/api.ts - Content entry → Page controller: assembles
src/content/main.ts - Page controller → DOM scanner: scans text
src/content/main.ts - Page controller → Site rules: loads site rule
- Page controller → Visible scheduler: schedules batches
src/content/main.ts - Page controller → Paragraph state: tracks paragraphs
src/content/index.ts - Page controller → Page renderers: renders results
src/content/main.ts - Visible scheduler → Page controller: runs worker
src/content/main.ts - Page controller → Message and task coordinator: requests translation
- Message and task coordinator → AI coordinator: coordinates AI
src/background/index.ts - Message and task coordinator → Provider registry: creates provider
src/background/index.ts - Provider registry → Google client: selects client
- Provider registry → Bing client: selects client
- Provider registry → OpenAI client: selects client
- Google client → Translation providers: sends translation
- Bing client → Translation providers: sends translation
- OpenAI client → Translation providers: sends translation
- Message and task coordinator → Translation cache: reads and writes
src/background/index.ts - Message and task coordinator → Shared configuration: loads preferences
src/background/index.ts - AI coordinator → Expert prompts: uses expert prompts
- Reader → Selection translation: selects text
README.md - Selection translation → Message and task coordinator: requests translation
- Reader → Vocabulary manager: manages saved words
README.md - Vocabulary manager → Vocabulary model: validates entries
src/options/VocabularySection.tsx - Message and task coordinator → Vocabulary storage: stores entries
src/background/index.ts - Vocabulary manager → Anki synchronization: starts sync
src/options/VocabularySection.tsx - Anki synchronization → AnkiConnect: sends notes
- YouTube subtitles → Message and task coordinator: requests translation
- YouTube subtitles → Subtitle renderer: renders subtitles
- Bilibili subtitles → Message and task coordinator: requests translation
- Bilibili subtitles → Subtitle renderer: renders subtitles