Greasy Fork

Greasy Fork is available in English.

Claude Storage Data Exporter

Monitors storage for Claude chat data and exports to endpoint

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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');
})();