-
Notifications
You must be signed in to change notification settings - Fork 0
/
funbackup.html
386 lines (336 loc) · 10.9 KB
/
funbackup.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8" />
<title>Vad har vi nu?</title>
<style>
/* CSS for a cute and soft UI */
@import url('https://fonts.googleapis.com/css2?family=DynaPuff&display=swap');
@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');
body {
background-color: #68384c;
margin: 0;
padding: 0;
font-family: 'DynaPuff', cursive;
display: flex;
flex-direction: column;
align-items: center;
overflow: hidden;
}
h1 {
font-size: 4em;
font-weight: bold;
margin-top: 5%;
color: #f0dcdc;
text-align: center;
letter-spacing: 2px;
}
p {
margin: 5%;
padding: 1%;
font-size: 4em;
color: #fdd5d5;
text-align: center;
font-weight: ;
}
.progress-bar {
margin: 20px;
width: 80%;
height: 40px;
border-radius: 20px;
background-color: #754747;
position: relative;
overflow: hidden;
/* hide the overflow of the progress bar */
}
.progress-bar span {
display: block;
height: 100%;
border-radius: 20px;
background-color: #a3d47a;
position: absolute;
transition: width 0.5s ease;
/* add a transition to the width property */
}
/* Button styles */
.button {
display: inline-block;
padding: 10px 10px;
background-color: #815a5a;
color: #fff;
font-size: 1.2em;
font-weight: bold;
text-decoration: solid;
border-radius: 15px;
text-align: center;
margin: 20px;
font-family: 'dynapuff', cursive;
transition: background-color 0.8s ease;
}
.button:hover {
background-color: #a89494;
}
/* Dropdown styles */
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: center;
z-index: 1;
background-color: #f5d0d0;
min-width: 170px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
border-radius: 5px;
font-size: 1.3em;
}
.dropdown-content a {
color: #815a5a;
font-family: 'dynapuff', cursive padding: 2px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #dfc4c4;
}
.dropdown:hover .dropdown-content {
display: block;
}
/* Media queries */
@media screen and (max-width: 768px) {
h1 {
font-size: 3.5em;
}
p {
font-size: 2.1em;
}
.progress-bar {
width: 80%;
}
}
</style>
<script>
// JavaScript code
let events = [];
let eventDuration = 0;
const eventFiles = [
{
name: "9B",
url: "9B.json"
},
{
name: "9A",
url: "9A.json"
},
{
name: "9C",
url: "9C.json"
}
];
function loadJSON(callback, url) {
const xhr = new XMLHttpRequest();
xhr.overrideMimeType("application/json");
xhr.open("GET", url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == "200") {
callback(xhr.responseText);
}
};
xhr.send(null);
}
function getTodaysEvents() {
const today = new Date();
const dayOfWeek = today.getDay();
return events.filter((event) => event.startDay === dayOfWeek);
}
function getNextEvent() {
const now = new Date();
const today = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate()
);
const todaysEvents = getTodaysEvents();
for (let i = 0; i < todaysEvents.length; i++) {
const start = new Date(
`${today.toDateString()} ${todaysEvents[i].startTime}`
);
const end = new Date(
`${today.toDateString()} ${todaysEvents[i].endTime}`
);
if (now >= start && now < end) {
// We're currently in this event
return { name: todaysEvents[i].name, start: start, end: end };
} else if (now < start) {
// This event hasn't started yet
return { name: todaysEvents[i].name, start: start, end: end };
}
}
// There are no events left today
return null;
}
function updateCountdown() {
if (events.length === 0) {
// JSON hasn't loaded yet, try again later
setTimeout(updateCountdown, 1000);
return;
}
const now = new Date();
const nextEvent = getNextEvent();
if (nextEvent === null) {
// No events left today
document.getElementById("countdown").innerHTML =
"Inga fler lektioner idag.";
document.getElementById("progress-bar").style.display = "none";
return;
}
const eventName = nextEvent.name;
const start = nextEvent.start;
const end = nextEvent.end;
if (now < start) {
// Event hasn't started yet
const timeUntilStart = (start - now) / 1000; // Convert to seconds
const countdown = ` ${eventName} börjar om: ${formatSeconds(
timeUntilStart
)} `;
document.getElementById("countdown").innerHTML = countdown;
document.getElementById("countdown").style.color = "#fdd5d5";
document.getElementById("progress").style.width = "0";
document.getElementById("progress").style.backgroundColor = "#a3d47a";
document.getElementById("progress-bar").style.display = "block";
return;
}
// Event is ongoing or already finished
const totalDuration = (end - start) / 1000; // Convert to seconds
const timeElapsed = (now - start) / 1000; // Convert to seconds
const timeRemaining = (end - now) / 1000; // Convert to seconds
const eventDuration = (end - start) / 1000; // convert to seconds
if (timeRemaining < 300 && timeRemaining >= 60) {
// Change color to yellow when there's less than 5 minutes left
document.getElementById("countdown").style.color = "#f7d26f";
document.getElementById("progress").style.backgroundColor = "#f7d26f";
} else if (timeRemaining < 60) {
// Change color to red when there's less than 1 minute left
document.getElementById("countdown").style.color = "#f36868";
document.getElementById("progress").style.backgroundColor = "#f26868";
}
const countdown = `Tid kvar för ${eventName}: ${formatSeconds(
timeRemaining
)}`;
document.getElementById("countdown").innerHTML = countdown;
const percentElapsed = (timeElapsed / eventDuration) * 100;
const width =
(percentElapsed / 100) *
document.getElementById("progress-bar").offsetWidth;
document.getElementById("progress").style.width = `${width}px`;
document.getElementById("progress-bar").style.display = "block";
}
function formatSeconds(seconds) {
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const paddedSeconds = pad(Math.floor(seconds) % 60, 2);
if (hours > 0) {
return `${hours}:${pad(minutes % 60, 2)}:${paddedSeconds}`;
}
return `${pad(minutes, 2)}:${paddedSeconds}`;
}
function pad(num, size) {
return ("000000000" + num).substr(-size);
}
function loadEventFile(url) {
loadJSON(function (response) {
events = JSON.parse(response);
updateCountdown();
}, url);
}
function init() {
const dropdownContent = document.querySelector(".dropdown-content");
const dropdownButton = document.querySelector(".dropdown-button");
eventFiles.forEach((eventFile) => {
const eventButton = document.createElement("a");
eventButton.innerText = eventFile.name;
eventButton.onclick = () => {
loadEventFile(eventFile.url);
};
dropdownContent.appendChild(eventButton);
});
loadEventFile(eventFiles[0].url);
}
setInterval(updateCountdown, 100);
</script>
</head>
<body onload="init()">
<h1>Vad har vi nu?</h1>
<p id="countdown"></p>
<div class="progress-bar" id="progress-bar">
<span id="progress"></span>
</div>
<div class="dropdown">
<button class="dropdown-button button">Byt schema</button>
<div class="dropdown-content"></div>
</div>
</body>
</html>
<div
id="page-visit-count"
style="
position: relative;
bottom: -20px;
right: 10px;
background-color: rgba(31, 21, 21, 0.5);
padding: 5px;
color: #fff;
font-size: 16px;
"
>
Du är den <span id="visit-count"></span>e besökaren!
</div>
<script>
// Check if the page was loaded for the first time in this session
let isNewSession = sessionStorage.getItem("isNewSession") === null;
if (isNewSession) {
// Get the visit count from local storage, or set it to 0 if it doesn't exist
let visitCount = localStorage.getItem("visitCount");
if (!visitCount) {
visitCount = 0;
}
// Increment the visit count and save it to local storage
visitCount++;
localStorage.setItem("visitCount", visitCount);
// Display the visit count on the page
document.getElementById("visit-count").textContent = visitCount;
// Log the current visit count to the console
console.log(`Current visit count: ${visitCount}`);
// Set the session flag to prevent incrementing the count on page refresh
sessionStorage.setItem("isNewSession", false);
} else {
// Get the visit count from local storage and display it on the page
let visitCount = localStorage.getItem("visitCount");
document.getElementById("visit-count").textContent = visitCount;
// Log the current visit count to the console
console.log(`Current visit count: ${visitCount}`);
}
// Get the client IP address and log it to the console
const ipRequest = new XMLHttpRequest();
ipRequest.addEventListener("load", function () {
console.log(`Client IP address: ${this.responseText}`);
});
ipRequest.open("GET", "https://api.ipify.org", true);
ipRequest.send();
// Fade out the visit count after 5 seconds
setTimeout(function () {
let fadeEffect = setInterval(function () {
if (!document.getElementById("page-visit-count").style.opacity) {
document.getElementById("page-visit-count").style.opacity = 1;
}
if (document.getElementById("page-visit-count").style.opacity > 0) {
document.getElementById("page-visit-count").style.opacity -= 0.1;
} else {
clearInterval(fadeEffect);
document.getElementById("page-visit-count").style.display = "none";
}
}, 50);
}, 5000);
</script>
</body> </html>