diff --git a/idb-notes.html b/idb-notes.html
index 136bcd8..65e11ad 100644
--- a/idb-notes.html
+++ b/idb-notes.html
@@ -79,6 +79,7 @@
<button id="saveBtn">Save Document</button>
<button id="newBtn">New Document</button>
<button id="exportBtn">Export as TXT</button>
+ <button id="exportDbBtn">Export NotesDB</button>
<div class="docs">
<h2>Saved Documents</h2>
@@ -230,6 +231,49 @@ function exportDocument() {
URL.revokeObjectURL(url);
}
+ function exportDatabase() {
+ const tx = db.transaction("documents", "readonly");
+ const store = tx.objectStore("documents");
+
+ const request = store.getAll();
+
+ request.onsuccess = function() {
+ const data = request.result;
+
+ if (!data.length) {
+ alert("No documents to export");
+ return;
+ }
+
+ const json = JSON.stringify(data, null, 2);
+
+ const blob = new Blob([json], {
+ type: "application/json"
+ });
+
+ const url = URL.createObjectURL(blob);
+
+ const a = document.createElement("a");
+ a.href = url;
+
+ const timestamp = new Date()
+ .toISOString()
+ .replace(/[:.]/g, "-");
+
+ a.download = `NotesDB-${timestamp}.json`;
+
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+
+ URL.revokeObjectURL(url);
+ };
+
+ request.onerror = function() {
+ alert("Export failed");
+ };
+ }
+
function escapeHtml(text) {
const div = document.createElement("div");
div.textContent = text;
@@ -254,6 +298,10 @@ document.getElementById("newBtn").onclick = function() {
document.getElementById("exportBtn").onclick = function() {
exportDocument();
};
+
+ document.getElementById("exportDbBtn").onclick = function() {
+ exportDatabase();
+ };
</script>
</body>