# museremarkable/swufe_ccf_show_ranking architecture

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

- Interactive diagram: https://gitdiagram.com/museremarkable/swufe_ccf_show_ranking
- Repository: https://github.com/museremarkable/swufe_ccf_show_ranking

## Overview

##### Project type and purpose
- **Type**: Browser extension (Chrome/Edge/Firefox)
- **Purpose**:
- Inject journal/conference ranking badges on academic websites (“Show Ranking”)
- Provide in-page translation (“Online Translation”)
- Offer a simple cloud storage interface (“科研云盘”)
- (Future) Reference management and formula recognition

##### High-level architecture components
a. **Manifest & Localization**
- manifest.json
- _locales/…
b. **Background Service Worker**
- background/background.js
- background/html/*.html (settings pages)
- Uses chrome.runtime, chrome.storage, webRequest (if any)
c. **Content Script Modules** (injected into target sites)
- show_ranking/script.js + show_ranking/ranking/*.js + show_ranking/data/*.js + show_ranking/site/*.js
- translation/translation.js
- paper_manager/paper.js + paper_manager/dialog.js
d. **UI Pages**
- popup/popup.html + popup/js/*.js + popup/css/*.css
- background/html/*.html (author.html, home.html, etc.)
e. **Assets & Libraries**
- lib/js, lib/css, lib/fonts, lib/plugins
- picture/
f. **External Services & APIs**
- Translation APIs: Google, Baidu, Tencent, Caiyun
- Cloud storage backend: easyscholar.cc
- Data sources: static JSON/JS ranking files, Excel/PDF reference data

##### Interactions & Data Flow
- **Startup**: manifest → registers background service + content scripts (for matching URL patterns)
- **Content Injection**:
· show_ranking script runs on academic sites, loads local data files, processes DOM → displays ranking badges
· translation script listens for key events, sends text to background → background fetches API → returns translation → overlays DOM
· paper_manager scripts run on the cloud storage page, interacting via fetch/XHR to the backend
- **User Actions**:
· Background page settings (background/html/*.html) use form inputs → save to chrome.storage
- **Message Passing**: chrome.runtime.sendMessage / onMessage between content scripts, background, and popup

##### Architectural patterns & design principles
- **Modular feature separation**: Each major feature (ranking, translation, cloud) lives in its own directory, with its own scripts and assets
- **Background + Content**: Follows browser-extension pattern—long-lived background worker for centralized logic/storage; per-page content scripts for UI injection
- **Local resource bundling**: Static ranking data stored under show_ranking/data and injected client-side
- **External API abstraction**: Translation module abstracts multiple third-party APIs with a common interface

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Extension Core
    subgraph "Extension Core"
        direction TB
        Manifest["manifest.json"]:::core
        Locales["_locales/"]:::core
        Background["Background Service Worker"]:::core
    end

    %% Feature Modules
    subgraph "Feature Modules"
        direction TB
        ShowRanking["ShowRanking Module"]:::feature
        Translation["Translation Module"]:::feature
        PaperManager["PaperManager Module"]:::feature
    end

    %% UI Layer
    subgraph "UI Layer"
        direction TB
        Popup["Popup UI"]:::ui
        Settings["Settings Pages"]:::ui
    end

    %% Assets & Libraries
    subgraph "Assets & Libraries"
        direction TB
        LibJS["lib/js/"]:::assets
        LibCSS["lib/css/"]:::assets
        LibFonts["lib/fonts/"]:::assets
        LibPlugins["lib/plugins/"]:::assets
        LibLogo["lib/logo/"]:::assets
        Picture["picture/"]:::assets
    end

    %% External Layer
    subgraph "External Layer"
        direction TB
        LocalData["Local Ranking Data"]:::data
        ExternalAPIs["Translation APIs"]:::external
        CloudBackend["Cloud Storage Backend"]:::external
    end

    %% Connections: Registration
    Manifest -->|"registers"| Background
    Manifest -->|"registers"| ShowRanking
    Manifest -->|"registers"| Translation
    Manifest -->|"registers"| PaperManager

    %% Content Scripts read local data
    ShowRanking -->|"reads"| LocalData

    %% Messaging between content and background
    ShowRanking <-->|"chrome.runtime.sendMessage"| Background
    Translation <-->|"chrome.runtime.sendMessage"| Background
    PaperManager <-->|"chrome.runtime.sendMessage"| Background

    %% Translation flow
    Translation -->|"fetch"| ExternalAPIs
    ExternalAPIs -->|"response"| Translation

    %% Paper manager backend
    PaperManager -->|"XHR/fetch"| CloudBackend

    %% UI interactions
    Popup -.->|"chrome.runtime.get|settings"| Background
    Settings -.->|"chrome.storage"| Background

    %% Assets usage
    Popup -->|"loads"| LibJS
    Popup -->|"loads"| LibCSS
    ShowRanking -->|"loads"| LibJS
    Translation -->|"loads"| LibJS
    PaperManager -->|"loads"| LibJS

    %% Click Events for mappings
    click Manifest "https://github.com/museremarkable/swufe_ccf_show_ranking/blob/master/manifest.json"
    click Locales "https://github.com/museremarkable/swufe_ccf_show_ranking/tree/master/_locales/"
    click Background "https://github.com/museremarkable/swufe_ccf_show_ranking/blob/master/background/background.js"
    click Settings "https://github.com/museremarkable/swufe_ccf_show_ranking/tree/master/background/html/"
    click ShowRanking "https://github.com/museremarkable/swufe_ccf_show_ranking/blob/master/show_ranking/script.js"
    click LocalData "https://github.com/museremarkable/swufe_ccf_show_ranking/tree/master/show_ranking/data/"
    click ShowRanking "https://github.com/museremarkable/swufe_ccf_show_ranking/tree/master/show_ranking/ranking/"
    click ShowRanking "https://github.com/museremarkable/swufe_ccf_show_ranking/blob/master/show_ranking/style.css"
    click Translation "https://github.com/museremarkable/swufe_ccf_show_ranking/blob/master/translation/translation.js"
    click PaperManager "https://github.com/museremarkable/swufe_ccf_show_ranking/blob/master/paper_manager/script.js"
    click PaperManager "https://github.com/museremarkable/swufe_ccf_show_ranking/blob/master/paper_manager/paper.js"
    click PaperManager "https://github.com/museremarkable/swufe_ccf_show_ranking/blob/master/paper_manager/dialog.js"
    click Popup "https://github.com/museremarkable/swufe_ccf_show_ranking/blob/master/popup/popup.html"
    click LibJS "https://github.com/museremarkable/swufe_ccf_show_ranking/tree/master/lib/js/"
    click LibCSS "https://github.com/museremarkable/swufe_ccf_show_ranking/tree/master/lib/css/"
    click LibFonts "https://github.com/museremarkable/swufe_ccf_show_ranking/tree/master/lib/fonts/"
    click LibPlugins "https://github.com/museremarkable/swufe_ccf_show_ranking/tree/master/lib/plugins/"
    click LibLogo "https://github.com/museremarkable/swufe_ccf_show_ranking/tree/master/lib/logo/"
    click Picture "https://github.com/museremarkable/swufe_ccf_show_ranking/tree/master/picture/"

    %% Styles
    classDef core fill:#0B6623,stroke:#000,color:#fff
    classDef feature fill:#1E90FF,stroke:#000,color:#fff
    classDef ui fill:#FFD700,stroke:#000,color:#000
    classDef data fill:#A9A9A9,stroke:#000,color:#000
    classDef external fill:#DC143C,stroke:#000,color:#fff,stroke-dasharray: 5 5
    classDef assets fill:#87CEFA,stroke:#000,color:#000
```
