# heyhuazi/xiaobottools architecture

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

- Interactive diagram: https://gitdiagram.com/heyhuazi/xiaobottools
- Repository: https://github.com/heyhuazi/xiaobottools

## Overview

XiaoBotTools is a Chrome extension that augments XiaoBot pages. Its main workflow detects article pages, builds a hierarchical table of contents from their headings, and lets readers jump to those headings. It also adds a ranking shortcut to the navigation bar and watches for URL changes so the interface can be refreshed on client-side navigation. The runtime behavior is visible in `js/content.js`; `manifest.json` is listed in the tree but was not sampled, so extension registration details are not shown.

Main entry points: [`js/content.js`](https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js) (Page initializer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Page integration"]
  node_lifecycle["Page lifecycle<br/>[content.js]"]
  node_urlwatch["URL watcher<br/>[content.js]"]
  node_initializer["Page initializer<br/>[content.js]"]
end

subgraph group_toc["Table of contents"]
  node_tocbuilder["TOC builder<br/>[content.js]"]
  node_headinglinks["Heading links<br/>[content.js]"]
end

subgraph group_links["Navigation links"]
  node_ranking["Ranking shortcut<br/>[content.js]"]
end

node_reader(("Reader"))
node_article["XiaoBot article page"]
node_rankingservice["Ranking site"]

node_lifecycle -->|"starts on load"| node_initializer
node_urlwatch -->|"restarts after URL change"| node_initializer
node_initializer -->|"adds shortcut"| node_ranking
node_initializer -->|"initializes on article pages"| node_tocbuilder
node_tocbuilder -->|"scans headings and inserts TOC"| node_article
node_tocbuilder -->|"creates heading anchors"| node_headinglinks
node_reader -->|"selects heading"| node_headinglinks
node_headinglinks -->|"jumps to heading"| node_article
node_ranking -->|"links to ranking site"| node_rankingservice

click node_lifecycle "https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js"
click node_urlwatch "https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js"
click node_initializer "https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js"
click node_tocbuilder "https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js"
click node_headinglinks "https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js"
click node_ranking "https://github.com/heyhuazi/xiaobottools/blob/main/js/content.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_lifecycle,node_urlwatch,node_initializer toneBlue
class node_tocbuilder,node_headinglinks toneAmber
class node_ranking toneMint
class node_reader,node_article,node_rankingservice toneIndigo
```

## Components

### Page integration

- [Page lifecycle](https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js): `js/content.js`
- [URL watcher](https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js): `js/content.js`
- [Page initializer](https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js): `js/content.js`

### Table of contents

- [TOC builder](https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js): `js/content.js`
- [Heading links](https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js): `js/content.js`

### Navigation links

- [Ranking shortcut](https://github.com/heyhuazi/xiaobottools/blob/main/js/content.js): `js/content.js`

### Other components

- **Reader**
- **XiaoBot article page**
- **Ranking site**

## Connections

- Page lifecycle → Page initializer: starts on load (evidence: `js/content.js`)
- URL watcher → Page initializer: restarts after URL change (evidence: `js/content.js`)
- Page initializer → Ranking shortcut: adds shortcut (evidence: `js/content.js`)
- Page initializer → TOC builder: initializes on article pages (evidence: `js/content.js`)
- TOC builder → XiaoBot article page: scans headings and inserts TOC (evidence: `js/content.js`)
- TOC builder → Heading links: creates heading anchors (evidence: `js/content.js`)
- Reader → Heading links: selects heading (evidence: `README.md`)
- Heading links → XiaoBot article page: jumps to heading (evidence: `README.md`)
- Ranking shortcut → Ranking site: links to ranking site (evidence: `js/content.js`)
