How dawn-lc/iwaradownloadtool works
Project Type and Purpose
• This is a browser userscript (Tampermonkey/GreasyFork) named “Iwara视频下载工具.” It runs entirely client-side in a Chromium-based or Firefox browser. Its purpose is to scrape Iwara video pages, extract video URLs (and third-party cloud drive links), offer bulk download via Aria2 (or native downloads), and manage user preferences (auto-follow, auto-like, private or hidden video access).
File Structure Analysis
• Top-level
• .github/ – CI workflows, issue templates, multi-language README stubs.
• build/ – custom TypeScript/JavaScript scripts to compile, inline CSS, remove comments, and produce the final .user.js for release.
• src/ – all TypeScript modules for runtime logic. Notable sub-folders:
– css/ – main.css injected into the page
– i18n/ – locale JSON files (en, zh_cn)
– mata/ – userscript metadata template
– types/ – custom .d.ts definitions
• test/ – unit tests for helper functions
• tsconfig.json, package.json – build & dependency configuration
README Insights
• Features list (bulk download, Aria2 integration, auto-actions, private/hidden video support)
• Browser and script manager compatibility
• Dependencies: moment.js, Dexie.js (IndexedDB wrapper), emoji-regex, aria2rpc
Diagramming: Main Components & Their Interactions
a. Build Pipeline
• Input: src/ (TS modules), css/, mata/
• Steps:
1. Transpile TS → JS (build/build.ts)
2. Inline CSS into JS (build/inlineCSS.ts)
3. Strip comments (build/removeComments.ts)
4. Package metadata & produce final .user.js (build/release.js)
• Output: distributable UserScript
b. Runtime Environment
• Browser Host
• Tampermonkey/GreasyFork loads the .user.js
• Script runs in the context of Iwara video pages
• Core Modules (src/)
• main.ts – entry point: reads config, initializes DB & i18n, injects CSS & UI
• db.ts – Dexie-based IndexedDB for storing settings, followed authors, download history
• hijack.ts – monkey-patches/fetch intercepts to grab dynamically loaded comments or pagination
• function.ts / import.ts – utilities for parsing DOM, extracting links, and building download tasks
• aria2rpc integration – sends RPC commands to an external Aria2 server for downloads
• toastify.ts – handles in-page notifications
• i18n.ts – locale switching
c. External Services
• Iwara Web Server – supplies HTML pages, comments JSON, video file URLs
• Aria2 RPC Server (optional) – receives HTTP RPC calls from the script to schedule downloads
d. Data Flows & Interactions
1. Page Load → Tampermonkey injects script
2. Script reads config (from config.ts or UI‐persisted DB settings)
3. Initialize Dexie DB → fetch local state (e.g., which authors are auto-followed)
4. Inject CSS + UI controls (download buttons, settings panel)
5. When a user clicks “Download” (or auto-download is enabled):
• The script collects video URLs and optional cloud drive links
• Depending on mode:
– Aria2 Mode: call aria2rpc.addUri(...)
– Native Mode: dynamically create and trigger click
• Record task in Dexie DB → show status via toastify
6. For auto-like/follow: trigger additional fetch requests or DOM events to simulate these actions
Architectural Patterns & Design Principles
• Modular TS code: each feature in its own module
• Event-driven: UI events (clicks) trigger download pipelines
• Client-only: no backend server except optional Aria2 process
• Separation of concerns: build pipeline vs runtime logic; CSS vs JS; i18n vs business logic