6
0
Fork 0
3D-Druck_Landingpage/themes/hugo-theme-flat/static/js/calendar.js

79 lines
2.3 KiB
JavaScript
Raw Normal View History

2024-02-18 10:17:23 +01:00
const calRefresh=function () {
2024-01-18 14:26:34 +01:00
let url =
2024-02-18 10:17:23 +01:00
"https://ical2json.c3re.de/api/?url=https%3A%2F%2Fcloud.c3re.de%2Fremote.php%2Fdav%2Fpublic-calendars%2FRLKKkdjNYgXH8yEz%3Fexport&start=today&end=next+month&maxitems=10";
2024-01-18 14:26:34 +01:00
let xmlHttp = new XMLHttpRequest();
let zeropad = function (i) {
let o = "";
if (i <= 9) o += "0";
o += i;
return o;
};
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
let cal = JSON.parse(xmlHttp.responseText);
let $ = jQuery;
let box = $("#calendar");
2024-02-18 10:17:23 +01:00
box.removeClass("loading");
try{
for( el of document.querySelectorAll("#calendar li")){
el.remove()
}
}catch(e){}
2024-01-18 14:26:34 +01:00
for (let item of cal) {
let li = $("<li/>");
//li.text(item.summary)
let startDate = new Date(item.start * 1000);
2024-02-12 18:02:25 +01:00
let date = $("<span class='date row'/>");
2024-01-18 14:26:34 +01:00
date.text(
2024-02-18 10:17:23 +01:00
zeropad(startDate.getDate()) +
2024-01-18 14:26:34 +01:00
"." +
zeropad(1 + startDate.getMonth()) +
"." +
startDate.getFullYear() +
" - " +
zeropad(startDate.getHours()) +
":" +
zeropad(startDate.getMinutes())
);
date.appendTo(li);
2024-02-12 18:02:25 +01:00
let summary = $("<span class='summary row'/>");
2024-01-18 14:26:34 +01:00
summary.text(item.summary);
if (item.url) {
let a = $("<a/>");
a.attr("href", item.url);
a.attr("title", item.description);
a.append(summary);
a.appendTo(li);
} else {
summary.appendTo(li);
}
if (item.location) {
let loc = $("<span class='location'>📍</span>");
2024-01-08 21:25:56 +01:00
2024-01-18 14:26:34 +01:00
loc.attr("data-loc", item.location);
loc.attr("title", "Click to copy: " + item.location);
2024-02-12 18:02:25 +01:00
loc.appendTo(date);
2024-01-08 21:25:56 +01:00
}
2024-01-18 14:26:34 +01:00
li.attr("title", item.description);
li.appendTo(box);
}
2024-02-18 10:17:23 +01:00
try{
document.querySelector("#calendar .loading").remove();
2024-02-18 10:17:23 +01:00
}catch(e){}
2024-01-18 14:26:34 +01:00
$(".location", box).click(function () {
navigator.clipboard.writeText($(this).attr("data-loc"));
});
}
};
xmlHttp.open("GET", url, true); // true for asynchronous
xmlHttp.send();
2024-02-18 10:17:23 +01:00
}
document.addEventListener("DOMContentLoaded", function(){
calRefresh();
setInterval(calRefresh, 1000*60*15);
2024-01-18 14:26:34 +01:00
});