From 8fcab339ce49f0a225cf656018c99f80b148f706 Mon Sep 17 00:00:00 2001 From: quenousimporte <76260127+quenousimporte@users.noreply.github.com> Date: Tue, 21 Feb 2023 12:05:04 +0100 Subject: [PATCH] improved: download all notes as flat md files --- main.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index 8bd4b89..901ef21 100644 --- a/main.js +++ b/main.js @@ -329,6 +329,10 @@ var commands = [ hint: "Download current note with merged subnotes", action: downloadnotewithsubs }, +{ + hint: "Download all notes as flat markdown files", + action: downloadnotes +}, { hint: "Download current vault", action: downloadvault, @@ -978,24 +982,29 @@ function sharehtml() function download(filename, content) { - // trick: https://www.bitdegree.org/learn/javascript-download - // to improve... var element = document.createElement('a'); - element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content)); + element.setAttribute('href', 'data:text/markdown;charset=utf-8,' + encodeURIComponent(content)); element.setAttribute('download', filename); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); + element = null; } function downloadnotes() { - localdata - .forEach(note => + var copy = localdata.slice(); + console.log(copy.length + " notes to download"); + var id = setInterval(() => { + var note = copy.pop(); download(note.title + ".md", note.content); - }); + if (copy.length == 0) + { + clearInterval(id); + } + }, 500); } function downloadallvaults()