From 9b25af24a0ef37fa758cf61a2d3382a839b18a90 Mon Sep 17 00:00:00 2001 From: giuliof Date: Sun, 18 Nov 2018 19:18:45 +0100 Subject: [PATCH] (ugly) JS frontend --- frontend/frontend.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 frontend/frontend.js diff --git a/frontend/frontend.js b/frontend/frontend.js new file mode 100644 index 0000000..d513981 --- /dev/null +++ b/frontend/frontend.js @@ -0,0 +1,23 @@ +function Get(yourUrl){ + var Httpreq = new XMLHttpRequest(); + Httpreq.open("GET",yourUrl,false); + Httpreq.send(null); + return Httpreq.responseText; +} + +var json_obj = JSON.parse(Get("https://golem.linux.it/cgi/zerocalcare/main.py?interval=4weeks")); +console.log("this is the JSON: "+JSON.stringify(json_obj)); +fmt_date = { weekday: 'short', month: 'long', day: 'numeric' }; +fmt_time = { hour: 'numeric', minute: 'numeric'}; +for (i in json_obj) { + var time_str; + var date = new Date(json_obj[i]["DATETIME"]) + console.log(JSON.stringify(json_obj[i])); + document.write('
'+json_obj[i]["NAME"]+'
'); + document.write("
📅 "+date.toLocaleDateString("it-IT", fmt_date)+"
"); + if (json_obj[i]["ALLDAY"] == true) + time_str = "Tutto il giorno" + else + time_str = date.toLocaleString("it-IT", fmt_time) + document.write("
⏰ "+time_str+"
"); +}