Export Indexed DB

Export indexed db

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Export Indexed DB
// @namespace    rbits.export-indexeddb
// @version      1.0.0
// @description  Export indexed db
// @author       rbits
// @license      MIT
// @match        https://*/*
// @grant        GM_registerMenuCommand
// @grant        GM_setClipboard
// ==/UserScript==

async function exportIndexedDb() {
    const databases = await window.indexedDB.databases();

    const outputObj = {};
    for (const database of databases) {
        const databaseObj = await exportDatabase(database.name);
        outputObj[database.name] = databaseObj;
    }

    const json = JSON.stringify(outputObj);
    GM_setClipboard(json, 'text', () => {
        alert('Copied to clipboard');
    });
}

const exportDatabase = (name) => new Promise((resolve, reject) => {
    const request = window.indexedDB.open(name);
    request.onsuccess = async (event) => {
        const db = event.target.result;
        const objectStoreNames = db.objectStoreNames;

        const outputObj = {};
        for (const objectStoreName of objectStoreNames) {
            const objectStore = await exportObjectStore(db, objectStoreName);
            outputObj[objectStoreName] = objectStore;
        }

        resolve(outputObj);
    };
});

const exportObjectStore = (db, objectStoreName) => new Promise((resolve, reject) => {
    const objectStore = db.transaction(objectStoreName).objectStore(objectStoreName);
    const request = objectStore.getAllKeys();
    request.onsuccess = async (event) => {
        const keys = event.target.result;

        const outputObj = {};
        for (const key of keys) {
            const value = await getFromObjectStore(objectStore, key);
            outputObj[key] = value;
        };

        resolve(outputObj);
    };
});


const getFromObjectStore = (objectStore, key) => new Promise((resolve, reject) => {
    const request = objectStore.get(key);
    request.onsuccess = (event) => {
        resolve(event.target.result);
    };
});


(function() {
    'use strict';

    GM_registerMenuCommand('Export', exportIndexedDb);
})();