This repository has been archived by the owner on Mar 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
100 lines (88 loc) · 2.97 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>When does next semester start?</title>
<style>
body {
text-align: center;
}
h1 {
font-size: 4em;
}
</style>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
<script type="text/babel">
ReactDOM.render([
<h1>11th October 2021*</h1>,
<p>*The date is final but it can still change.</p>
],
document.getElementById("reactCrap"));
</script>
</head>
<body>
<div id="reactCrap"></div>
<h2 id="counter"></h2>
<script>
let counter = document.getElementById("counter");
let currentTime = new Date().getTime();
let probablyOpen = new Date(Date.UTC(2021, 11, 11, 18, 0));
let actual_timediff = Math.floor((probablyOpen - currentTime) / 1000);
let half_life = actual_timediff / 2;
let fake_counter = Math.min(60 * 60 * 4 * Math.random(), actual_timediff);
let x = 0;
function pluralize(count, word) {
if (count !== 1) {
return `${word}s`;
}
return word;
}
function updateCounter(elem) {
x++;
let timediff;
if (x < 4) {
timediff = fake_counter - x;
} else {
// The Laws of Time Are Mine!
timediff = Math.floor((fake_counter - 3) * 2 ** ((-1 * x) / half_life));
}
let now = moment();
let end = moment(new Date(Date.UTC(2021, 09, 11, 00, 0))); // Semester start date
let duration = moment.duration(end.diff(now));
durationArr = [];
if (duration._data.years > 0) {
durationArr.push(`${duration._data.years} ${pluralize(duration._data.years, 'year')}`);
}
if (duration._data.months > 0) {
durationArr.push(`${duration._data.months} ${pluralize(duration._data.months, 'month')}`);
}
if (duration._data.days > 0) {
durationArr.push(`${duration._data.days} ${pluralize(duration._data.days, 'day')}`);
}
if (duration._data.weeks > 0) {
durationArr.push(`${duration._data.weeks} ${pluralize(duration._data.weeks, 'week')}`);
}
if (duration._data.hours > 0) {
durationArr.push(`${duration._data.hours} ${pluralize(duration._data.hours, 'hour')}`);
}
if (duration._data.minutes > 0) {
durationArr.push(`${duration._data.minutes} ${pluralize(duration._data.minutes, 'minute')}`);
}
if (duration._data.seconds > 0) {
durationArr.push(`${duration._data.seconds} ${pluralize(duration._data.seconds, 'second')}`);
}
time = new Date(timediff * 1000);
countDownString = durationArr.join(', ');
counter.innerHTML =
timediff > 1 && actual_timediff > 0
? `Starting in ${countDownString}`
: "New semester started!";
}
setInterval(() => updateCounter(counter), 1000);
</script>
</body>
</html>