From 712694bd283da7454b2fbbd40e679ae20c77b897 Mon Sep 17 00:00:00 2001 From: quenousimporte <76260127+quenousimporte@users.noreply.github.com> Date: Wed, 1 Feb 2023 12:34:40 +0100 Subject: [PATCH] added: sandbox vault with loading datafile added: vault in title bar --- index.html | 1 + main.js | 55 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/index.html b/index.html index c0584a4..f8977c7 100644 --- a/index.html +++ b/index.html @@ -37,6 +37,7 @@
+
diff --git a/main.js b/main.js index 7d20f6d..35dc07e 100644 --- a/main.js +++ b/main.js @@ -35,6 +35,8 @@ var tags = null; var currentvault = ""; var currenttag = ""; +var vaults = ["local", "remote", "sandbox"]; + var stat = { ses: @@ -228,8 +230,8 @@ var commands = [ action: downloadnotewithsubs }, { - hint: "Download local data", - action: downloadlocal, + hint: "Download vault", + action: downloadvault, shortcut: "ctrl+shift+S" }, { @@ -275,7 +277,7 @@ var commands = [ shortcut: "ctrl+l" }, { - hint: "Switch vault", + hint: "Change vault", action: switchvault, shortcut: "ctrl+shift+V" }, @@ -482,8 +484,17 @@ function addtagfilter() function switchvault() { - window.localStorage.setItem("vault", othervault()); - init(); + searchinlist(vaults) + .then(vault => + { + window.localStorage.setItem("vault", vault); + init(); + + if (vault == "sandbox") + { + datafile.hidden = false; + } + }); } function ancestors(note) @@ -804,14 +815,9 @@ function downloadnotes() }); } -function downloadlocal() +function downloadvault() { - var data = - { - local : JSON.parse(window.localStorage.getItem("local")), - remote : JSON.parse(window.localStorage.getItem("remote")) - }; - download(timestamp() + " notes.json", JSON.stringify(data)); + download("notes " + timestamp() + " " + currentvault + ".json", window.localStorage.getItem(currentvault)); } function downloadnotewithsubs() @@ -961,23 +967,32 @@ function initsnippets() } } -function othervault() -{ - return isremote() ? "local" : "remote"; -} - function initvault() { currentvault = window.localStorage.getItem("vault") || "local"; } +function loaddatafile(filepath) +{ + reader = new FileReader(); + if (filepath.files && filepath.files[0]) + { + reader.onload = function (e) + { + localdata = JSON.parse(e.target.result); + loadlast(); + datafile.hidden = true; + }; + reader.readAsText(filepath.files[0]); + } + return true; +} + function init() { loadsettings(); initvault(); - commands.find(c => c.action == switchvault).hint = "Switch to " + othervault() + " vault"; - window.onbeforeunload = checksaved; window.onclick = focuseditor; @@ -1865,7 +1880,7 @@ function mainkeydownhandler() function setwindowtitle() { - document.title = ""; + document.title = "[" + currentvault + "] -\xa0"; if (currenttag) { document.title += "[" + currenttag + "] -\xa0";