Export Indexed DB

Export indexed db

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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