How deep2universe/youtube-motion-tracking works
1. What this repo is
- This is a Chrome Extension Manifest V3 project that augments the YouTube page itself. The runtime is split between a content script injected into YouTube, a background service worker, and extension UI surfaces like the popup and options page.
2. Primary runtime boundary
- The main boundary is “extension code” vs “YouTube page DOM”. src/content.js is the central orchestrator that runs in the YouTube tab, reads the player/video state, injects overlays and styles, and coordinates pose tracking, animations, filters, and game mode.
3. Page overlay and DOM integration
- src/content.css plus the src/themes/*.css files define the visual layer that is injected into the YouTube page. This includes Halloween UI theming, overlay containers, particle layers, and player-adjacent controls. The theme is additive: it changes YouTube’s look without replacing core YouTube functionality.
4. Pose detection and motion analysis
- The AI pipeline centers on TensorFlow.js MoveNet. src/detectUtils.js, src/motionDetector.js, src/motionDetectors.js, src/motionPatterns.js, src/motionEnum.js, and src/gameConfig.js handle keypoint interpretation, motion classification, and movement pattern thresholds.
- Data flow here is: video frame / pose keypoints → motion interpretation → event triggers. This is the foundation for both animations and game mode.
5. Animation subsystem
- src/anim.js is the main rendering/animation engine, with src/animEnum.js defining the available effects. src/jumpMarkers.js and src/ghostCharacter.js support visual reactions and game feedback.
- The README indicates a dual rendering strategy using Canvas 2D and WebGL, so the diagram should show overlays being drawn over the YouTube player, not inside the video itself.
6. Effects composition
- src/filterEnum.js defines horror video filters, which are visually separate from motion-triggered animations but can be applied together. This means the architecture has two visual effect paths:
- motion-driven overlays/animations
- video-wide filters / style transforms
- The system is designed so these layers can stack.
7. Motion Game Mode
- src/gameMode.js and src/gameModeEnum.js implement a stateful “game” layer on top of motion tracking. Rather than animating the page directly, it translates detected movement into gameplay events like ghost jumps and scoring.
- Conceptually, this is a separate subsystem that consumes motion events and emits game state updates, score persistence, and feedback effects.
8. Extension UI and configuration
- src/popup.html/js and src/options.html/js are the user control surfaces. The popup appears to be the primary in-player control for selecting animations, filters, theme settings, and game mode; the options page handles persistent configuration.
- These pages are likely connected to content-script state through Chrome extension messaging and storage APIs.
9. Background/service worker role
- src/background.js is the MV3 service worker. The README says it monitors URLs, so its job is likely to keep extension state aligned with tab navigation and YouTube page changes, not to render UI or run detection.
10. State and persistence
- Persistent user choices and game stats are part of the architecture even if the exact storage layer is not visible from the tree. The presence of popup/options pages, game scoring, and theme intensity controls implies a Chrome storage-backed settings layer used by the content script and UI.
11. Build and delivery pipeline
- The repo is bundled with Parcel (package.json, package-lock.json), producing a distributable extension in dist/.
- build-for-store.sh packages a release ZIP for Chrome Web Store-style distribution, while manifest.json in src/ defines the extension entrypoints and permissions.
12. Non-runtime support assets
- debug_scripts/, dev_docs/, and .kiro/specs/ are support and planning artifacts rather than runtime subsystems. They document diagnosis, fixes, architecture decisions, and testing, which is useful for understanding evolution but should not be drawn as active components in the runtime diagram.
13. External dependencies that matter architecturally
- YouTube is the host environment the extension hooks into.
- TensorFlow.js / MoveNet is the AI inference dependency.
- Proton Engine is used for particle-style visual effects.
- WebGL + Canvas 2D are the rendering backends for overlays and effects.
14. High-level data flow to diagram
- User action in popup/options or page state on YouTube → extension state changes → content script coordinates detection/rendering → pose/motion modules emit signals → animation/filter/game subsystems render results over the player → background service worker keeps tab/navigation state in sync.
Main entry points: content.js Content script · motionDetector.js Motion detector · manifest.json Manifest · gameMode.js Game mode
Components 24
Extension runtime
Core MV3 code that runs in the YouTube tab and in the service worker.
- Content script · Runs in the YouTube tab, reads player state, injects overlays, and coordinates subsystems.
src/content.js - Service worker · Background entrypoint that keeps extension state aligned with tab and URL changes.
src/background.js - Manifest · Defines extension permissions, pages, and runtime wiring.
src/manifest.json
Motion pipeline
Pose detection, motion interpretation, and game-event generation.
- Pose utils · Normalizes pose keypoints and detection helpers for downstream motion logic.
src/detectUtils.js - Motion detector · Interprets keypoints and identifies motion signals from the video feed.
src/motionDetector.js - Detector set · Collection of motion detectors used for specific movement types.
src/motionDetectors.js - Motion patterns · Pattern definitions and thresholds used to recognize gestures and actions.
src/motionPatterns.js - Motion types · Shared motion event vocabulary used across the pipeline.
src/motionEnum.js - Game config · Thresholds and tuning values for game-mode motion behavior.
src/gameConfig.js - Game mode · Consumes motion events and turns them into gameplay, scoring, and reset logic.
src/gameMode.js - Game states · Game-mode state and mode definitions.
src/gameModeEnum.js
Visual effects
Overlay rendering, animations, filters, and themed styling layered on top of YouTube.
- Animator · Main animation engine that renders motion-reactive overlays and feedback.
src/anim.js - Effects enum · Available animation effect definitions.
src/animEnum.js - Video filters · Horror-style video-wide filters and style transforms that can stack with animations.
src/filterEnum.js - Jump markers · Visual markers used for jump and reaction feedback.
src/jumpMarkers.js - Ghost character · Game-feedback character used for motion-driven reactions.
src/ghostCharacter.js - Overlay styles · Base injected CSS for overlays, controls, and player-adjacent visuals.
src/content.css - Theme layer · YouTube theme variables, particles, colors, and additive Halloween styling.
src/themes/youtube-theme.css
User surfaces
Popup and options pages for control and persistence.
- Popup UI · Primary in-player control surface for animations, filters, themes, and game mode.
src/popup.html - Popup logic · Popup behavior and state synchronization logic.
src/popup.js - Options page · Persistent configuration surface for extension preferences.
src/options.html - Options logic · Options-page behavior and storage-backed settings handling.
src/options.js
Other components
- YouTube · The embedded host environment that the extension augments.
- Store build · Release packaging script used to produce distributable extension builds.
build-for-store.sh
Connections 24
- Manifest → Content script: loads · Registers the content script as the main YouTube-tab runtime.
- Manifest → Service worker: loads · Registers the service worker entrypoint.
- Manifest → Popup UI: opens · Connects the popup surface to the extension action.
- Manifest → Options page: opens · Connects the options surface to extension settings.
- Content script → YouTube: augments · Reads player state and injects overlays into the host page.
- Service worker → Content script: syncs · Keeps tab and navigation state aligned with the active YouTube page.
- Popup logic → Content script: controls · Updates runtime modes and selected effects.
- Options logic → Content script: persists · Writes and restores configuration used by the content script.
- Content script → Pose utils: feeds · Supplies video and pose data to detection helpers.
- Pose utils → Motion detector: normalizes · Prepares keypoints for interpretation.
- Motion detector → Detector set: delegates · Uses specialized detectors for different movement types.
- Detector set → Motion patterns: matches · Applies pattern thresholds and gesture rules.
- Motion detector → Motion types: emits · Maps recognized actions into shared motion event types.
- Motion detector → Game config: tuned by · Uses game-specific thresholds and sensitivity settings.
- Motion detector → Game mode: triggers · Motion events become gameplay actions and resets.
- Game mode → Game states: states · Uses game-state definitions to manage progression.
- Content script → Animator: drives · Routes motion and UI state into the animation engine.
- Animator → Effects enum: selects · Chooses from available animation effects.
- Content script → Video filters: applies · Applies video-wide visual filters alongside animations.
- Overlay styles → YouTube: styles · Injects overlay and player-adjacent styling into the page.
- Theme layer → YouTube: themes · Adds additive YouTube theming and particle visuals.
- Game mode → Jump markers: feedback · Uses jump markers as motion-game feedback.
- Game mode → Ghost character: feedback · Uses the ghost character for game reactions.
- Store build → Manifest: packages · Bundles the extension using the manifest-defined entrypoints.