-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
487 lines (450 loc) · 14.7 KB
/
script.js
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
import store from "./store.js";
import { requestAnimFrame } from "./lib.js";
import sparks from "./sparks.js";
import {
html as swalSettingsHtml,
mountSwal as swalSettingsMount,
} from "./components/settings.js";
import {
html as swalEditorHtml,
mountSwal as swalEditorMount,
} from "./components/text-editor.js";
import {
html as iframeHtml,
mountSwal as swalIframeMount,
} from "./components/iframe.js";
import {
html as swalPlatformHtml,
mountSwal as swalPlatformMount,
} from "./components/platform.js";
(() => {
const rand = function (a, b) {
return ~~(Math.random() * (b - a + 1) + a);
};
let released = false;
//Use this function to get UTC time
Date.prototype.getUTCTime = function () {
return new Date(
this.getUTCFullYear(),
this.getUTCMonth(),
this.getUTCDate(),
this.getUTCHours(),
this.getUTCMinutes(),
this.getUTCSeconds()
).getTime();
};
function calcFPS(opts) {
const count = opts.count || 60;
let index;
// eslint-disable-next-line no-undef
const start = performance.now();
if (!requestAnimFrame) return true;
function checker() {
if (index--) requestAnimFrame(checker);
else {
// eslint-disable-next-line no-undef
const result = (count * 1000) / (performance.now() - start);
if (typeof opts.callback === "function") opts.callback(result);
window.app.fps = Math.round(result);
}
}
if (!opts) opts = {};
index = count;
checker();
}
async function setBackground(url, isMobile) {
const blobUrl = await window
.fetch(url)
.then((res) => res.blob())
.then((blob) => URL.createObjectURL(blob));
document.body.style.background = "black url(" + blobUrl + ")";
document.body.style.backgroundRepeat = "no-repeat";
if (isMobile) {
document.body.style.backgroundSize = "auto";
document.body.style.backgroundPosition = "50% 0%";
document.body.style.backgroundAttachment = "scroll";
} else {
document.body.style.backgroundSize = "cover";
document.body.style.backgroundPosition = "50% 50%";
document.body.style.backgroundAttachment = "fixed";
}
}
calcFPS({ count: 144 });
window.app = new window.Vue({
el: "#app",
data: store,
async mounted() {
const self = this;
const savedSettings = JSON.parse(window.localStorage.getItem("settings"));
if (savedSettings && savedSettings.version === this.settings.version) {
this.settings = savedSettings;
} else {
window.localStorage.setItem("settings", JSON.stringify(this.settings));
}
try {
document.createEvent("TouchEvent");
this.isTouch = true;
} catch {
this.isTouch = false;
}
await this.updateBackground();
this.initBackgroundInterval();
this.initCountDownDate();
this.initHiddenBar();
this.initListeners();
this.initToastStyles();
this.updateMusic();
this.fadingLoop();
setTimeout(function () {
self.toastStyle.visibility = "hidden";
}, 5000);
sparks();
// Select platform on first visit to correctly calculate the release time
if (this.settings.console === "") {
this.settings.console = "true";
await this.platformChooser();
}
},
watch: {
settings: {
handler() {
this.updateTextStyle();
window.localStorage.setItem(
"settings",
JSON.stringify(this.settings)
);
},
deep: true,
},
"settings.backgroundImage"() {
if (this.settings.backgroundImage) {
this.updateBackground();
} else {
document.body.style.background = "black";
}
},
"settings.maxTextOpacity"() {
if (this.fading) return;
this.textStyle.opacity = this.settings.maxTextOpacity;
},
"settings.music"() {
this.updateMusic();
},
"settings.uncompressedImages"() {
this.updateBackground();
},
countdownUpdate() {
this.countdown = {
days: Math.floor(this.distance() / (1000 * 60 * 60 * 24)),
hours: Math.floor(
(this.distance() % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
),
minutes: Math.floor(
(this.distance() % (1000 * 60 * 60)) / (1000 * 60)
),
seconds: Math.floor((this.distance() % (1000 * 60)) / 1000),
};
},
"settings.volume"() {
if (this.musicPlayer != null)
this.musicPlayer.volume = this.settings.volume / 100;
},
"settings.console"() {
this.initCountDownDate();
},
},
methods: {
applyTextStylePreset(defaultPreset) {
this.settings.textBrightness = 1.25;
this.settings.maxTextOpacity = 1;
this.textStyle.opacity = 1;
if (defaultPreset) {
this.settings.dropShadowColor = "";
this.settings.dropShadowX = 0;
this.settings.dropShadowY = 0;
this.settings.dropShadowBlur = 0;
} else {
this.settings.dropShadowColor = "black";
this.settings.dropShadowX = 2;
this.settings.dropShadowY = 2;
this.settings.dropShadowBlur = 3;
}
},
countdownLoop() {
this.countdownUpdate++;
if (this.distance() <= 0) {
if (!released) {
this.settings.music = "resources/music/timothy-richards.mp3";
this.updateMusic();
released = true;
}
} else {
return this.countdownLoop;
}
},
fadingLoop() {
if (!this.lastFrameTime) this.lastFrameTime = Date.now();
const deltaTime = Date.now() - this.lastFrameTime;
const increment = (0.007 * deltaTime) / 16;
if (this.contentOpacity > 1) {
this.contentOpacity = 1;
this.fading = false;
return;
}
if (this.textStyle.opacity >= this.settings.maxTextOpacity) {
this.textStyle.opacity = this.settings.maxTextOpacity;
this.toastStyle.opacity = this.settings.maxTextOpacity;
} else {
this.textStyle.opacity =
parseFloat(this.textStyle.opacity) + increment;
this.toastStyle.opacity =
parseFloat(this.textStyle.opacity) + increment;
}
requestAnimFrame(this.fadingLoop);
this.contentOpacity += increment;
this.lastFrameTime = Date.now();
},
async iframeClick(src) {
if (this.musicPlayer !== null) this.musicPlayer.pause();
if (this.isTouch) {
window.open(src);
} else {
this.iframeUrl = src;
this.initIframe();
window.Swal.fire({
html: await iframeHtml,
showConfirmButton: false,
background: "rgba(0,0,0,0)",
}).then((value) => {
this.menuVisible = value;
if (this.musicPlayer !== null) this.musicPlayer.play();
});
this.$nextTick(swalIframeMount);
this.toastStyle.visibility = "hidden";
this.hiddenBarVisible = false;
this.menuVisible = false;
}
},
initBackgroundInterval() {
setInterval(() => {
if (this.today !== new Date().getDay()) {
this.today = new Date().getDay();
this.updateBackground();
}
}, 1000);
},
initCountDownDate() {
// Set release time according to daylight saving
if (
new Date().getTime() > new Date("Oct 31, 2021 04:00:00").getTime()
) {
// Change between local release time (consoles) and global UTC release time (steam)
if (this.settings.console === "true") {
// Local time
this.countDownDate = new Date("Jun 21, 2024 00:00:00").getTime();
} else {
// Global UTC
this.countDownDate = new Date("Jun 20, 2024 23:00:00").getTime();
}
} else {
if (this.settings.console === "true") {
this.countDownDate = new Date("Jun 20, 2024 23:00:00").getTime();
} else {
this.countDownDate = new Date("Jun 20, 2024 22:00:00").getTime();
}
}
this.untilInterval = setInterval(this.countdownLoop(), 1000);
},
initHiddenBar() {
if (this.isTouch) {
const mc = new window.Hammer.Manager(document.body, {
recognizers: [
[window.Hammer.Swipe, { direction: window.Hammer.DIRECTION_ALL }],
],
});
mc.on("swipeup", () => {
this.hiddenBarVisible = true;
this.toastStyle.visibility = "hidden";
});
mc.on("swipedown", () => {
if (!this.hiddenBarVisible) {
window.location.reload();
} else {
this.hiddenBarVisible = false;
}
});
} else {
document.body.onmousemove = (e) => {
if (!(this.menuVisible && window.app.settings.hiddenBar)) {
this.hiddenBarVisible = false;
return;
}
const pos = { x: e.clientX, y: e.clientY };
if (
pos.y < window.innerHeight - 100 &&
this.settings.topBar !== "true"
) {
this.hiddenBarVisible = false;
return;
} else if (pos.y > 100 && this.settings.topBar === "true") {
this.hiddenBarVisible = false;
return;
}
this.toastStyle.visibility = "hidden";
this.hiddenBarVisible = true;
};
}
},
initIframe() {
this.iframeWidth = window.innerWidth * 0.75;
this.iframeHeight = window.innerWidth * 0.75 * (9 / 16);
if (this.iframeHeight > window.innerHeight) {
this.iframeWidth = (window.innerHeight * 0.75) / (9 / 16);
this.iframeHeight = window.innerHeight * 0.75;
}
},
initListeners() {
if (!(this.settings.hiddenBar || this.isTouch))
this.toastMessage = "press esc to re-enable the bottom bar";
// Toggle hidden bar with ESC
document.addEventListener("keydown", (e) => {
if (e.code === "Escape") {
this.settings.hiddenBar = !this.settings.hiddenBar;
}
});
// Play music upon user interaction
document.body.addEventListener(
"mousemove",
() => this.musicPlayer?.currentTime === 0 && this.musicPlayer?.play()
);
document.body.addEventListener(
"click",
() => this.musicPlayer?.currentTime === 0 && this.musicPlayer?.play()
);
document.body.addEventListener(
"keydown",
() => this.musicPlayer?.currentTime === 0 && this.musicPlayer?.play()
);
// Resize iframes based on window resize
window.addEventListener("resize", () => {
this.initIframe();
});
},
initToastStyles() {
this.toastStyle.filter =
"brightness(" +
this.settings.textBrightness +
") drop-shadow(" +
this.settings.dropShadowColor +
" " +
this.settings.dropShadowX +
"px " +
this.settings.dropShadowY +
"px " +
this.settings.dropShadowBlur +
"px";
this.toastStyle.bottom = this.settings.topBar === "true" ? "" : "30px";
this.toastStyle.top = this.settings.topBar === "true" ? "30px" : "";
if (this.isTouch) {
this.toastStyle.left = "48%";
this.toastMessage = "swipe up for info and settings";
} else {
this.toastStyle.left = "49%";
this.toastStyle.fontSize = "20px";
this.toastMessage =
"move the mouse cursor here for info and settings";
}
},
async settingsClick() {
window.Swal.fire({
html: await swalSettingsHtml,
showConfirmButton: false,
background: "rgba(50,50,50,1)",
}).then((value) => {
this.menuVisible = value;
});
this.$nextTick(swalSettingsMount);
this.toastStyle.visibility = "hidden";
if (!this.isTouch) this.hiddenBarVisible = false;
this.menuVisible = false;
},
async textEditorClick(recall) {
window.Swal.fire({
html: await swalEditorHtml,
showConfirmButton: false,
background: "rgba(50,50,50,1)",
position: "top-end",
showClass: {
popup: recall ? "" : "swal2-show",
backdrop: "",
},
}).then((value) => {
this.menuVisible = value;
});
this.$nextTick(swalEditorMount);
},
async updateBackground() {
if (!this.settings.backgroundImage) return;
const uncompressed = this.settings.uncompressedImages ? "-u" : "";
const url = "resources/backgrounds/dlc/" + rand(1, 12) + ".jpg";
await window
.fetch(url, { method: "HEAD" })
.then((res) =>
res.ok ? url : "resources/backgrounds/dlc/" + rand(1, 12) + ".jpg"
)
.then((url) => setBackground(url, this.isMobile));
},
updateTextStyle() {
this.textStyle.filter =
"brightness(" +
this.settings.textBrightness +
") drop-shadow(" +
this.settings.dropShadowColor +
" " +
this.settings.dropShadowX +
"px " +
this.settings.dropShadowY +
"px " +
this.settings.dropShadowBlur +
"px)";
},
updateMusic() {
try {
this.musicPlayer.pause();
this.musicPlayer.currentTime = 0;
} catch {}
if (!(this.settings.music === "none")) {
this.musicPlayer = new window.Audio(this.settings.music);
this.musicPlayer.loop = true;
this.musicPlayer.volume = this.settings.volume / 100;
} else this.musicPlayer = null;
},
formatValue(value, name) {
return `${value} ${name}${value === 1 ? "" : "s"}`;
},
distance() {
if (this.settings.console === "true") {
return this.countDownDate - new Date().getTime();
} else {
return this.countDownDate - new Date().getUTCTime();
}
},
secondsRemaining() {
return this.distance() <= 60 * 1000;
},
async platformChooser() {
window.Swal.fire({
html: await swalPlatformHtml,
showConfirmButton: true,
background: "rgba(50,50,50,1)",
allowOutsideClick: false,
confirmButtonColor:
"rgb(var(--pure-material-primary-rgb, 33, 150, 243))",
}).then((value) => {
this.menuVisible = value;
});
this.$nextTick(swalPlatformMount);
},
},
});
})();