# romanverdysh/tampermonkey-menu-chatgpt architecture

> Architecture diagram of the GitHub repository romanverdysh/tampermonkey-menu-chatgpt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/romanverdysh/tampermonkey-menu-chatgpt
- Repository: https://github.com/romanverdysh/tampermonkey-menu-chatgpt

## Overview

##### Project Type and Purpose
- This is an open-source Tampermonkey userscript (“Claude & ChatGPT.js”) that injects a custom prompt menu into the ChatGPT and Claude.ai web interfaces.

##### File Structure Analysis
- Top-level files:
- README.md – installation and usage instructions
- LICENSE
- chatGPT.js – module handling injection & API calls for ChatGPT’s web UI
- claudeAI.js – analogous module for Claude.ai’s web UI
- “Claude & ChatGPT.js” – the combined userscript (could be the concatenation or entry point)
- No backend services, build scripts, or databases—everything runs client-side in the browser via Tampermonkey.

##### Key Insights from README
- Two modes (ChatGPT vs. Claude.ai) unified into one script.
- UI elements: collapsible menu, scroll support, draggable window.
- Prompt functions live in a “ВСЕ СВОИ ФУНКЦИИ ВСТАВЛЯТЬ СЮДА” section.
- Utility functions for single/dual-input windows and prompt execution.

a. Main Components
– Browser (Chrome)
– Tampermonkey Extension
– Userscript (“Claude & ChatGPT.js”)
· UI Layer (menu panel, headers, buttons)
· Prompt Manager (functions defining templates: checkSenseArticle(), achesAndPainsCA(), semanticProximity(), etc.)
· Input Handler (customInputWindow())
· Executor (executeChatCommand())
· Integration Modules
- ChatGPT Module (DOM selectors & injection logic in chatGPT.js)
- Claude.ai Module (DOM selectors & injection logic in claudeAI.js)
– External Web Apps
· ChatGPT Web Interface → OpenAI backend
· Claude.ai Web Interface → Claude backend

b. Relationships & Data Flow
1. User opens ChatGPT or Claude.ai page in browser.
2. Tampermonkey loads the userscript.
3. Script injects a draggable, collapsible menu UI into the page DOM.
4. User clicks a custom-prompt button.
5. Input Handler (if needed) prompts for variables.
6. Prompt Manager constructs the template string.
7. Executor inserts the prompt into the chat input field and triggers “Send.”
8. Web app forwards the prompt to its backend service; response is rendered in the chat window.

c. Architectural Patterns & Principles
– Modular separation: UI layer vs. prompt definitions vs. injection logic
– Single responsibility: each prompt function only defines its template
– Extension-script integration: leverages Tampermonkey’s sandbox and GM_ APIs if used
– Event-driven: button clicks drive the entire workflow

d. Key Technologies & Libraries
– Tampermonkey userscript environment (GM_ APIs, @match metadata)
– Plain JavaScript for DOM manipulation
– ChatGPT/Claude web frontends (selectors may need updates if UI changes)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Environment
    Browser["Browser (Chrome)"]:::extension
    TM["Tampermonkey Extension"]:::extension
    Browser --> TM

    %% Userscript Entry
    UserScript["Userscript: Claude & ChatGPT.js"]:::script
    TM --> UserScript

    %% Documentation Files
    README["README.md"]:::file
    LICENSE["LICENSE"]:::file
    UserScript --> README
    UserScript --> LICENSE

    %% Userscript Modules
    subgraph "Userscript Modules"
        UI["UI Layer"]:::script
        PM["Prompt Manager"]:::script
        IH["Input Handler"]:::script
        EXE["Executor"]:::script

        subgraph "Integration Modules"
            GPT["ChatGPT Module"]:::script
            CLAUDE["Claude.ai Module"]:::script
        end
    end

    %% User Interaction Flow
    User["End-User"]:::extension
    User --> UI
    UI --> PM
    UI --> IH
    IH --> PM
    PM --> EXE
    EXE --> GPT
    EXE --> CLAUDE

    %% External Web Apps and Backends
    ChatGPTWeb["ChatGPT Web Interface"]:::external
    ClaudeWeb["Claude.ai Web Interface"]:::external
    ChatGPTBackend[(ChatGPT Backend)]:::external
    ClaudeBackend[(Claude.ai Backend)]:::external

    GPT --> ChatGPTWeb
    ChatGPTWeb --> ChatGPTBackend
    CLAUDE --> ClaudeWeb
    ClaudeWeb --> ClaudeBackend

    %% Click Events
    click UserScript "https://github.com/romanverdysh/tampermonkey-menu-chatgpt/blob/main/Claude & ChatGPT.js"
    click UI "https://github.com/romanverdysh/tampermonkey-menu-chatgpt/blob/main/Claude & ChatGPT.js"
    click PM "https://github.com/romanverdysh/tampermonkey-menu-chatgpt/blob/main/Claude & ChatGPT.js"
    click IH "https://github.com/romanverdysh/tampermonkey-menu-chatgpt/blob/main/Claude & ChatGPT.js"
    click EXE "https://github.com/romanverdysh/tampermonkey-menu-chatgpt/blob/main/Claude & ChatGPT.js"
    click GPT "https://github.com/romanverdysh/tampermonkey-menu-chatgpt/blob/main/chatGPT.js"
    click CLAUDE "https://github.com/romanverdysh/tampermonkey-menu-chatgpt/blob/main/claudeAI.js"
    click README "https://github.com/romanverdysh/tampermonkey-menu-chatgpt/blob/main/README.md"
    click LICENSE "https://github.com/romanverdysh/tampermonkey-menu-chatgpt/tree/main/LICENSE"

    %% Styles
    classDef extension fill:#ADD8E6,stroke:#000;
    classDef script fill:#90EE90,stroke:#000;
    classDef external fill:#FFA500,stroke:#000;
    classDef file fill:#D3D3D3,stroke:#000;
```
