How ilyhalight/voice-over-translation works
Project Type and Purpose
• This is not a traditional full-stack web app but a browser user-script extension (“VOT”) that runs in Tampermonkey (or similar) to inject voice-over translation and subtitles into arbitrary video pages (YouTube, other sites).
• The README emphasizes features like on-the-fly translation (via Yandex.Translate or proxy), subtitle display & saving, audio export, UI customization, volume sync, and multi-language support.
Key Architectural Components
a. Development & CI
• GitHub repository with CI workflows (.github/workflows/build.yml, release.yml).
• Linting/precommit via Husky, ESLint, Prettier.
• Patch-package workflows for vendored dependency fixes (patches/).
• Localization generation tool (scripts/wiki-gen and @toil/localize-tui).
• Tests folder.
b. Build & Distribution
• Build scripts in package.json (npm run build, build:min, etc.).
• Output artifacts in dist/ (vot.user.js, vot-min.user.js).
• Dependencies managed via npm or Bun (bun.lock, package-lock.json).
c. Runtime (Injected User Script)
• src/index.js: entry point registered as user script.
• Core modules under src/:
• config (config.js)
• localization (hashes.json, locales, provider)
• ui (ui.js, ui/tooltip.ts) and styles (SCSS under src/styles)
• subtitle orchestration (subtitles.js)
• utilities (VideoObserver, storage, translateApis, volume control, errors)
• Type definitions (global.d.ts, index.d.ts, tooltip.ts).
d. External Services
• Yandex.Translate API (direct or via proxy servers)
• Proxy servers (vot-worker, media-proxy) for CORS or media-format support
• VOT-Backend for unsupported video formats
• Supported site pages (YouTube, others) where script is injected
Relationships & Data Flows
• VideoObserver → passes frames/time events → Subtitles Manager → UI overlay
• Audio Mixer → injects <audio> element or AudioContext → output mixed track
• UI Controls → user actions (volume slider, language select) → Config & Storage
• Build Pipeline → produces user script → deployed via GitHub Releases
Architectural Patterns & Principles
• Modular separation (config / localization / UI / utils)
• Single Responsibility per module (VideoObserver only watches player events, TranslateApis only handles API calls, etc.)
• Adapter pattern for translation backends (direct vs. proxy vs. backend)
• Observer pattern for video time updates & UI refresh
• Plugin-style localization (load JSON bundles)
• Build-time patch integration via patch-package
Essential Details
• Be explicit about the injection environment (Tampermonkey host context).
• How localization is loaded at startup.
• How SCSS styles compile into inline <style> or imported CSS.
• Patch-package mechanism at build time.
• Don’t omit the script’s interplay with browser storage and page DOM.
• Detail the external proxy/back-end services enabling translation and media handling.