-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_db.js
More file actions
55 lines (49 loc) · 1.54 KB
/
10_db.js
File metadata and controls
55 lines (49 loc) · 1.54 KB
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
// IndexedDB helpers + raw log rendering.
(function installPopupDb() {
const NS = globalThis.__POSEYEDOM.popup;
function openDatabase() {
return new Promise((resolve, reject) => {
try {
const request = indexedDB.open("DivLoggerDB");
request.onsuccess = (event) => resolve(event.target.result);
request.onerror = (event) => reject(event.target.error);
} catch (err) {
reject(err);
}
});
}
function fetchLogs() {
return new Promise(async (resolve, reject) => {
try {
const db = await openDatabase();
const transaction = db.transaction("logs", "readonly");
const store = transaction.objectStore("logs");
const logs = [];
const cursorRequest = store.openCursor();
cursorRequest.onsuccess = (event) => {
const cursor = event.target.result;
if (cursor) {
logs.push(cursor.value);
cursor.continue();
} else {
resolve(logs);
}
};
cursorRequest.onerror = (event) => reject(event.target.error);
} catch (err) {
reject(err);
}
});
}
function displayLogs(logs) {
const pre = document.getElementById("logs");
if (!logs || logs.length === 0) {
pre.textContent = "No logs available. Open a GitHub Codespace to start tracking suggestions.";
} else {
pre.textContent = JSON.stringify(logs, null, 2);
}
}
NS.api.openDatabase = openDatabase;
NS.api.fetchLogs = fetchLogs;
NS.api.displayLogs = displayLogs;
})();