-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountdown.html
More file actions
293 lines (288 loc) · 11.8 KB
/
countdown.html
File metadata and controls
293 lines (288 loc) · 11.8 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<!-- <script src="../lottie/lottie-nogzip.js"></script> -->
<script src="../lottie/lottie.min.js"></script>
<link rel="stylesheet" type="text/css" href="assets/fonts.css">
<style>
body {
font-family: 'Bild Variable Web';
font-size: 20pt;
text-shadow: -1px -1px 1px #00009e, 1px 1px 2px #00009e;
-webkit-text-stroke: 0.3px black;
color: #fff;
background-color: rgba(0, 0, 0, 0);;
padding: 0 0 0 0;
margin: 0 0 0 0;
}
.bold {
font-family: 'Bild Variable Web';
font-weight: 900;
}
.minor-container {
position: absolute;
margin-top: 170px;
margin-left: 50px;
}
.major-container {
position: absolute;
width: 300px;
margin-top: -98px;
margin-left: 1273px;
}
.major-content {
margin: 0px;
width: 100%
/* position: relative; */
}
.overlap-video {
position: absolute;
top: 0;
left: 0;
}
.host {
font-size: 36pt;
}
.preload {
display: none;
}
#lottie {
/* position: absolute; */
width: 800px;
height: 800px;
/* top: 0px;
left: 1193px; */
}
</style>
</head>
<body>
<div id="countdown">
<div class="minor-container" v-show="this.seconds>=0 && !eodaoe">
<span class="bold">NEXT REGION:</span>
{{city}} in {{hourFmt}}{{minutes.toString().padStart(2, 0)}}:{{seconds.toString().padStart(2, 0)}}
</div>
<div class="minor-container" v-show="eodaoe">
<span class="bold">Welcome to 2025!</span>
</div>
<div class="major-container">
<div class="major-content">
<video ref="hostVideo" v-show="showHostedVideo" preload="auto" width=400></video>
<img ref="hostImg" v-show="showHostedImg"></img>
<div ref="hostedLottie" id="lottie" v-show="showHostedLottie"></div>
</div>
</div>
<div class="preload">
<img ref="preloadImg"></img>
</div>
</div>
<script>
// const REF_DATETIME_STR = '2024-12-29T17:23:00'
const REF_DATETIME_STR = '2025-01-01T00:00:00'
const VIDEO_PRE_MS = 66000
const TICK_INTERVAL_MS = 100
var CITY_OFFSETS = [
{ offset: '+14:00', city: 'UTC+14 Apia, Tabwakea Village, Line Islands' },
{ offset: '+13:00', city: 'UTC+13 Auckland, Suva (Fiji), Tokelau, Tonga' },
{ offset: '+12:00', city: 'UTC+12 Marshall Islands, Nauru, Tuvalu, Petroavlovsk-Kamchatsky' },
{ offset: '+11:00', city: 'UTC+11 Sydney, Nouméa, Solomon Islands, Vanuatu, Yuzhno-Sakhalinsk' },
{ offset: '+10:00', city: 'UTC+10 Brisbane, Guam, Papua New Guinea, Khabarovsk' },
{ offset: '+09:00', city: 'UTC+9 Tokyo, Seoul, East Timor, Yakutsk' },
{ offset: '+08:00', city: 'UTC+8 Taipei, Singapore, Hong Kong, Manila, Ulan Bator, Irkutsk' },
{ offset: '+07:00', city: 'UTC+7 Bangkok, Jakarta, Hanoi, Phnom Penh, Novosibirsk' },
{ offset: '+06:00', city: 'UTC+6 Dhaka, Thumphu (Bhutan), Bishkek (Kyrgyzstan), Omsk' },
{ offset: '+05:00', city: 'UTC+5 Karachi, Tashkent, Malé (Maldives), Yekaterinburg' },
{ offset: '+04:00', city: 'UTC+4 Dubai, Seychelles, Tbilisi, Samara' },
{ offset: '+03:00', city: 'UTC+3 Moscow, Istanbul, Baghdad, Djibouti' },
{ offset: '+02:00', city: 'UTC+2 Helsinki, Cairo, Athens, Jerusalem, Harare' },
{ offset: '+01:00', city: 'UTC+1 Barcelona, Amsterdam, Berlin, Brussels, Tunis' },
{ offset: '+00:00', city: 'UTC+0 London, Lisbon, Monrovia, Canary Islands' },
{ offset: '-01:00', city: 'UTC-1 Ponta Delgada, Ittoqqortoormiit' },
{ offset: '-02:00', city: 'UTC-2 Fernando de Noronha, South Georgia & South Sandwich Islands' },
{ offset: '-03:00', city: 'UTC-3 Sao Paulo, Buenos Aires, Santiago, Nuuk' },
{ offset: '-04:00', city: 'UTC-4 Halifax, Caracas, Santo Domingo, Pitugfik' },
{ offset: '-05:00', city: 'UTC-5 New York, Toronto, Lima, Port-au-Prince, Bogotá' },
{ offset: '-06:00', city: 'UTC-6 Chicago, Winnipeg, Mexico City, Managua' },
{ offset: '-07:00', city: 'UTC-7 Edmonton, Denver, Ciudad Juarez' },
{ offset: '-08:00', city: 'UTC-8 San Francisco, Vancouver, Los Angeles, Tijuana' },
{ offset: '-09:00', city: 'UTC-9 Anchorage, Rikitea' },
{ offset: '-10:00', city: 'UTC-10 Honolulu, Avarua (Cook Islands)' },
{ offset: '-11:00', city: 'UTC-11 Tāfuna, Alofi (Niue)' },
{ offset: '-12:00', city: 'UTC-12 Howland and Baker Islands (Uninhabited), End of Day AoE' },
{ offset: '-13:00', city: '2023 AoE'}
]
const CITY_HOSTS = {
'+09:00': '../lottie/AU24_CountdownTimer_01_JPKR.json',
'+08:00': '../lottie/AU24_CountdownTimer_02_UTC8.json',
'+07:00': '../lottie/AU24_CountdownTimer_03_WIB.json',
'+02:00': '../lottie/AU24_CountdownTimer_04_EET.json',
'+01:00': '../lottie/AU24_CountdownTimer_05_CET.json',
'+00:00': '../lottie/AU24_CountdownTimer_06_GMT.json',
'-03:00': '../lottie/AU24_CountdownTimer_07_ART.json',
'-05:00': '../lottie/AU24_CountdownTimer_08_EST.json',
'-06:00': '../lottie/AU24_CountdownTimer_09_CST.json',
'-07:00': '../lottie/AU24_CountdownTimer_10_MST.json',
'-08:00': '../lottie/AU24_CountdownTimer_11_PST.json'
}
CITY_OFFSETS.forEach( (tz) => {
const dateStr = REF_DATETIME_STR+tz.offset;
// console.log(dateStr);
tz.msTime = new Date(dateStr).getTime();
})
var app = new Vue({
el: '#countdown',
data: {
cityIndex: -1,
hours: -1,
minutes: -1,
seconds: -1,
totalSecs: -1,
interval: null,
host: null,
eodaoe: false,
showHostedVideo: false,
showHostedImg: false,
showHostedLottie: false,
lottieAnim: null,
city_hosts: CITY_HOSTS
},
computed: {
city: function () {
if (this.cityIndex === -1) {
return 'Unknown'
} else {
return CITY_OFFSETS[this.cityIndex].city
}
},
offset: function () {
if (this.cityIndex === -1) {
return 'Unknown'
} else {
return CITY_OFFSETS[this.cityIndex].offset
}
},
hourFmt: function () {
if (this.hours === 0) {
return ''
} else {
return this.hours + ':'
}
}
},
mounted: function () {
this.updateCity()
this.interval = setInterval(this.tick, TICK_INTERVAL_MS)
},
methods: {
tick: function () {
if (this.cityIndex < 0) {
return
}
const msNow = new Date().getTime()
let msUntil = CITY_OFFSETS[this.cityIndex].msTime - msNow + (1000 - TICK_INTERVAL_MS)
if (msUntil < 0) {
if (msUntil > -9000) {
return
}
this.updateCity()
if (this.cityIndex === CITY_OFFSETS.length-1) {
// We're past EOD AOE, no more countdowns
clearInterval(this.interval)
this.eodaoe = true
console.log("EOD AOE - Countdown complete!")
}
msUntil = CITY_OFFSETS[this.cityIndex].msTime - msNow
} else if (msUntil <= VIDEO_PRE_MS + TICK_INTERVAL_MS) {
this.playHost()
}
// this.hours = Math.floor((msUntil % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
this.hours = Math.floor(msUntil / (1000 * 60 * 60))
this.minutes = Math.floor((msUntil % (1000 * 60 * 60)) / (1000 * 60))
this.seconds = Math.floor((msUntil % (1000 * 60)) / 1000)
this.totalSecs = msUntil / 1000
},
updateCity: function () {
const now = new Date().getTime()
for (let i=0; i<CITY_OFFSETS.length; i++) {
const msUntil = CITY_OFFSETS[i].msTime - now
if (msUntil > 0) {
this.cityIndex = i
break
}
}
if (this.cityIndex === -1) {
console.log(`${REF_DATETIME_STR} is in the past for all time zones`)
this.host = null
this.eodaoe = true
} else {
console.log(`City updated to: ${CITY_OFFSETS[this.cityIndex].city}`)
if (typeof CITY_HOSTS[this.offset] !== 'undefined') {
// The new city will be hosted
this.host = this.offset
// Prepare host video
this.preloadHost()
} else {
this.host = null
}
}
return this.cityIndex
},
preloadHost: function() {
var src = CITY_HOSTS[this.host]
var lowerSrc = src.toLowerCase()
this.showHostedImg = false
this.showHostedVideo = false
this.showHostedLottie = false
if (lowerSrc.endsWith(".webm")) {
this.$refs.hostVideo.src = src
this.$refs.hostVideo.load()
console.log("Preload hosted webm video: "+src)
} else if (lowerSrc.endsWith(".png")) {
this.$refs.preloadImg.src = src
this.$refs.hostImg.src = null
console.log("Preload hosted APNG: "+src)
} else if (lowerSrc.endsWith(".json")) {
// Presume json is lottie JSON
if (this.lottieAnim !== null) {
this.lottieAnim.destroy()
}
this.lottieAnim = bodymovin.loadAnimation({
container: document.getElementById('lottie'), // Required
path: src, // Required
renderer: 'svg', // Required
loop: false, // Optional
autoplay: false, // Optional
})
console.log("Preload hosted Lottie json: "+src)
} else {
console.log("Failed to preload hosted media that's not json, webm or png: "+src)
}
},
playHost: function() {
if (this.host) {
var src = CITY_HOSTS[this.host]
var lowerSrc = src.toLowerCase()
if (lowerSrc.endsWith(".webm") && this.$refs.hostVideo.paused) {
// Start playing video if city is hosted and it hasn't started already
console.log("Playing hosted video: "+this.$refs.hostVideo.src)
this.showHostedVideo = true
this.$refs.hostVideo.play()
} else if (lowerSrc.endsWith(".png")) {
console.log("Playing hosted APNG: "+src)
this.$refs.hostImg.src = src
this.showHostedImg = true
} else if (lowerSrc.endsWith(".json")) {
console.log("Playing hosted Lottie json: "+src)
this.showHostedLottie = true
this.lottieAnim.play()
}
}
this.host = null // make sure we play only once
}
}
});
</script>
</body>
</html>