-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
133 lines (110 loc) · 3.41 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@500;700&display=swap" rel="stylesheet" />
<style>
body {
font-family: "Open Sans", sans-serif;
}
.container {
max-width: 600px;
margin: 0 auto;
}
.alert {
padding: 20px;
background-color: #f44336;
color: white;
}
table {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
table td,
table th {
border: 1px solid #ddd;
padding: 8px;
}
table th {
padding-top: 12px;
padding-bottom: 12px;
background-color: #04aa6d;
color: white;
}
</style>
<title>Redirect lezioni</title>
</head>
<body>
<div class="container">
<div class="alert" id="error-box" style="display: none"></div>
<noscript>
<div class="alert"><b>Errore!</b> JavaScript richiesto.</div>
</noscript>
<table id="lessons-table" style="display: none">
<tr>
<th>Lezione</th>
<th>Ora</th>
<th>Link</th>
</tr>
<!-- Rows are populated in JavaScript -->
</table>
<p>
<a href="https://github.com/appinfosapienza/timetable-redirect/edit/main/lezioni.json">
<small>Modifica orario (autorizzati)</small>
</a>
</p>
</div>
<script>
const errorBox = document.getElementById("error-box");
const lessonsTable = document.getElementById("lessons-table");
const WEEK_DAYS = ["LUN", "MAR", "MER", "GIO", "VEN", "SAB", "DOM"];
const today = new Date();
const todayWeekDay = WEEK_DAYS[today.getDay() - 1];
function showError(error) {
errorBox.style.display = 'block';
errorBox.innerText = error.toString();
}
fetch(
"https://raw.githubusercontent.com/appinfosapienza/timetable-redirect/main/lezioni.json",
{ cache: "no-store" }
)
.then((response) => response.json())
.then((timetable) => {
const todayLessons = timetable
.flatMap((lesson) => {
return lesson.quando.map((quando) => ({
name: lesson.nome,
day: quando[0],
from: quando[1],
to: quando[2],
url: lesson.urlLezione,
}));
})
.filter((lesson) => lesson.day === todayWeekDay);
todayLessons.sort((a, b) => a.from - b.from);
if (todayLessons.length > 0) {
lessonsTable.style.display = "table";
todayLessons.forEach((lesson, index) => {
const row = lessonsTable.insertRow(index + 1);
// Opposite order
const linkCell = row.insertCell(0);
const timeCell = row.insertCell(0);
const nameCell = row.insertCell(0);
nameCell.innerText = lesson.name;
timeCell.innerText = lesson.from + " - " + lesson.to;
const linkElement = document.createElement("a");
linkElement.href = lesson.url;
linkElement.innerText = "Entra";
linkCell.appendChild(linkElement);
});
} else {
throw new Error("Nessuna lezione trovata.");
}
}).catch(err => {
showError(err);
});
</script>
</body>
</html>