From e9076eb2d0adf8c911a4e51f61f0418a725fa63c Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Sun, 7 Jan 2024 16:54:28 +0100 Subject: [PATCH] changed: store bookmarks as json added: command to browse bookmarks --- clipper/clipper.js | 7 ++++-- main.js | 60 +++++++++++++++++++++++++++++++++------------- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/clipper/clipper.js b/clipper/clipper.js index 873d55d..290a74e 100644 --- a/clipper/clipper.js +++ b/clipper/clipper.js @@ -1,6 +1,9 @@ javascript: (function() { var notesurl = ""; - var content = document.title + "\n" + document.location; - window.open("https://" + notesurl + "?c=" + encodeURIComponent(content), "_blank", "popup,width=100,height=100"); + var bm = { + title: document.title, + url: document.location.href + }; + window.open("https://" + notesurl + "?c=" + encodeURIComponent(JSON.stringify(bm)), "_blank", "popup,width=100,height=100"); })(); diff --git a/main.js b/main.js index 88e45b3..2d87473 100644 --- a/main.js +++ b/main.js @@ -268,6 +268,10 @@ var commands = [ hint: "Remove completed tasks", action: purgetodo, allowunsaved: true +}, +{ + hint: "Browse bookmarks", + action: browsebookmarks }]; var snippets = [ @@ -313,6 +317,21 @@ var snippets = [ insert: "x " + (new Date).toISOString().substring(0, 10) + " " }]; + +function browsebookmarks() +{ + var bookmarks = JSON.parse(getnote("bookmarks").content); + searchinlist(bookmarks.map(b => b.title)) + .then(title => + { + var url = bookmarks + .find(b => b.title == title) + .url; + + window.open(url, "_blank"); + }); +} + function purgetodo() { if (currentistodo() && confirm("Remove completed tasks?")) @@ -1184,7 +1203,30 @@ function loadstorage() if (clip) { - title = "bookmarks"; + var bmnote = getnote("bookmarks"); + if (!bmnote) + { + bmnote = {title: "bookmarks", content: "[]"}; + localdata.unshift(bmnote); + } + + var bookmarks = JSON.parse(bmnote.content); + bookmarks.unshift(JSON.parse(clip)); + bmnote.content = JSON.stringify(bookmarks, null, " "); + + bindfile(bmnote); + + colored.hidden = true; + md.hidden = true; + var msg = document.createElement("div"); + msg.innerText = "Clipping..."; + msg.setAttribute("style", "width:100px;height:100px;top:0;left:0"); + notepage.appendChild(msg); + + saved = false; + save(); + + return; } if (currentnote) @@ -1200,12 +1242,6 @@ function loadstorage() currentnote = {title: title, content: newcontent, pos: newcontent.length}; localdata.unshift(currentnote); } - if (clip) - { - hat = headerandtext(currentnote); - var dt = timestamp().substr(0,10); - currentnote.content = hat.header + dt + " " + clip + "\n\n" + hat.text; - } } if (currentnote) @@ -1215,16 +1251,6 @@ function loadstorage() { gotoline(line); } - if (clip) - { - colored.hidden = true; - var msg = document.createElement("div"); - msg.innerText = "Clipping..."; - msg.setAttribute("style", "width:100px;height:100px;top:0;left:0"); - notepage.appendChild(msg); - saved = false; - save(); - } } else {