-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
102 lines (88 loc) · 5.57 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
<!DOCTYPE html>
<html lang="en">
<!-- Wanna help with maintenance? Head to GitHub repo: https://github.com/joevaugh4n/hasitcomehome-->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="Has It Come Home Yet?">
<meta property="og:description" content="Find out how long it has been since it last came home.">
<meta property="og:image" content="https://hasitcomehomeyet.netlify.app/home.jpeg">
<meta property="og:url" content="https://hasitcomehomeyet.netlify.app/">
<meta property="og:type" content="website">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<title>Has It Come Home Yet?</title>
<link href="/tailwind.css" rel="stylesheet">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
</head>
<body class="min-h-screen flex flex-col">
<main class="flex flex-col flex-1 items-center font-serif px-12 my-8">
<header class="flex flex-col items-center">
<h1 class="text-4xl font-bold my-8 text-center">Has It Come Home?</h1>
</header>
<article class="text-4xl py-8 px-16 rounded text-white font-semibold mb-4 bg-orange-600 self-center shadow">Not
Yet
</article>
<aside>
<div onclick="copyTimerText()" class='cursor-pointer mb-4 text-lg' id="time-since-last-win"
class="text-lg mb-4 text-left"></div>
<div id="time-to-next-opportunity" class="text-lg"></div>
</aside>
<script>
function updateTimer() {
// England's lost to West Germany, 1970
const lastWin = new Date(Date.UTC(1970, 5, 14, 16, 0, 0));
const nextOpportunity = new Date(Date.UTC(2024, 6, 14, 21, 0, 0));
const now = new Date();
// Calculate the time difference from the last win to now
const diffToLastWin = now - lastWin;
const yearsSinceLastWin = Math.floor(diffToLastWin / (1000 * 60 * 60 * 24 * 365.25));
const monthsSinceLastWin = Math.floor((diffToLastWin % (1000 * 60 * 60 * 24 * 365.25)) / (1000 * 60 * 60 * 24 * 30.44));
const daysSinceLastWin = Math.floor((diffToLastWin % (1000 * 60 * 60 * 24 * 30.44)) / (1000 * 60 * 60 * 24));
const hoursSinceLastWin = Math.floor((diffToLastWin % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutesSinceLastWin = Math.floor((diffToLastWin % (1000 * 60 * 60)) / (1000 * 60));
const secondsSinceLastWin = Math.floor((diffToLastWin % (1000 * 60)) / 1000);
document.getElementById('time-since-last-win').innerHTML =
`<b>${yearsSinceLastWin} years, ${monthsSinceLastWin} months, ${daysSinceLastWin} days, ${hoursSinceLastWin} hours, ${minutesSinceLastWin} minutes, and ${secondsSinceLastWin} seconds of hurt</b>.`;
// Calculate the time difference from now to the next opportunity
const diffToOpportunity = nextOpportunity - now;
if (diffToOpportunity > 0) {
const daysToOpportunity = Math.floor(diffToOpportunity / (1000 * 60 * 60 * 24));
const hoursToOpportunity = Math.floor((diffToOpportunity % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutesToOpportunity = Math.floor((diffToOpportunity % (1000 * 60 * 60)) / (1000 * 60));
const secondsToOpportunity = Math.floor((diffToOpportunity % (1000 * 60)) / 1000);
document.getElementById('time-to-next-opportunity').innerHTML =
`The next opportunity for it to come home is in <b>${daysToOpportunity} days</b>, <b>${hoursToOpportunity} hours</b>, <b>${minutesToOpportunity} minutes</b>, and <b>${secondsToOpportunity} seconds</b>.`;
}
}
function copyTimerText() {
const range = document.createRange();
const timeToNextOpportunity = document.getElementById('time-since-last-win');
range.selectNode(timeToNextOpportunity);
window.getSelection().removeAllRanges(); // clear current selection
window.getSelection().addRange(range); // to select text
document.execCommand('copy');
window.getSelection().removeAllRanges(); // to deselect
alert('Timer text copied to clipboard!');
}
setInterval(updateTimer, 1000);
updateTimer();
</script>
</main>
<footer class='flex font-serif mx-10 self-end md:flex-row flex-col gap-x-4 gap-y-2 items-end mb-4 mt-8'>
<div>Maths by <a class="underline text-[#0000EE]" href="https://joevaughan.net">Joe Vaughan</a></div>
<a href="https://github.com/joevaugh4n/hasitcomehome" class="underline text-[#0000EE]">Link to repo</a>
<script type='text/javascript' src='https://storage.ko-fi.com/cdn/widget/Widget_2.js'></script>
<script type='text/javascript'>
kofiwidget2.init('Coffee for more maths', '#29abe0', 'B0B7ZLCIS');
kofiwidget2.draw();
</script>
</footer>
</body>
</html>