From f01fb199dcf85c7ae5645768c398413371f1ad50 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Thu, 20 Jul 2023 09:52:17 +0200 Subject: [PATCH 01/10] added: insert header common --- main.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.js b/main.js index 546cf92..8394d0c 100644 --- a/main.js +++ b/main.js @@ -207,6 +207,12 @@ var commands = [ hint: "Restore note", action: restore }, +{ + shortcut: "ctrl+h", + hint: "Insert markdown header", + action: insertheader, + allowunsaved: true +}, { shortcut: "F1", hint: "Show help", @@ -2096,6 +2102,17 @@ function restore() } } +function insertheader() +{ + if (preview.hidden && !md.value.startsWith("---\n")) + { + var headers = "---\ndate: " + (new Date).toISOString().substring(0, 10) + "\ntags: \n---\n\n"; + md.value = headers + md.value; + setpos(27); + } + resize(); +} + function splitshortcut(s) { var r = {}; From 45a85e13ff61f83914aad0740e410e1a439f1f3a Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Fri, 21 Jul 2023 10:34:43 +0200 Subject: [PATCH 02/10] fixed: do not hide title on change if option is checked --- main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 8394d0c..9dc1762 100644 --- a/main.js +++ b/main.js @@ -2227,7 +2227,11 @@ function ontitlechange() datachanged(); setwindowtitle(); - toggletitle(); + + if (!settings.titlebydefault) + { + toggletitle(); + } } function applyfilter() From f17eb11afc170003e1b8cd4f083830d13b2a71a6 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Fri, 21 Jul 2023 10:58:13 +0200 Subject: [PATCH 03/10] added: new theme white monkey improved titlebydefault setting --- main.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 9dc1762..982fd28 100644 --- a/main.js +++ b/main.js @@ -98,6 +98,16 @@ var themes = lineheight: "24px", accentcolor: "#5AA7CE" }, + "White monkey": + { + bgcolor: "white", + fontfamily: "'Inconsolata', 'Consolas', monospace", + fontsize: "18px", + fontcolor: "black", + lineheight: "150%", + accentcolor: "#5AA7CE", + titlebydefault: true + }, Mariana: { bgcolor: "rgb(48,56,65)", @@ -1116,6 +1126,11 @@ function applystyle() { title.style.color = settings.accentcolor; } + + if (settings.titlebydefault && title.hidden) + { + toggletitle(); + } } function loadsettings() @@ -1136,7 +1151,7 @@ function loadsettings() applystyle(); - if (settings.titlebydefault) + if (settings.titlebydefault && title.hidden) { toggletitle(); } From 9cb6080cf77fd80b8f02aa944a1da8dcdc8cb553 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Wed, 16 Aug 2023 17:03:38 +0200 Subject: [PATCH 04/10] fixed: search in list accent insensitive --- main.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 982fd28..b0638f9 100644 --- a/main.js +++ b/main.js @@ -2249,11 +2249,16 @@ function ontitlechange() } } +function simplifystring(str) +{ + return str.toLowerCase().normalize('NFD').replace(/\p{Diacritic}/gu, ""); +} + function applyfilter() { [...filteredlist.children].forEach(div => { - div.hidden = div.textContent.toLowerCase().indexOf(filter.value.toLowerCase()) < 0; + div.hidden = simplifystring(div.textContent).indexOf(simplifystring(filter.value)) < 0; }); fileindex = 0; From efddca0483a475055b661ba3a308ae8b075f8c4d Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Thu, 24 Aug 2023 11:07:46 +0200 Subject: [PATCH 05/10] changed: removed default title from theme settings --- main.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/main.js b/main.js index b0638f9..92fec49 100644 --- a/main.js +++ b/main.js @@ -105,8 +105,7 @@ var themes = fontsize: "18px", fontcolor: "black", lineheight: "150%", - accentcolor: "#5AA7CE", - titlebydefault: true + accentcolor: "#5AA7CE" }, Mariana: { @@ -1126,11 +1125,6 @@ function applystyle() { title.style.color = settings.accentcolor; } - - if (settings.titlebydefault && title.hidden) - { - toggletitle(); - } } function loadsettings() From bb1730f2b2f9aa9d41f4b6d92386f278c9a3b480 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Thu, 24 Aug 2023 17:19:03 +0200 Subject: [PATCH 06/10] added: pgp in cli tool --- tools/nodeclient/app.js | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/tools/nodeclient/app.js b/tools/nodeclient/app.js index c4312ba..5058d0c 100644 --- a/tools/nodeclient/app.js +++ b/tools/nodeclient/app.js @@ -1,6 +1,7 @@ const axios = require("axios"); const readline = require("readline"); const fs = require("fs"); +const openpgp = require("openpgp"); var cp = require("child_process"); var rl = readline.createInterface({ @@ -9,10 +10,34 @@ var rl = readline.createInterface({ }); var settings = JSON.parse(fs.readFileSync("settings.json", { encoding: "utf8", flag: "r" })); +var pgpkey = fs.readFileSync("key.acs", { encoding: "utf8", flag: "r" }); var filter = process.argv.length > 2 ? process.argv[2] : ""; var intervalid = null; var notes = null; +async function decrypt(str) +{ + var key = pgpkey.split("-----END PGP PUBLIC KEY BLOCK-----")[1]; + var privateKey = await openpgp.readKey({ armoredKey: key }); + var decrypted = await openpgp.decrypt({ + message: await openpgp.readMessage({ armoredMessage: str }), + decryptionKeys: privateKey }); + const chunks = []; + for await (const chunk of decrypted.data) { + chunks.push(chunk); + } + return chunks.join(''); +} + +async function encrypt(str) +{ + var key = pgpkey.split("-----BEGIN PGP PRIVATE KEY BLOCK-----")[0]; + var publicKey = await openpgp.readKey({ armoredKey: key }); + return await openpgp.encrypt({ + message: await openpgp.createMessage({ text: str }), + encryptionKeys: publicKey }); +} + function filteredlist() { return notes @@ -30,9 +55,9 @@ axios.post(`${settings.url}/handler.php`, "Content-type": "application/x-www-form-urlencoded" } }) -.then(res => +.then(async function(res) { - notes = res.data; + notes = JSON.parse(await decrypt(res.data)); filteredlist() .every( (note, i) => @@ -43,14 +68,14 @@ axios.post(`${settings.url}/handler.php`, // todo: open if only one match. quit if no match rl.prompt(); - rl.on("line", (line) => + rl.on("line", async function (line) { var note = filteredlist()[line]; // todo: use title instead? To put in data folder? fs.writeFileSync("note.md", note.content); - cp.exec(`${settings.command} note.md`, function (err, stdout, stderr) + cp.exec(`${settings.command} note.md`, async function (err, stdout, stderr) { clearInterval(intervalid); var newcontent = fs.readFileSync("note.md", { encoding: "utf8", flag: "r" }); @@ -62,11 +87,12 @@ axios.post(`${settings.url}/handler.php`, notes.unshift(note); console.log("sending data file to server..."); + var encrypted = await encrypt(JSON.stringify(notes)); axios.post(`${settings.url}/handler.php`, { action: "push", password: settings.password, - data: JSON.stringify(notes) + data: encrypted }, { headers: @@ -83,7 +109,7 @@ axios.post(`${settings.url}/handler.php`, } }) - intervalid = setInterval(function() + intervalid = setInterval(async function() { //todo: refactor "save" var newcontent = fs.readFileSync("note.md", { encoding: "utf8", flag: "r" }); @@ -95,11 +121,12 @@ axios.post(`${settings.url}/handler.php`, notes.unshift(note); console.log("sending data file to server..."); + var encrypted = await encrypt(JSON.stringify(notes)); axios.post(`${settings.url}/handler.php`, { action: "push", password: settings.password, - data: JSON.stringify(notes) + data: encrypted }, { headers: From c48da6d245a12405c729ff46a52b1a996b6e564f Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Fri, 25 Aug 2023 17:44:24 +0200 Subject: [PATCH 07/10] cli tool: handle accents in filter --- tools/nodeclient/app.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/nodeclient/app.js b/tools/nodeclient/app.js index 5058d0c..aaeec02 100644 --- a/tools/nodeclient/app.js +++ b/tools/nodeclient/app.js @@ -15,6 +15,11 @@ var filter = process.argv.length > 2 ? process.argv[2] : ""; var intervalid = null; var notes = null; +function simplifystring(str) +{ + return str.toLowerCase().normalize('NFD').replace(/\p{Diacritic}/gu, ""); +} + async function decrypt(str) { var key = pgpkey.split("-----END PGP PUBLIC KEY BLOCK-----")[1]; @@ -41,7 +46,7 @@ async function encrypt(str) function filteredlist() { return notes - .filter(n => n.title.toLowerCase().includes(filter.toLowerCase())); + .filter(n => simplifystring(n.title).includes(simplifystring(filter))); } axios.post(`${settings.url}/handler.php`, From 6122e20e3dfe8fbee277b64bbdd4ee42d0b4cdb9 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Fri, 25 Aug 2023 17:57:20 +0200 Subject: [PATCH 08/10] cli tool: bypass max count if there is a filter --- tools/nodeclient/app.js | 2 +- tools/nodeclient/settings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/nodeclient/app.js b/tools/nodeclient/app.js index aaeec02..54287c6 100644 --- a/tools/nodeclient/app.js +++ b/tools/nodeclient/app.js @@ -68,7 +68,7 @@ axios.post(`${settings.url}/handler.php`, .every( (note, i) => { console.log(`[${i}] ${note.title}`) - return i < settings.maxcount; + return Boolean(filter) || i < settings.maxcountifnofilter; }); // todo: open if only one match. quit if no match diff --git a/tools/nodeclient/settings.json b/tools/nodeclient/settings.json index fa4fd04..227734b 100644 --- a/tools/nodeclient/settings.json +++ b/tools/nodeclient/settings.json @@ -1,6 +1,6 @@ { "password": "", "url": "http://localhost:8000", - "maxcount": 50, + "maxcountifnofilter": 10, "command": "sublime_text.exe -w" } From 77e63d3113a785c5cfc2cf027a781a7ec080f362 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Mon, 28 Aug 2023 11:21:39 +0200 Subject: [PATCH 09/10] fixed: cursor pos in % when content is empty --- main.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 92fec49..fe93751 100644 --- a/main.js +++ b/main.js @@ -510,6 +510,11 @@ function formatsize(size) return size.toFixed(2) + " " + unit; } +function pospercent() +{ + return md.value.length > 0 ?(100 * md.selectionStart / md.value.length).toFixed(2) : 100; +} + function showinfo() { var tags = gettags(currentnote); @@ -518,7 +523,7 @@ function showinfo() "vault: " + currentvault, "saved: " + saved, "title: " + currentnote.title, - "cursor position: " + md.selectionStart + " (" + (100 * md.selectionStart / md.value.length).toFixed(2) + "%)", + "cursor position: " + md.selectionStart + " (" + pospercent() + "%)", (tags ? "tags: " + tags : ""), "spell check: " + (md.spellcheck ? "en" : "dis") + "abled", "notes count: " + localdata.length, From 45898cc2141b406ecd27c924ba99622c6f868e0c Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Mon, 28 Aug 2023 11:33:04 +0200 Subject: [PATCH 10/10] renamed cli tool settings file --- tools/nodeclient/{settings.json => settingssample.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tools/nodeclient/{settings.json => settingssample.json} (100%) diff --git a/tools/nodeclient/settings.json b/tools/nodeclient/settingssample.json similarity index 100% rename from tools/nodeclient/settings.json rename to tools/nodeclient/settingssample.json