-
Notifications
You must be signed in to change notification settings - Fork 10
/
get_storage.js
150 lines (136 loc) · 4.37 KB
/
get_storage.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
javascript:
(
()=>
{
async function getAllIndexedDBData() {
const allDatabasesData = {};
// Function to get all database names (IDBFactory.databases is still experimental)
async function getAllDatabaseNames() {
if (!indexedDB.databases) {
console.error("indexedDB.databases is not supported in this browser.");
return [];
}
const dbs = await indexedDB.databases();
return dbs.map(db => db.name);
}
// Function to get all data from a specific object store
function getAllDataFromObjectStore(db, storeName) {
return new Promise((resolve, reject) => {
const transaction = db.transaction(storeName, 'readonly');
const objectStore = transaction.objectStore(storeName);
const request = objectStore.getAll();
request.onsuccess = (event) => {
resolve(event.target.result);
};
request.onerror = (event) => {
reject(event.target.error);
};
});
}
// Function to get all data from a database
async function getAllDataFromDatabase(dbName) {
return new Promise((resolve, reject) => {
const openRequest = indexedDB.open(dbName);
openRequest.onsuccess = async (event) => {
const db = event.target.result;
const databaseData = {};
if (db.objectStoreNames.length > 0)
{
const transaction = db.transaction(db.objectStoreNames, 'readonly');
const objectStoreNames = Array.from(db.objectStoreNames);
try {
for (const storeName of objectStoreNames) {
databaseData[storeName] = await getAllDataFromObjectStore(db, storeName);
}
resolve(databaseData);
} catch (error) {
reject(error);
} finally {
db.close();
}
}
else
{
resolve(databaseData);
}
};
openRequest.onerror = (event) => {
reject(event.target.error);
};
});
}
// Get all database names
const dbNames = await getAllDatabaseNames();
// Get all data from each database
for (const dbName of dbNames) {
try {
allDatabasesData[dbName] = await getAllDataFromDatabase(dbName);
} catch (error) {
console.error(`Error retrieving data from database "${dbName}":`, error);
}
}
return allDatabasesData;
}
function downloadName()
{
var hostname = window.location.hostname.substring(0, window.location.hostname.lastIndexOf('.')).replaceAll(".", "_");
var pathname = window.location.pathname ? window.location.pathname.replaceAll('/', '_'): "_";
var filename = hostname + pathname + "_Storage.json";
return filename;
}
function download(text, name, type)
{
var a = document.createElement("a");
var file = new Blob([text], {type: type});
a.href = URL.createObjectURL(file);
a.download = name;
a.click()
}
function send(l,s,c,i)
{
download(JSON.stringify({"javascriptCookies":c,"localStorage":l,"sessionStorage":s,"indexedDB":i},null,2),downloadName(),"application/json");
}
const result_l = {};
const result_s = {};
const result_c = {};
for (var i = 0; i < localStorage.length; i++)
{
try {
result_l[localStorage.key(i)] = JSON.parse(localStorage.getItem(localStorage.key(i)));
}
catch {
result_l[localStorage.key(i)] = localStorage.getItem(localStorage.key(i));
}
}
for (var i = 0; i < sessionStorage.length; i++)
{
try {
result_l[sessionStorage.key(i)] = JSON.parse(JSON.parse(sessionStorage.getItem(sessionStorage.key(i))));
}
catch {
result_l[sessionStorage.key(i)] = sessionStorage.getItem(sessionStorage.key(i));
}
}
getAllIndexedDBData().then
(
(result_i) =>
{
the_title = document.title;
the_place = window.location.href;
the_text = window.getSelection().toString();
the_time = Date().valueOf();
console.log("*** Test Stamp ***\n(Downloaded stored variables)\n" + "TIME: " + the_time + "\n" + "TITLE: " + the_title + "\n" + "URL: " + the_place + "\n" );
window.cookieStore.getAll().then(
function (value)
{
for (v in value)
{
result_c[value[v].name]=value[v].value;
}
send(result_l,result_s,result_c,result_i);
}
);
}
);
}
)();