Add click sound effect and option to disable on settings.

This commit is contained in:
天クマ 2026-07-01 15:08:00 -03:00
commit fb73bfa300
7 changed files with 40 additions and 0 deletions

View file

@ -69,6 +69,7 @@ module.exports = {
by: "by",
back: "back",
hideBackground: "Hide background",
disableSoundEffects: "Disable sound effects",
options: "Options",
alsoAvailableAsVideo: "Also available as video",
websiteDescription: "Personal website/blog of Adrian Victor.",
@ -124,6 +125,7 @@ module.exports = {
by: "por",
back: "voltar",
hideBackground: "Esconder imagem de fundo",
disableSoundEffects: "Desabilitar efeitos sonoros",
options: "Opções",
alsoAvailableAsVideo: "Também disponível em vídeo",
websiteDescription: "Website/blog pessoal de Adrian Victor.",

View file

@ -20,6 +20,7 @@
<script type="module" src="{{ '/static/scripts/music.js' | url }}" defer></script>
<script type="module" src="{{ '/static/scripts/88x31.js' | url }}" defer></script>
<script type="module" src="{{ '/static/scripts/tips.js' | url }}" defer></script>
<script type="module" src="{{ '/static/scripts/click.js' | url }}" defer></script>
<link rel="apple-touch-icon" sizes="180x180" href="{{ '/static/apple-touch-icon.png' | url }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ '/static/favicon-32x32.png' | url }}">

View file

@ -12,6 +12,7 @@
permissionIssue: "{{ i18n[langKey].permissionIssue | safe }}",
permissionIssueNotificationContent: "{{ i18n[langKey].permissionIssueNotificationContent | safe }}",
notificationDefaultHint: "{{ i18n[langKey].notificationDefaultHint | safe }}",
disableSoundEffects: "{{ i18n[langKey].disableSoundEffects | safe }}"
}
</script>
</div>

BIN
static/audio/click.ogg Normal file

Binary file not shown.

BIN
static/audio/hover.ogg Normal file

Binary file not shown.

26
static/scripts/click.js Normal file
View file

@ -0,0 +1,26 @@
/*
This script plays a sound when user clicks on the page.
*/
const click = new Audio(`${rootPrefix}static/audio/click.ogg`);
const hover = new Audio(`${rootPrefix}static/audio/hover.ogg`);
click.preload = "auto";
hover.preload = "auto";
click.volume = 0.5;
hover.volume = 0.5;
document.body.addEventListener("click", () => {
if (localStorage.getItem("disablesfx") == 'true') return;
click.currentTime = 0;
click.play().catch(() => {});
});
document.querySelectorAll('a').forEach(link => {
link.addEventListener("mouseenter", () => {
if (localStorage.getItem("disablesfx") == 'true') return;
hover.currentTime = 0;
hover.play().catch(() => {});
})
})

View file

@ -49,6 +49,10 @@ optionsAside.classList.add("metromenu");
<p>${headeri18n.hideBackground}</p>
<input id="background" type="checkbox"></input>
</div>
<div class="checkbox">
<p>${headeri18n.disableSoundEffects}</p>
<input id="soundEffects" type="checkbox"></input>
</div>
</div>
`
optionsAside.appendChild(content);
@ -76,6 +80,12 @@ function toggleBG() {
localStorage.setItem("bgHidden", bg.classList.contains("invisible"))
}
const disableSFX = document.querySelector("input#soundEffects");
if (localStorage.getItem("disablesfx") === "true") disableSFX.checked = true;
disableSFX.addEventListener("click", () => {
localStorage.setItem("disablesfx", disableSFX.checked)
})
const songsDrawer = document.querySelector("#songDrawer");
const drawerSongs = [];
const playlist = document.querySelector("#playlist");