src/pages/soundboard.astro 1.3 K raw
1
---
2
import PageLayout from "@/layouts/Base.astro";
3
4
const meta = {
5
	title: "/soundboard",
6
	description: "Click buttons. Hear sounds.",
7
};
8
9
const sounds = [
10
	{ name: "Ack", file: "/audio/ack.mp3" },
11
	{ name: "Airhorn", file: "/audio/airhorn.mp3" },
12
	{ name: "Anime Wow", file: "/audio/anime-wow.mp3" },
13
	{ name: "Boom", file: "/audio/boom.mp3" },
14
	{ name: "Bruh", file: "/audio/bruh.mp3" },
15
	{ name: "Lizard", file: "/audio/lizard.mp3" },
16
];
17
---
18
19
<PageLayout meta={meta}>
20
  <div class="space-y-6">
21
    <h1 class="title mb-6">/soundboard</h1>
22
    <div class="grid grid-cols-2 gap-4 sm:grid-cols-3">
23
      {
24
        sounds.map((sound) => (
25
          <button
26
            type="button"
27
            data-sound={sound.file}
28
            class="sound-btn aspect-square rounded-lg border border-white/20 bg-white/5 p-4 text-center transition-colors sm:hover:bg-white/10 sm:hover:text-link"
29
          >
30
            {sound.name}
31
          </button>
32
        ))
33
      }
34
    </div>
35
  </div>
36
37
  <script>
38
    const buttons = document.querySelectorAll<HTMLButtonElement>(".sound-btn");
39
    buttons.forEach((btn) => {
40
      btn.addEventListener("click", () => {
41
        const src = btn.dataset.sound;
42
        if (!src) return;
43
        const audio = new Audio(src);
44
        audio.play();
45
      });
46
    });
47
  </script>
48
</PageLayout>