changed: store bookmarks as json

added: command to browse bookmarks
This commit is contained in:
quenousimporte 2024-01-07 16:54:28 +01:00
parent f83944444f
commit e9076eb2d0
2 changed files with 48 additions and 19 deletions

View File

@ -1,6 +1,9 @@
javascript: (function() javascript: (function()
{ {
var notesurl = ""; var notesurl = "";
var content = document.title + "\n" + document.location; var bm = {
window.open("https://" + notesurl + "?c=" + encodeURIComponent(content), "_blank", "popup,width=100,height=100"); title: document.title,
url: document.location.href
};
window.open("https://" + notesurl + "?c=" + encodeURIComponent(JSON.stringify(bm)), "_blank", "popup,width=100,height=100");
})(); })();

60
main.js
View File

@ -268,6 +268,10 @@ var commands = [
hint: "Remove completed tasks", hint: "Remove completed tasks",
action: purgetodo, action: purgetodo,
allowunsaved: true allowunsaved: true
},
{
hint: "Browse bookmarks",
action: browsebookmarks
}]; }];
var snippets = [ var snippets = [
@ -313,6 +317,21 @@ var snippets = [
insert: "x " + (new Date).toISOString().substring(0, 10) + " " 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() function purgetodo()
{ {
if (currentistodo() && confirm("Remove completed tasks?")) if (currentistodo() && confirm("Remove completed tasks?"))
@ -1184,7 +1203,30 @@ function loadstorage()
if (clip) 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) if (currentnote)
@ -1200,12 +1242,6 @@ function loadstorage()
currentnote = {title: title, content: newcontent, pos: newcontent.length}; currentnote = {title: title, content: newcontent, pos: newcontent.length};
localdata.unshift(currentnote); 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) if (currentnote)
@ -1215,16 +1251,6 @@ function loadstorage()
{ {
gotoline(line); 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 else
{ {