# flanker/bilibili-dark-mode architecture

> Architecture diagram of the GitHub repository flanker/bilibili-dark-mode, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/flanker/bilibili-dark-mode
- Repository: https://github.com/flanker/bilibili-dark-mode

## Overview

##### Main Components

A. Browser Extension Components:
- Popup Interface (from /popup directory)
- Content Scripts (from /contents directory)
- Background Service Worker (implied by modern extension architecture)

B. External Systems:
- Bilibili.com Website
- Chrome/Edge Extension Store
- Browser Extension API

**┌─ Browser Context ──────────────────────────────┐**

- ┌─ DarkBili Extension ─────────────────────┐ │

- ┌─ Popup UI ─┐    ┌─ Content Scripts ┐ │ │

- index.tsx  │◄──►│  dark-mode.ts   │ │ │
- index.css  │    │  dark-mode.css  │ │ │
- ┘    └────────────────┬─┘ │ │
- ▲                           │   │ │
- ▼   │ │
- ┌─ Extension Storage ─┐    ┌─ DOM ──┐ │ │

- ┘    └────────┘ │ │
- ┬──┘ │

- ┼────┘

- ┌──────▼─────┐

- Bilibili   │
- Website    │

- ┘

##### Important Relationships

a. Data Flow:
- Popup → Content Scripts: Theme toggle commands
- Content Scripts → DOM: Style injection
- Extension Storage → Popup: User preferences
- Content Scripts → Bilibili Website: DOM manipulation

b. Dependencies:
- TypeScript compilation flow
- CSS injection paths
- Browser API interactions

##### Technical Stack Highlights

Technology indicators:
- TypeScript/TSX for components
- CSS for styling
- Plasmo framework
- Browser Extension APIs

##### Implementation Details

- The separation between the popup interface and content scripts
- How the dark mode styles are injected into the target website
- Storage and state management for user preferences
- Browser extension security boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser["Browser Context"]
        subgraph Extension["DarkBili Extension"]
            subgraph PopupUI["Popup UI Layer"]
                IndexTSX["index.tsx"]:::ui
                IndexCSS["index.css"]:::ui
            end

            subgraph ContentScripts["Content Scripts Layer"]
                DarkModeTS["dark-mode.ts"]:::script
                DarkModeCSS["dark-mode.css"]:::script
            end

            subgraph Config["Configuration Layer"]
                TSConfig["TypeScript Config"]:::config
                ESLint["ESLint Config"]:::config
                Prettier["Prettier Config"]:::config
                Package["Package Config"]:::config
            end

            Storage["Extension Storage"]:::storage
        end

        DOM["Browser DOM"]:::browser
    end

    subgraph External["External Systems"]
        Bilibili["Bilibili Website"]:::external
    end

    %% Relationships
    IndexTSX --> Storage
    Storage --> IndexTSX
    IndexTSX --> DarkModeTS
    DarkModeTS --> DOM
    DOM --> Bilibili
    DarkModeCSS --> DOM
    IndexCSS --> IndexTSX

    %% Click Events
    click IndexTSX "https://github.com/flanker/bilibili-dark-mode/blob/master/popup/index.tsx"
    click IndexCSS "https://github.com/flanker/bilibili-dark-mode/blob/master/popup/index.css"
    click DarkModeTS "https://github.com/flanker/bilibili-dark-mode/blob/master/contents/dark-mode.ts"
    click DarkModeCSS "https://github.com/flanker/bilibili-dark-mode/blob/master/contents/dark-mode.css"
    click TSConfig "https://github.com/flanker/bilibili-dark-mode/blob/master/tsconfig.json"
    click ESLint "https://github.com/flanker/bilibili-dark-mode/blob/master/.eslintrc.json"
    click Prettier "https://github.com/flanker/bilibili-dark-mode/blob/master/.prettierrc.cjs"
    click Package "https://github.com/flanker/bilibili-dark-mode/blob/master/package.json"

    %% Styling
    classDef ui fill:#FFE873,stroke:#333,stroke-width:2px
    classDef script fill:#90EE90,stroke:#333,stroke-width:2px
    classDef config fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef storage fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef browser fill:#F0F8FF,stroke:#333,stroke-width:2px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        UI["UI Component"]:::ui
        Script["Script Component"]:::script
        Conf["Configuration"]:::config
        Store["Storage"]:::storage
        Ext["External System"]:::external
    end
```
