added: upcoming events

This commit is contained in:
quenousimporte 2023-09-27 09:05:45 +02:00
parent 1ce493fe58
commit e59e37d954
1 changed files with 46 additions and 0 deletions

46
main.js
View File

@ -360,6 +360,10 @@ var commands = [
{ {
hint: "Decrypt note", hint: "Decrypt note",
action: decryptnote action: decryptnote
},
{
hint: "Show upcoming events",
action: showupcomingevents
}]; }];
var snippets = [ var snippets = [
@ -971,6 +975,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() function decryptnote()
{ {
decryptstring(md.value) decryptstring(md.value)