-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
95 lines (79 loc) · 2.02 KB
/
index.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
import { version } from "/app-info.js";
const version_div = document.getElementById("version");
version_div.innerText = `v${version}`;
/**
* @type HTMLAudioElement
*/
const audio = document.getElementById("white-audio");
/**
* @type HTMLDivElement
*/
const playButton = document.getElementById("play-button");
/**
* @type HTMLDivElement
*/
const playInnerButton = document.getElementById("play-inner-button");
/**
* @type Element
*/
const mainElement = document.getElementById("main");
/**
* @type Element
*/
const menuButton = document.getElementById("menu-button");
/**
* @type Element
*/
const drawer = document.getElementById("drawer");
/** @type HTMLButtonElement */
const installDialog = document.querySelector("#install-dialog");
/** @type HTMLElement */
const installButton = document.querySelector("#install-button");
installDialog.addEventListener("ready", () => {
installButton.removeAttribute("hidden");
});
installButton.addEventListener("click", () => {
installDialog.show();
});
audio.addEventListener("timeupdate", () => {
// if 1 second left in audio track reset track to 0
// so it's continuous
if (audio.currentTime > audio.duration - 1) {
audio.currentTime = 1;
audio.play();
}
});
playButton.addEventListener("click", () => {
if (audio.paused) {
audio.play();
} else {
audio.pause();
}
});
audio.addEventListener("play", () => {
playInnerButton.classList.add("pause");
mainElement.classList.add("playing");
});
audio.addEventListener("pause", () => {
playInnerButton.classList.remove("pause");
mainElement.classList.remove("playing");
});
// side drawer setup
menuButton.addEventListener("opened", (ev) => {
drawer.open = true;
});
drawer.addEventListener("open", (ev) => {
menuButton.open = true;
});
drawer.addEventListener("close", (ev) => {
menuButton.open = false;
});
document.addEventListener("keydown", (ev) => {
if (ev.code === "Space" && ev.target === document.body) {
if (audio.paused) {
audio.play();
} else {
audio.pause();
}
}
});