forked from kabukki/khrissbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
162 lines (157 loc) · 2.79 KB
/
main.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
const SFX_PATH_BASE = 'assets/sfx';
const SFX = {
feuerball: {
text: 'Feuerball',
samples: 1
},
ruelps: {
text: 'Rülps',
samples: 1
},
homo: {
text: 'Homo',
samples: 1
},
kackteil: {
text: 'Kackteil',
samples: 1
},
fuehlnichts: {
text: 'Ich fühl nichts',
samples: 1
},
zweiliter: {
text: '2 liter Muschi',
samples: 1
},
geldgeben: {
text: 'Gib Geld',
samples: 1
},
bierweg: {
text: 'Bleib vom Bier weg',
samples: 1
},
meinplatz: {
text: 'Mein Platz',
samples: 1
},
homo2: {
text: 'Was fürn Homo',
samples: 1
},
nichtgefickt: {
text: 'Gefickt wird nicht',
samples: 1
},
unfall: {
text: 'Da haben wir den Unfall',
samples: 1
},
sonescheisse: {
text: 'Sone Scheiße',
samples: 1
},
kommdoch: {
text: 'Komm doch Junge',
samples: 1
},
homo3: {
text: 'Homo!',
samples: 1
},
sogehtdas: {
text: 'In die Fresse ballern',
samples: 1
},
mongo: {
text: 'Verrückter Mongo',
samples: 1
},
gehtnicht: {
text: 'Junge das geht nicht',
samples: 1
},
geldalle: {
text: 'Einkaufen, Geld alle',
samples: 1
},
freibier: {
text: 'Freibier!',
samples: 1
},
fingervonnuggets: {
text: 'Lass deine Finger von meinen Nuggets',
samples: 1
},
wievielbier: {
text: 'Wie viel Bier ist das?',
samples: 1
},
lastkraftwagen: {
text: 'Lastkraftwagenfahrer',
samples: 1
},
wasserskiYorick: {
text: 'Wasserskifahren mit Yorick',
samples: 1
},
sicherwache: {
text: 'Sicher auf Wache?',
samples: 1
},
dulallst: {
text: 'Du weißt wie doll du lallst?',
samples: 1
},
maybritthass: {
text: 'Maybritt ich hasse dich',
samples: 1
},
jajaja: {
text: 'Jajaja',
samples: 1
}
};
/**
* Returns a random number between two bounds
* @param {*} min
* @param {*} max
*/
function getRandomNumber (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* Returns a random sample path for the given SFX
* @param {*} name
*/
function getSFXPath (name) {
if (!(name in SFX)) throw new Error(`Unknown SFX: ${name}`);
return SFX_PATH_BASE + '/' + name + '/' + getRandomNumber(1, SFX[name].samples) + '.wav';
}
const audio = new Audio();
const main = document.querySelector('main');
// Register service worker
if ('serviceWorker' in navigator) {
window.addEventListener('load', async _ => {
try {
const registration = await navigator.serviceWorker.register('/soundboard/sw.js', {
scope: '/soundboard/'
});
console.log(registration);
} catch (err) {
console.log(err.message);
}
})
}
// Create buttons
for (const [name, sfx] of Object.entries(SFX)) {
const button = document.createElement('button');
button.innerText = `${sfx.text}`;
button.addEventListener('click', _ => {
audio.src = getSFXPath(name);
console.log(audio.src);
audio.play();
});
main.appendChild(button);
}