-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexport.js
50 lines (43 loc) · 1 KB
/
export.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
indexedDB.open('your-db-name-here').onsuccess = function(e)
{
try
{
console.warn('Success opening db');
var ret = {};
var db = e.target.result;
var t = db.transaction(db.objectStoreNames, "readonly");
var toExport = Array.prototype.slice.call(db.objectStoreNames, 0).filter(function(a) { return a.indexOf('messages') === 0; });
toExport.forEach(function(n)
{
console.warn('Exporting '+n);
var d = [];
t.objectStore(n).openCursor().onsuccess = function(e)
{
var c = e.target.result;
if(c)
{
d.push(c.value);
c.continue();
}
else
{
ret[n] = d;
if(toExport.length === Object.keys(ret).length)
{
var blob = new Blob([ JSON.stringify(ret) ], { type: "octet/stream" });
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = "export.json";
a.click();
window.URL.revokeObjectURL(url);
}
}
};
});
}
catch(e)
{
console.error(e);
}
};