ChatGPT Exporter

repository·master·Indexed 25 days ago

https://github.com/pionxzh/chatgpt-exporter

A userscript for exporting ChatGPT conversation histories into multiple formats, including Markdown, HTML, Text, JSON, and PNG screenshots. It supports single and bulk exports, importing from official conversations.json files, and administrative actions like archiving or deleting chats. The tool includes a programmatic API for fetching conversations, handling rate limits, and processing raw OpenAI API data into structured formats.

Tokens
4.2K
Snippets
2
Records
30
Agent score
83%

What's inside chatgpt-exporter

  1. Export multiple conversations

    master

    When you click the "Tout Exporter" (Export All) button, the Exporter les Conversations (Export Conversations) dialog opens.

    Import from official file

    You can click the download icon to import a conversations.json file, such as the one exported directly from OpenAI.

    Export via API

    1. In the list of all conversations, select the ones you wish to export.
    2. Use the "Tout Sélectionner" (Select All) checkbox to select all conversations.
    3. Select your desired export format from the dropdown menu in the bottom left. Supported formats in this menu include:
      • Markdown
      • HTML
      • JSON
      • JSON (ZIP)
    4. Click the action button to perform the task.

    Available Actions

    • Archiver (Archive): Moves chat sessions to the archive. They will disappear from the sidebar and can be managed in ChatGPT settings.
    • Supprimer (Delete): Deletes the selected conversations.
    • Exporter (Export): Exports the selected conversations in the format chosen from the selector.
  2. Export Multiple Chats

    master

    To export multiple conversations at once, click the "Export All" button to open the "Export Conversations" dialog.

    Available Functions

    • Import from official export file (conversations.json): Click the upload icon to load a JSON file (e.g., one downloaded directly from OpenAI).
    • Export from API: Select specific conversations from your list. Use the "Select All" checkbox to select everything.

    Export Options

    Select your desired format from the dropdown menu in the bottom left corner:

    • Markdown
    • HTML
    • JSON
    • JSON (ZIP)

    Bulk Actions

    • Archive: Moves selected chats to the archive (they will disappear from the sidebar but remain manageable in ChatGPT settings).
    • Delete: Deletes the selected chats.
    • Export: Exports the selected chats in the chosen format.
  3. JSON Export Format Reference

    master

    The JSON export format provides the raw content from the OpenAI API endpoint https://chat.openai.com/backend-api/conversation/[id]. It includes conversation metadata such as id, title, create_time, and a mapping object containing the message tree (roles, content, timestamps, etc.).

    {
        "id": "35a1fa05-e928-4c39-8ffa-ca74f75b509f",
        "title": "AI Turing Test.",
        "create_time": 1678015311.655875,
        "mapping": {
            "5c48fa3e-e4ee-4d00-aa66-8fbcb671a358": {
                "id": "5c48fa3e-e4ee-4d00-aa66-8fbcb671a358",
                "message": {
                    "id": "5c48fa3e-e4ee-4d00-aa66-8fbcb671a358",
                    "author": {
                        "role": "system",
                        "metadata": {}
                    },
                    "create_time": 1678015311.655875,
                    "content": {
                        "content_type": "text",
                        "parts": [
                            ""
                        ]
                    },
                    "end_turn": true,
                    "weight": 1,
                    "metadata": {},
                    "recipient": "all"
                },
                "parent": "9310b90f-d8f0-4be6-bac2-daacddac784f",
                "children": [
                    "4afb9720-3a88-49b1-9309-e2b53d607f34"
                ]
            }
        }
    }
  4. JSON Export Data Contract

    master

    When exporting to JSON, the output is the raw content retrieved from the OpenAI API endpoint https://chat.openai.com/backend-api/conversation/[id].

    Key fields in the JSON structure include:

    • id: The unique identifier for the conversation.
    • title: The title of the chat.
    • create_time: Timestamp of creation.
    • mapping: A dictionary containing conversation nodes, where each node includes message (with author.role, content, etc.), parent, and children IDs.
    {
        "id": "35a1fa05-e928-4c39-8ffa-ca74f75b509f",
        "title": "AI Turing Test.",
        "create_time": 1678015311.655875,
        "mapping": {
            "5c48fa3e-e4ee-4d00-aa66-8fbcb671a358": {
                "id": "5c48fa3e-e4ee-4d00-aa66-8fbcb671a358",
                "message": {
                    "id": "5c48fa3e-e4ee-4d00-aa66-8fbcb671a358",
                    "author": {
                        "role": "system",
                        "metadata": {}
                    },
                    "create_time": 1678015311.655875,
                    "content": {
                        "content_type": "text",
                        "parts": [""]
                    },
                    "end_turn": true,
                    "weight": 1,
                    "metadata": {},
                    "recipient": "all"
                },
                "parent": "9310b90f-d8f0-4be6-bac2-daacddac784f",
                "children": ["4afb9720-3a88-49b1-9309-e2b53d607f34"]
            }
        }
    }
  5. Supported Export Formats

    master

    ChatGPT Exporter supports exporting chat history in the following formats:

    • Text
    • HTML
    • Markdown
    • PNG (Screenshot)
    • JSON (Raw content from the OpenAI API https://chat.openai.com/backend-api/conversation/[id])

    Markdown exports include metadata such as title, source, and author in the YAML front matter.

  6. Export multiple conversations to a ZIP archive

    master

    Use exportAllToJson to export multiple conversations into a single .zip file. Each conversation within the ZIP is saved as an individual .json file. If multiple conversations share the same filename, they are automatically suffixed with a count (e.g., (2).json).

    Parameters:

    • fileNameFormat: The base filename format for individual JSON files.
    • apiConversations: An array of ApiConversationWithId objects.
    • _metaList (optional): Metadata for the export.
    • projectName (optional): The name of the project used for the ZIP filename.
    • partIndex (optional): The index of the current part in a batch.
    • totalParts (optional): The total number of parts in the batch.
  7. Probe the ChatGPT API status

    master
    Use probeApi() to perform a lightweight check to see if the ChatGPT API is currently accepting requests. This is useful for displaying status to users before starting large export tasks. It returns an object containing ok status, retryAfterMs (if rate-limited), and rateLimitHeaders.
  8. Format filenames using template placeholders

    master

    The getFileNameWithFormat function allows you to generate dynamic filenames using a template string and specific placeholders. The resulting filename is appended with the provided extension.

    Available Placeholders:

    • {title}: The sanitized title (spaces replaced with underscores).
    • {date}: Current date string.
    • {timestamp}: Current timestamp.
    • {chat_id}: The unique ID of the chat (empty if exporting all conversations).
    • {create_time}: ISO string of the creation time (expects Unix timestamp in seconds).
    • {update_time}: ISO string of the update time (expects Unix timestamp in seconds).

    Options Object:

    • title: The title to use (defaults to document.title).
    • chatId: The chat ID string.
    • createTime: Unix timestamp in seconds.
    • updateTime: Unix timestamp in seconds.
  9. Export chat history to PNG using `exportToPng`

    master

    The exportToPng function captures the current ChatGPT conversation and downloads it as a PNG image. It automatically handles styling (adjusting for dark/light mode), hides UI elements like headers and buttons to ensure a clean screenshot, and attempts to handle large conversations by recursively reducing the scale if the canvas size limit is exceeded.

    Requirements:

    • A conversation must be active/started in the current ChatGPT session.
    • The function relies on the presence of specific DOM elements (e.g., #thread and [data-testid="conversation-turn-1"]).

    Returns:

    • true if the export and download were successful.
    • false if the conversation hasn't started, the element could not be found, or the conversation is too large to export.