Export Indexed DB

Export indexed db

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
})();