# systemmin/kill-doc architecture

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

- Interactive diagram: https://gitdiagram.com/systemmin/kill-doc
- Repository: https://github.com/systemmin/kill-doc

## Overview

##### Project type and purpose
- This is a **browser userscript toolkit** (written in JavaScript) designed to be installed via **Tampermonkey** (or any userscript manager).
- Its goal is to automate document preview and download workflows on many online document‐hosting sites (e.g., Baidu Wenku, Docin, Renrendoc, Feishu, etc.), leveraging canvas screenshots, HTML-to-PDF conversion, and ZIP packaging.

##### File structure
- **package.json** + **main.js** at the root suggest a Node/npm‐managed repo, though there is no complex build—scripts are plain JS for Tampermonkey.
- Top‐level modules (folders):
- **autox/** – two “auto” scripts for specific sites
- **bookmark/** – per-site bookmarklet‐style scripts
- **e-book/** – e-book download helper (index.js + URL list)
- **script/** – a generic script runner (index.js + URL list)
- **up.woozooo.com/** – custom scripts for up.woozooo.com
- **AMOUNT.md**, **LICENSE**, multiple README.md files – documentation.

##### README
- Describes supported platforms, feature pipeline (0→1→2→3→4), underlying technologies:
- **jspdf** (PDF generation)
- **@html2canvas** (DOM→canvas screenshot)
- **@zip.js** (create zip archives)
- Workflow steps: auto-preview (scroll), stop preview, download images, generate PDF, extract text, package HTML+TXT, etc.

##### Diagramming strategy
a. Main components:
- **Developer Environment**
– Git repo / npm
– Local editor, commits → GitHub
- **Userscript Packaging**
– main.js orchestrator
– Module folders (autox, bookmark, e-book, script, up.woozooo.com)
– 3rd-party libraries (jspdf, html2canvas, zip.js)
- **Delivery & Installation**
– Published on GreasyFork / GitHub Releases
– Installed into Tampermonkey
- **Runtime Environment**
– Browser + Tampermonkey
– Script injector matching URL patterns
- **Target Websites**
– Set of document portals (e.g., Baidu Wenku, Doc88, Feishu, etc.)
- **Processing Pipeline**
1. DOM Manipulation & Scrolling (auto-preview)
2. Canvas/Image Capture
3. Binary/Text Extraction
4. PDF Generation
5. ZIP Packaging
6. Download Trigger via GM_download or browser “Save as”

b. Relationships & Interactions:
– **User** installs script → **Tampermonkey**
– **Tampermonkey** injects **main.js**
– **main.js** loads the appropriate module based on current URL
– Module runs its **pipeline**: interacts with page DOM, calls html2canvas/jspdf/zip.js
– Output is handed to **Tampermonkey API** (GM_download) → **Browser Download**

c. Architectural patterns & principles:
– **Modular plugin pattern**: one folder per site/feature
– **Sequential pipeline**: discrete, ordered steps (preview → capture → package)
– **Dependency injection**: core libs (jspdf, html2canvas, zip.js) are shared across modules
– **URL-based routing**: modules register handlers for specific domain patterns

d. Technologies & libraries:
– **JavaScript** (ES6)
– **Tampermonkey API** (GM_download, GM_xmlhttpRequest, etc.)
– **jspdf v2.4.0**
– **@html2canvas v1.4.1**
– **@zip.js v2.7.34**

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer Environment
    subgraph "Developer Environment"
        style DeveloperBg fill:#E0F7FA,stroke:#333,stroke-width:1px
        AMOUNT["AMOUNT.md"] 
        LICENSE["LICENSE"]
        README["README.md"]
        PACKAGE["package.json"]
    end
    class DeveloperBg fill:#E0F7FA
    click AMOUNT "https://github.com/systemmin/kill-doc/blob/master/AMOUNT.md"
    click LICENSE "https://github.com/systemmin/kill-doc/tree/master/LICENSE"
    click README "https://github.com/systemmin/kill-doc/blob/master/README.md"
    click PACKAGE "https://github.com/systemmin/kill-doc/blob/master/package.json"

    %% Target Websites
    subgraph "Target Websites"
        style WebsitesBg fill:#ECEFF1,stroke:#333,stroke-width:1px
        Baidu["Baidu Wenku"]
        Docin["Doc88"]
        Renrendoc["Renrendoc"]
        Feishu["Feishu"]
    end
    class WebsitesBg fill:#ECEFF1

    %% Runtime and Orchestrator
    subgraph "Extension Runtime"
        style RuntimeBg fill:#E8F5E9,stroke:#333,stroke-width:1px
        TM["Tampermonkey"]:::runtime
        MainJS["main.js orchestrator"]:::orchestrator
    end
    class RuntimeBg fill:#E8F5E9
    click MainJS "https://github.com/systemmin/kill-doc/blob/master/main.js"
    
    %% Modules
    subgraph "Modules"
        style ModulesBg fill:#E1F5FE,stroke:#333,stroke-width:1px
        Autox["autox/"]:::module
        Bookmark["bookmark/"]:::module
        EBook["e-book/"]:::module
        ScriptMod["script/"]:::module
        UpWooz["up.woozooo.com/"]:::module
    end
    class ModulesBg fill:#E1F5FE
    click Autox "https://github.com/systemmin/kill-doc/tree/master/autox/"
    click Bookmark "https://github.com/systemmin/kill-doc/tree/master/bookmark/"
    click EBook "https://github.com/systemmin/kill-doc/tree/master/e-book/"
    click ScriptMod "https://github.com/systemmin/kill-doc/tree/master/script/"
    click UpWooz "https://github.com/systemmin/kill-doc/tree/master/up.woozooo.com/"

    %% Libraries
    subgraph "Shared Libraries"
        style LibsBg fill:#FFF3E0,stroke:#333,stroke-width:1px
        Html2Canvas["@html2canvas v1.4.1"]:::library
        jsPDF["jspdf v2.4.0"]:::library
        ZipJS["@zip.js v2.7.34"]:::library
    end
    class LibsBg fill:#FFF3E0

    %% Processing Pipeline
    subgraph "Processing Pipeline"
        style PipelineBg fill:#F3E5F5,stroke:#333,stroke-width:1px
        DOMManip["1. DOM Manipulation & Scrolling"]:::pipeline
        CanvasCap["2. Canvas/Image Capture"]:::pipeline
        TextExt["3. Binary/Text Extraction"]:::pipeline
        PDFGen["4. PDF Generation"]:::pipeline
        ZipPack["5. ZIP Packaging"]:::pipeline
        DownloadTrig["6. Download Trigger"]:::pipeline
    end
    class PipelineBg fill:#F3E5F5

    %% Browser Download Sink
    BrowserAPI["Tampermonkey API (GM_download)"]:::api
    BrowserDL["Browser Download"]:::external

    %% Connections
    Baidu -->|injects script| TM
    Docin -->|injects script| TM
    Renrendoc -->|injects script| TM
    Feishu -->|injects script| TM

    PACKAGE -->|publishes to| TM
    README -->|publishes to| TM

    TM -->|"loads"| MainJS

    MainJS -->|"routes by URL"| Autox
    MainJS -->|"routes by URL"| Bookmark
    MainJS -->|"routes by URL"| EBook
    MainJS -->|"routes by URL"| ScriptMod
    MainJS -->|"routes by URL"| UpWooz

    Autox -->|uses| DOMManip
    Bookmark -->|uses| DOMManip
    EBook -->|uses| DOMManip
    ScriptMod -->|uses| DOMManip
    UpWooz -->|uses| DOMManip

    DOMManip --> CanvasCap
    CanvasCap --> TextExt
    TextExt --> PDFGen
    PDFGen --> ZipPack
    ZipPack --> DownloadTrig
    DownloadTrig --> BrowserAPI
    BrowserAPI --> BrowserDL

    %% Modules invoke libraries
    Autox -->|calls| Html2Canvas
    Bookmark -->|calls| Html2Canvas
    EBook -->|calls| jsPDF
    ScriptMod -->|calls| ZipJS
    UpWooz -->|calls| jsPDF

    %% Styles
    classDef runtime fill:#A5D6A7,stroke:#333,stroke-width:1px
    classDef orchestrator fill:#C8E6C9,stroke:#333,stroke-width:1px
    classDef module fill:#B3E5FC,stroke:#333,stroke-width:1px
    classDef library fill:#FFCC80,stroke:#333,stroke-width:1px
    classDef pipeline fill:#CE93D8,stroke:#333,stroke-width:1px
    classDef api fill:#FFF59D,stroke:#333,stroke-width:1px
    classDef external fill:#B0BEC5,stroke:#333,stroke-width:1px
```
