Merge branch 'main' into feat/colors

This commit is contained in:
quenousimporte 2023-09-27 12:17:59 +02:00
commit bfb0258720
1 changed files with 47 additions and 0 deletions

47
main.js
View File

@ -361,6 +361,11 @@ var commands = [
{
hint: "Decrypt note",
action: decryptnote
},
{
hint: "Show upcoming events",
action: showupcomingevents,
remoteonly: true
}];
var snippets = [
@ -991,6 +996,48 @@ function changesetting()
});
}
function showupcomingevents()
{
var note = getnote("events.json");
if (note)
{
var upcomingnote = getorcreate("Upcoming events", "---\ntags: preview\n---\n\n");
var events = JSON.parse(note.content);
var sorted = {};
events.forEach(event =>
{
var date = new Date(event.DTSTART);
if (date >= new Date)
{
event.readabledate = date.toLocaleDateString('fr-FR', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
var month = event.readabledate.split(" ")[2];
var year = event.readabledate.split(" ")[3];
sorted[year] = sorted[year] || {};
sorted[year][month] = sorted[year][month] || [];
sorted[year][month].push(event);
}
});
upcomingnote.content = "";
for (var year in sorted)
{
upcomingnote.content += "# " + year + "\n";
for (var month in sorted[year])
{
upcomingnote.content += "## " + month.charAt(0).toUpperCase() + month.slice(1) + "\n";
for (var i in sorted[year][month])
{
var event = sorted[year][month][i];
upcomingnote.content += event.readabledate.split(" ")[0] + " " + event.readabledate.split(" ")[1] + ": " + event.SUMMARY + "\n";
}
}
}
bindfile(upcomingnote);
togglepreview();
}
}
function decryptnote()
{
decryptstring(md.value)