Last active
February 21, 2026 18:34
-
-
Save billywhizz/43cd45c1d9e3faf682cc0594879e11d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getDatabase (name = 'ConversationsDatabase') { | |
| const req = window.indexedDB.open(name) | |
| return new Promise((resolve, reject) => { | |
| req.onsuccess = e => resolve(req.result) | |
| req.onerror = req.onabort = reject | |
| }) | |
| } | |
| function getAllKeys (db, collection = 'conversations') { | |
| const req = db.transaction([collection], 'readonly').objectStore(collection).getAllKeys() | |
| return new Promise((resolve, reject) => { | |
| req.onsuccess = e => resolve(req.result) | |
| req.onerror = req.onabort = reject | |
| }) | |
| } | |
| function getByKey (db, key, collection = 'conversations') { | |
| const req = db.transaction([collection], 'readonly').objectStore(collection).get(key) | |
| return new Promise((resolve, reject) => { | |
| req.onsuccess = e => resolve(req.result) | |
| req.onerror = req.onabort = reject | |
| }) | |
| } | |
| function fileName (path) { | |
| return path.slice(path.lastIndexOf('/') + 1) | |
| } | |
| let database | |
| getDatabase() | |
| .then(db => { | |
| database = db | |
| return getAllKeys(db) | |
| }) | |
| .then(keys => { | |
| return Promise.all(keys.map(k => getByKey(database, k))) | |
| }) | |
| .then(all => { | |
| const link = document.createElement('a') | |
| const blob = new Blob([JSON.stringify(all, null, ' ')], { type: 'application/json' } ) | |
| link.href = URL.createObjectURL(blob) | |
| link.download = fileName("conversations.json") | |
| link.click() | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment