How code-charity/youtube works
1. What this repo is
- This is a cross-browser YouTube extension, not a web app.
- Its runtime behavior is split between browser extension logic, YouTube-page content scripts, and a bundled settings/menu UI.
2. Top-level execution model
- manifest.json is the main integration point that tells the browser which scripts/styles run on YouTube.
- The extension also has browser-specific manifest variants under build/ for packaging, especially Firefox and legacy manifest differences.
3. Core runtime logic
- background.js is the extension-side coordinator.
- The js&css/extension/ tree contains the main page-facing logic and feature wiring:
- core.js for shared behavior
- functions.js for utilities
- init.js for bootstrapping
- This is the layer that reacts to YouTube page state and user settings.
4. YouTube feature subsystems
- Most functionality is organized by YouTube surface and feature area under js&css/extension/www.youtube.com/.
- Notable feature boundaries include:
- appearance/ for page layout and visual tweaks
- general/ for general page behavior
- night-mode/ for dark/night styling
- sidebar.js, plus related player/channel/blocklist/theme modules in the web-accessible tree
- This structure suggests the extension is modular: each feature can be enabled, styled, and maintained independently.
5. Content scripts vs page-context scripts
- js&css/web-accessible/ is a separate boundary for scripts and assets that must be reachable by the page context or injected in a more permissive way.
- It contains feature modules like player.js, channel.js, settings.js, themes.js, shortcuts.js, and blocklist.js.
- The split between extension/ and web-accessible/ is important: one side runs as extension-controlled content logic, the other exposes functionality/assets to the page or other injected contexts.
6. Settings and user interface
- The menu/ directory is the extension’s settings UI.
- menu/index.html, menu/index.js, and menu/sidepanel.html indicate a browser UI surface for configuring features.
- menu/satus.js and menu/skeleton*.js show the UI is built on the project’s own Satus component library, with feature-specific panels in menu/skeleton-parts/ and matching styles in menu/styles/.
- This UI is the main user control plane that drives which YouTube behaviors are enabled.
7. Localization pipeline
- _locales/ contains a large set of translation bundles, each with messages.json.
- These locale files are consumed by the extension UI and feature labels, allowing the same settings/menu experience across many languages.
- build/crowdin.yml indicates translations are also managed via Crowdin, so localization is partly externalized to a translation platform.
8. Styling and DOM manipulation
- CSS is a first-class part of the architecture: many features are implemented by injecting or toggling CSS under js&css/.../*.css.
- This aligns with the repo’s goal of lightweight YouTube modifications—many behaviors are visual or layout-based rather than full JavaScript replacements.
9. Build and packaging
- build/build.py, build/locale.py, and the manifest templates in build/ indicate a generated release pipeline rather than a single hand-written distribution artifact.
- There are separate packaging concerns for browser stores and browser variants, including Firefox and Safari workflows in .github/workflows/.
- The repo is designed to be shipped as unpacked extension code, but also as store-ready builds.
10. Quality gates and automated checks
- Tests are split into repo-level and unit-level checks under tests/.
- jest.config.js plus unit tests like themes-menu.test.js, thumbnails-per-row.test.js, and remaining-duration.test.js indicate feature-level regression coverage for specific YouTube behaviors.
- CI also runs linting for JavaScript, CSS, and test rules, reflecting a codebase with many DOM/CSS-driven feature toggles.
11. External integration points
- The primary external dependency is YouTube itself; nearly all runtime behavior is page-specific customization of youtube.com.
- The repo also depends on browser extension ecosystems: Chrome/Chromium, Firefox, Edge, Safari, Opera/Whale.
- Crowdin is the only clearly visible non-browser service in the architecture, used for translation management.
12. How data flows through the system
- User settings are edited in the menu UI, then consumed by feature modules in the extension runtime.
- Those modules inject scripts and CSS into YouTube pages, where they modify DOM, visibility, styling, and player/page behavior.
- Locale strings flow from _locales/ into the UI and feature labels, while build scripts transform source files into browser-specific packages.
13. Main architectural boundary to diagram
- The key separation is: browser extension shell + settings UI on one side, and YouTube page augmentation modules on the other.
- Inside the augmentation side, the cleanest sub-boundaries are: core/bootstrap, feature modules by YouTube surface, web-accessible page-context helpers, and CSS-based appearance tweaks.
Main entry points: extension/core.js Core · web-accessible/core.js Web core · index.js Menu app · background.js Background
Components 23
Extension shell
Browser integration, bootstrap, and runtime coordination.
- Manifest · Primary extension declaration and script wiring.
manifest.json - Background · Extension-side runtime coordinator.
background.js
YouTube augmentation
Content scripts and injected modules that modify YouTube pages.
- Core · Shared extension behavior for YouTube page logic.
js&css/extension/core.js - Functions · Utility functions used across extension runtime.
js&css/extension/functions.js - Init · Bootstraps page-facing extension behavior.
js&css/extension/init.js - Appearance · Layout and visual tweaks for YouTube surfaces.
js&css/extension/www.youtube.com/appearance - General · General page behavior and baseline UI changes.
js&css/extension/www.youtube.com/general - Night mode · Dark-mode styling and related behavior.
js&css/extension/www.youtube.com/night-mode - Web core · Shared helpers for injected page-context modules.
js&css/web-accessible/core.js - Player · Player-related injected logic and state handling.
js&css/web-accessible/www.youtube.com/player.js - Channel · Channel-page injected logic.
js&css/web-accessible/www.youtube.com/channel.js - Settings · Settings-related injected logic.
js&css/web-accessible/www.youtube.com/settings.js - Themes · Theme handling shared with the UI and page context.
js&css/web-accessible/www.youtube.com/themes.js - Shortcuts · Keyboard shortcut handling for YouTube.
js&css/web-accessible/www.youtube.com/shortcuts.js - Blocklist · Filtering and blocklist logic exposed to the page context.
js&css/web-accessible/www.youtube.com/blocklist.js
Settings UI
User-facing configuration and menu surfaces.
Build and release
Packaging, manifests, localization, and CI workflows.
- Locales · Localized message bundles for UI and feature labels.
_locales - Build scripts · Release build and locale generation scripts.
build/build.py - Build manifests · Browser-specific manifest templates for packaged builds.
build/manifest2.json - CI workflows · Automated build, lint, and release workflows.
.github/workflows
Connections 25
- Manifest → Background: loads · Declares the background runtime and extension entrypoints.
- Manifest → Init: injects · Registers page-facing scripts for YouTube.
- Background → Core: coordinates · Orchestrates extension-side behavior through the core layer.
- Background → Menu app: opens UI · Connects extension state to the settings interface.
- Init → Core: boots · Initializes shared content-script behavior.
- Core → Functions: uses · Relies on shared helpers and utilities.
- Core → Appearance: activates · Enables appearance-related feature modules.
- Core → General: activates · Enables general YouTube behavior modules.
- Core → Night mode: activates · Enables night-mode styling and behavior.
- Core → Web core: bridges · Passes common logic to injected page-context modules.
- Web core → Player: supports · Shared helpers back player logic.
- Web core → Channel: supports · Shared helpers back channel logic.
- Web core → Settings: supports · Shared helpers back settings logic.
- Web core → Themes: supports · Shared helpers back theme logic.
- Web core → Shortcuts: supports · Shared helpers back shortcut logic.
- Web core → Blocklist: supports · Shared helpers back blocklist logic.
- Menu app → Satus: renders with · Settings app is built on the project UI framework.
- Menu app → Skeleton: composes · Loads the main settings structure.
- Skeleton → Panels: organizes · Breaks the menu into feature-specific panels.
- Menu app → Locales: reads · Uses translated labels and messages.
- Core → Locales: reads · Uses localized strings for feature UI.
- Build scripts → Build manifests: generates · Produces browser-specific manifest variants.
- Build scripts → Locales: packages · Transforms translation bundles into release artifacts.
- CI workflows → Build scripts: runs · Automates build and packaging steps.
- CI workflows → Menu app: checks · Validates settings UI and related assets in CI.