# magicoflolis/magic-ph architecture

> Architecture diagram of the GitHub repository magicoflolis/magic-ph, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/magicoflolis/magic-ph
- Repository: https://github.com/magicoflolis/magic-ph

## Overview

MagicPH is primarily a browser userscript that detects supported-site video sources, presents them in a tabbed downloader interface, and lets users choose and save media. The sampled main userscript is a large, mostly self-contained module, so its domain responsibilities share one implementation path. The tree also contains an older WebExtension runtime; the README says that version is unavailable and outdated. Its sampled background code shows tab and message handling, but not its full product workflow.

Main entry points: [`src/js/bg-start.js`](https://github.com/magicoflolis/magic-ph/blob/master/src/js/bg-start.js) (Background startup), [`src/js/background.js`](https://github.com/magicoflolis/magic-ph/blob/master/src/js/background.js) (Background utilities), [`src/js/querySelector.js`](https://github.com/magicoflolis/magic-ph/blob/master/src/js/querySelector.js) (DOM helpers), [`src/UserJS/main.js`](https://github.com/magicoflolis/magic-ph/blob/master/src/UserJS/main.js) (Source detection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_userscript["Userscript runtime"]
  node_user_script["Userscript entry<br/>[main.js]"]
  node_source_detection["Source detection<br/>[main.js]"]
  node_video_tabs["Video tabs<br/>[main.js]"]
  node_downloader["Media downloader<br/>[main.js]"]
end

subgraph group_extension["WebExtension runtime"]
  node_site_content["Site enhancements<br/>[start.js]"]
  node_custom_player["Player integration<br/>[custom-player.js]"]
  node_extension_start["Background startup<br/>[bg-start.js]"]
  node_tab_messaging["Tabs and messaging<br/>[bg-background.js]"]
  node_extension_config[("Extension config<br/>[config.js]")]
  node_extension_options["Options UI<br/>[options.js]"]
  node_extension_background["Background utilities<br/>[background.js]"]
  node_extension_common["Background helpers<br/>[bg-common.js]"]
  node_ad_removal["Ad removal<br/>[mph-adremover.js]"]
  node_client["Site client<br/>[mph-client.js]"]
  node_common["Site utilities<br/>[mph-common.js]"]
end

subgraph group_shared["Interface support"]
  node_locales["Translations"]
  node_dom_helpers["DOM helpers<br/>[querySelector.js]"]
end

node_viewer(("Viewer"))
node_supported_sites["Supported sites"]
node_third_party["External downloader"]
node_extension_api["Browser APIs"]

node_viewer -->|"runs on page"| node_user_script
node_supported_sites -->|"provides video"| node_source_detection
node_source_detection -->|"creates title tab"| node_video_tabs
node_viewer -->|"opens list"| node_video_tabs
node_viewer -->|"chooses quality"| node_downloader
node_downloader -.->|"can combine"| node_third_party
node_extension_start -->|"starts"| node_tab_messaging
node_extension_start -->|"uses"| node_extension_common
node_extension_start -->|"uses"| node_extension_config
node_extension_start -->|"uses"| node_extension_background
node_extension_start -.->|"registers handlers"| node_extension_api
node_extension_background -->|"reads settings"| node_extension_config
node_extension_background -.->|"uses"| node_extension_api
node_extension_options -->|"uses"| node_dom_helpers
node_site_content -->|"uses"| node_dom_helpers
node_custom_player -->|"uses"| node_dom_helpers
node_tab_messaging -->|"routes messages"| node_extension_api

click node_user_script "https://github.com/magicoflolis/magic-ph/blob/master/src/UserJS/main.js"
click node_source_detection "https://github.com/magicoflolis/magic-ph/blob/master/src/UserJS/main.js"
click node_video_tabs "https://github.com/magicoflolis/magic-ph/blob/master/src/UserJS/main.js"
click node_downloader "https://github.com/magicoflolis/magic-ph/blob/master/src/UserJS/main.js"
click node_locales "https://github.com/magicoflolis/magic-ph/tree/master/src/_locales"
click node_site_content "https://github.com/magicoflolis/magic-ph/blob/master/src/js/start.js"
click node_custom_player "https://github.com/magicoflolis/magic-ph/blob/master/src/js/custom-player.js"
click node_dom_helpers "https://github.com/magicoflolis/magic-ph/blob/master/src/js/querySelector.js"
click node_extension_start "https://github.com/magicoflolis/magic-ph/blob/master/src/js/bg-start.js"
click node_tab_messaging "https://github.com/magicoflolis/magic-ph/blob/master/src/js/bg-background.js"
click node_extension_config "https://github.com/magicoflolis/magic-ph/blob/master/src/js/config.js"
click node_extension_options "https://github.com/magicoflolis/magic-ph/blob/master/src/js/options.js"
click node_extension_background "https://github.com/magicoflolis/magic-ph/blob/master/src/js/background.js"
click node_extension_common "https://github.com/magicoflolis/magic-ph/blob/master/src/js/bg-common.js"
click node_ad_removal "https://github.com/magicoflolis/magic-ph/blob/master/src/js/mph-adremover.js"
click node_client "https://github.com/magicoflolis/magic-ph/blob/master/src/js/mph-client.js"
click node_common "https://github.com/magicoflolis/magic-ph/blob/master/src/js/mph-common.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_user_script,node_source_detection,node_video_tabs,node_downloader,node_viewer,node_extension_api toneBlue
class node_site_content,node_custom_player,node_extension_start,node_tab_messaging,node_extension_config,node_extension_options,node_extension_background,node_extension_common,node_ad_removal,node_client,node_common toneAmber
class node_locales,node_dom_helpers toneMint
class node_supported_sites,node_third_party toneIndigo
```

## Components

### Userscript runtime

- [Userscript entry](https://github.com/magicoflolis/magic-ph/blob/master/src/UserJS/main.js): `src/UserJS/main.js`
- [Source detection](https://github.com/magicoflolis/magic-ph/blob/master/src/UserJS/main.js): `src/UserJS/main.js`
- [Video tabs](https://github.com/magicoflolis/magic-ph/blob/master/src/UserJS/main.js): `src/UserJS/main.js`
- [Media downloader](https://github.com/magicoflolis/magic-ph/blob/master/src/UserJS/main.js): `src/UserJS/main.js`

### WebExtension runtime

- [Site enhancements](https://github.com/magicoflolis/magic-ph/blob/master/src/js/start.js): `src/js/start.js`
- [Player integration](https://github.com/magicoflolis/magic-ph/blob/master/src/js/custom-player.js): `src/js/custom-player.js`
- [Background startup](https://github.com/magicoflolis/magic-ph/blob/master/src/js/bg-start.js): `src/js/bg-start.js`
- [Tabs and messaging](https://github.com/magicoflolis/magic-ph/blob/master/src/js/bg-background.js): `src/js/bg-background.js`
- [Extension config](https://github.com/magicoflolis/magic-ph/blob/master/src/js/config.js): `src/js/config.js`
- [Options UI](https://github.com/magicoflolis/magic-ph/blob/master/src/js/options.js): `src/js/options.js`
- [Background utilities](https://github.com/magicoflolis/magic-ph/blob/master/src/js/background.js): `src/js/background.js`
- [Background helpers](https://github.com/magicoflolis/magic-ph/blob/master/src/js/bg-common.js): `src/js/bg-common.js`
- [Ad removal](https://github.com/magicoflolis/magic-ph/blob/master/src/js/mph-adremover.js): `src/js/mph-adremover.js`
- [Site client](https://github.com/magicoflolis/magic-ph/blob/master/src/js/mph-client.js): `src/js/mph-client.js`
- [Site utilities](https://github.com/magicoflolis/magic-ph/blob/master/src/js/mph-common.js): `src/js/mph-common.js`

### Interface support

- [Translations](https://github.com/magicoflolis/magic-ph/tree/master/src/_locales): `src/_locales`
- [DOM helpers](https://github.com/magicoflolis/magic-ph/blob/master/src/js/querySelector.js): `src/js/querySelector.js`

### Other components

- **Viewer**
- **Supported sites**
- **External downloader**
- **Browser APIs**

## Connections

- Viewer → Userscript entry: runs on page (evidence: `README.md`)
- Supported sites → Source detection: provides video (evidence: `README.md`)
- Source detection → Video tabs: creates title tab (evidence: `README.md`)
- Viewer → Video tabs: opens list (evidence: `README.md`)
- Viewer → Media downloader: chooses quality (evidence: `README.md`)
- Media downloader → External downloader: can combine (evidence: `README.md`)
- Background startup → Tabs and messaging: starts (evidence: `src/js/bg-start.js`)
- Background startup → Background helpers: uses (evidence: `src/js/bg-start.js`)
- Background startup → Extension config: uses (evidence: `src/js/bg-start.js`)
- Background startup → Background utilities: uses (evidence: `src/js/bg-start.js`)
- Background startup → Browser APIs: registers handlers
- Background utilities → Extension config: reads settings (evidence: `src/js/background.js`)
- Background utilities → Browser APIs: uses
- Options UI → DOM helpers: uses (evidence: `src/js/options.js`)
- Site enhancements → DOM helpers: uses (evidence: `src/js/start.js`)
- Player integration → DOM helpers: uses (evidence: `src/js/custom-player.js`)
- Tabs and messaging → Browser APIs: routes messages (evidence: `src/js/bg-background.js`)
