ChatGPT Tools Export/Import

Export and import localStorage keys rulesProfiles and lorebookEntries

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         ChatGPT Tools Export/Import
// @namespace    ChatGPT Tools by Vishanka
// @version      1.0
// @description  Export and import localStorage keys rulesProfiles and lorebookEntries
// @author       Vishanka
// @match        https://chatgpt.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Create an export button
    const exportButton = document.createElement('button');
    exportButton.innerText = 'Export Data';
    exportButton.style.position = 'fixed';
    exportButton.style.top = '10px';
    exportButton.style.right = '10px';
    exportButton.style.zIndex = '10000';
    document.body.appendChild(exportButton);

    // Create an import button
    const importButton = document.createElement('button');
    importButton.innerText = 'Import Data';
    importButton.style.position = 'fixed';
    importButton.style.top = '50px';
    importButton.style.right = '10px';
    importButton.style.zIndex = '10000';
    document.body.appendChild(importButton);

    // Function to export data
    exportButton.addEventListener('click', () => {
        const keysToExport = ['rulesProfiles', 'lorebookEntries'];
        const exportedData = {};

        keysToExport.forEach(key => {
            if (localStorage.getItem(key)) {
                exportedData[key] = JSON.parse(localStorage.getItem(key));
            }
        });

        const blob = new Blob([JSON.stringify(exportedData, null, 2)], { type: 'application/json' });
        const url = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = 'exported_data.json';
        a.click();
        URL.revokeObjectURL(url);
    });

    // Function to import data
    importButton.addEventListener('click', () => {
        const input = document.createElement('input');
        input.type = 'file';
        input.accept = 'application/json';
        input.addEventListener('change', (event) => {
            const file = event.target.files[0];
            const reader = new FileReader();

            reader.onload = function(e) {
                try {
                    const importedData = JSON.parse(e.target.result);

                    Object.keys(importedData).forEach(key => {
                        if (importedData[key]) {
                            localStorage.setItem(key, JSON.stringify(importedData[key]));
                        }
                    });

                    alert('Data imported successfully!');
                } catch (error) {
                    alert('Failed to import data: Invalid JSON file.');
                }
            };

            reader.readAsText(file);
        });

        input.click();
    });
})();