Claude Storage Data Exporter

Monitors storage for Claude chat data and exports to endpoint

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Claude Storage Data Exporter
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Monitors storage for Claude chat data and exports to endpoint
// @author       nickm8
// @match        https://claude.ai/chat/*
// @grant        GM.xmlHttpRequest
// @grant        GM_xmlhttpRequest
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Debug logging
    const DEBUG = true;
    const log = {
        debug: (...args) => DEBUG && console.log('🔍 EXPORT:', ...args),
        error: (...args) => console.error('❌ EXPORT:', ...args),
        info: (...args) => console.log('ℹ️ EXPORT:', ...args)
    };

    // Configuration
    const CONFIG = {
        storageKey: 'captured_chat_data',
        endpoint: 'http://localhost:8000/collect',
        checkInterval: 1000
    };

    // Export functionality
    function exportData(data) {
        const requestObj = {
            method: 'POST',
            url: CONFIG.endpoint,
            headers: {
                'Content-Type': 'application/json'
            },
            data: JSON.stringify({
                type: 'chatData',
                data: data,
                timestamp: new Date().toISOString(),
                url: window.location.href
            }),
            onload: function(response) {
                log.info('Data exported successfully:', response.responseText);
                // Clear storage after successful export
                localStorage.removeItem(CONFIG.storageKey);
            },
            onerror: function(error) {
                log.error('Error exporting data:', error);
            }
        };

        if (typeof GM !== 'undefined' && GM.xmlHttpRequest) {
            GM.xmlHttpRequest(requestObj);
        }
        else if (typeof GM_xmlhttpRequest !== 'undefined') {
            GM_xmlhttpRequest(requestObj);
        }
        else {
            log.error('Neither GM.xmlHttpRequest nor GM_xmlhttpRequest is available');
        }
    }

    // Check storage and export
    function checkAndExport() {
        try {
            const data = localStorage.getItem(CONFIG.storageKey);
            if (data) {
                log.debug('Found data in storage');
                const parsedData = JSON.parse(data);
                exportData(parsedData);
            }
        } catch (error) {
            log.error('Check and export failed:', error);
        }
    }

    // Start monitoring
    setInterval(checkAndExport, CONFIG.checkInterval);

    // Initialize
    log.info('Storage export initialized');
})();