forked from c3re/c3re-website
reformte js
parent
77a6b4f165
commit
2a8a424ca7
|
@ -1,53 +1,62 @@
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
let url =
|
||||||
let url="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"
|
"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";
|
||||||
let xmlHttp = new XMLHttpRequest();
|
let xmlHttp = new XMLHttpRequest();
|
||||||
let zeropad=function(i){
|
let zeropad = function (i) {
|
||||||
let o=""
|
let o = "";
|
||||||
if(i<=9) o+="0"
|
if (i <= 9) o += "0";
|
||||||
o+=i
|
o += i;
|
||||||
return o
|
return o;
|
||||||
}
|
};
|
||||||
xmlHttp.onreadystatechange = function() {
|
xmlHttp.onreadystatechange = function () {
|
||||||
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
|
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
|
||||||
let cal=JSON.parse(xmlHttp.responseText)
|
let cal = JSON.parse(xmlHttp.responseText);
|
||||||
let $ = jQuery
|
let $ = jQuery;
|
||||||
let box=$('#calendar')
|
let box = $("#calendar");
|
||||||
for(let item of cal){
|
for (let item of cal) {
|
||||||
let li=$("<li/>")
|
let li = $("<li/>");
|
||||||
//li.text(item.summary)
|
//li.text(item.summary)
|
||||||
let startDate=new Date(item.start * 1000)
|
let startDate = new Date(item.start * 1000);
|
||||||
let date=$("<span class='date'/>")
|
let date = $("<span class='date'/>");
|
||||||
date.text(zeropad(startDate.getDate())+'.'+zeropad(1+startDate.getMonth())+'.'+startDate.getFullYear()+' - '+zeropad(startDate.getHours())+':'+zeropad(startDate.getMinutes()))
|
date.text(
|
||||||
date.appendTo(li)
|
zeropad(startDate.getDate()) +
|
||||||
let summary=$("<span class='summary'/>")
|
"." +
|
||||||
summary.text(item.summary)
|
zeropad(1 + startDate.getMonth()) +
|
||||||
if(item.url){
|
"." +
|
||||||
let a = $('<a/>')
|
startDate.getFullYear() +
|
||||||
a.attr('href',item.url)
|
" - " +
|
||||||
a.attr('title',item.description)
|
zeropad(startDate.getHours()) +
|
||||||
a.append(summary)
|
":" +
|
||||||
a.appendTo(li)
|
zeropad(startDate.getMinutes())
|
||||||
}else{
|
);
|
||||||
summary.appendTo(li)
|
date.appendTo(li);
|
||||||
}
|
let summary = $("<span class='summary'/>");
|
||||||
if(item.location){
|
summary.text(item.summary);
|
||||||
let loc=$("<span class='location'>📍</span>")
|
if (item.url) {
|
||||||
|
let a = $("<a/>");
|
||||||
loc.attr('data-loc',item.location)
|
a.attr("href", item.url);
|
||||||
loc.attr('title',"Click to copy: "+item.location)
|
a.attr("title", item.description);
|
||||||
loc.appendTo(li)
|
a.append(summary);
|
||||||
}
|
a.appendTo(li);
|
||||||
|
} else {
|
||||||
li.attr('title',item.description)
|
summary.appendTo(li);
|
||||||
li.appendTo(box)
|
|
||||||
}
|
}
|
||||||
$(".location",box).click(function(){
|
if (item.location) {
|
||||||
navigator.clipboard.writeText($(this).attr('data-loc'))
|
let loc = $("<span class='location'>📍</span>");
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xmlHttp.open("GET", url, true); // true for asynchronous
|
|
||||||
xmlHttp.send();
|
|
||||||
|
|
||||||
|
loc.attr("data-loc", item.location);
|
||||||
|
loc.attr("title", "Click to copy: " + item.location);
|
||||||
|
loc.appendTo(li);
|
||||||
|
}
|
||||||
|
|
||||||
|
li.attr("title", item.description);
|
||||||
|
li.appendTo(box);
|
||||||
|
}
|
||||||
|
$(".location", box).click(function () {
|
||||||
|
navigator.clipboard.writeText($(this).attr("data-loc"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xmlHttp.open("GET", url, true); // true for asynchronous
|
||||||
|
xmlHttp.send();
|
||||||
});
|
});
|
|
@ -1,21 +1,37 @@
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
const update = function () {
|
||||||
|
fetch("https://spaceapi.c3re.de/")
|
||||||
|
.then(function (response) {
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(function (data) {
|
||||||
|
document
|
||||||
|
.getElementById("ds-img")
|
||||||
|
.setAttribute(
|
||||||
|
"src",
|
||||||
|
data.state.open ? data.state.icon.open : data.state.icon.closed
|
||||||
|
);
|
||||||
|
document.getElementById("ds-status").innerHTML = data.state.open
|
||||||
|
? "Geöffnet"
|
||||||
|
: "Geschlossen";
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.getElementById("ds-temp").innerHTML =
|
||||||
const update=function(){
|
"" +
|
||||||
fetch("https://spaceapi.c3re.de/").then(function(response) {
|
data.sensors.temperature[0].value +
|
||||||
return( response.json());
|
data.sensors.temperature[0].unit;
|
||||||
}).then(function(data) {
|
const lastchange = new Date(data.state.lastchange * 1000);
|
||||||
document.getElementById("ds-img").setAttribute("src",data.state.open?data.state.icon.open:data.state.icon.closed);
|
document.getElementById("ds-date").innerHTML =
|
||||||
document.getElementById("ds-status").innerHTML=data.state.open?"Geöffnet":"Geschlossen";
|
lastchange.getDate().toString().padStart(2, "0") +
|
||||||
|
"." +
|
||||||
document.getElementById("ds-temp").innerHTML=""+data.sensors.temperature[0].value+data.sensors.temperature[0].unit;
|
(lastchange.getMonth() + 1).toString().padStart(2, "0") +
|
||||||
const lastchange=new Date(data.state.lastchange*1000)
|
"." +
|
||||||
document.getElementById('ds-date').innerHTML=lastchange.getDate().toString().padStart(2, "0") + "."
|
lastchange.getFullYear() +
|
||||||
+ (lastchange.getMonth()+1).toString().padStart(2, "0") + "."
|
" " +
|
||||||
+ lastchange.getFullYear() + " "
|
lastchange.getHours().toString().padStart(2, "0") +
|
||||||
+ lastchange.getHours().toString().padStart(2, "0") + ":"
|
":" +
|
||||||
+ lastchange.getMinutes().toString().padStart(2, "0")
|
lastchange.getMinutes().toString().padStart(2, "0");
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
update();
|
update();
|
||||||
setInterval(update,10000);
|
setInterval(update, 10000);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.querySelectorAll("a").forEach(function (element) {
|
||||||
document.querySelectorAll('a').forEach(function(element) {
|
|
||||||
const myhost = window.location.hostname;
|
const myhost = window.location.hostname;
|
||||||
const linkhost=new URL(element.href).hostname;
|
const linkhost = new URL(element.href).hostname;
|
||||||
if(myhost === linkhost) {
|
if (myhost === linkhost) {
|
||||||
let prefetchUrl=new URL(element.href).toString()
|
let prefetchUrl = new URL(element.href).toString();
|
||||||
// lest make a prefetch tag for this url
|
// lest make a prefetch tag for this url
|
||||||
let link = document.createElement('link');
|
let link = document.createElement("link");
|
||||||
link.setAttribute('rel', 'prefetch');
|
link.setAttribute("rel", "prefetch");
|
||||||
link.setAttribute('href', prefetchUrl);
|
link.setAttribute("href", prefetchUrl);
|
||||||
link.setAttribute('as', 'document');
|
link.setAttribute("as", "document");
|
||||||
document.head.appendChild(link);
|
document.head.appendChild(link);
|
||||||
element.classList.add("internal");
|
element.classList.add("internal");
|
||||||
}else {
|
} else {
|
||||||
element.setAttribute("target", "_blank");
|
element.setAttribute("target", "_blank");
|
||||||
element.classList.add("external");
|
element.classList.add("external");
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue