forked from mirrors/akkoma-fe
round volume to nearest 10%
This commit is contained in:
parent
b9540a6ac3
commit
a1abd32939
1 changed files with 10 additions and 4 deletions
|
@ -50,8 +50,14 @@
|
||||||
localStorage.audiovolume = number; //Save
|
localStorage.audiovolume = number; //Save
|
||||||
updateVolumeLabel();
|
updateVolumeLabel();
|
||||||
}
|
}
|
||||||
function volumeAdd(number) {
|
function volumeInc() {
|
||||||
volumeSet(Math.min(1, Math.max(0, audio.volume + number)));
|
//We would not need to multiply by 10 and truncate if
|
||||||
|
//not for javascript constantly spewing rounding errors.
|
||||||
|
//But we do not live in an ideal world.
|
||||||
|
volumeSet(Math.min(1, Math.floor((Math.trunc(audio.volume * 1000) / 100) + 1) * 0.1));
|
||||||
|
}
|
||||||
|
function volumeDec() {
|
||||||
|
volumeSet(Math.max(0, Math.ceil((Math.trunc(audio.volume * 1000) / 100) - 1) * 0.1));
|
||||||
}
|
}
|
||||||
function updateVolumeLabel() {
|
function updateVolumeLabel() {
|
||||||
const percentage = `${Math.round(audio.volume * 100)}%`;
|
const percentage = `${Math.round(audio.volume * 100)}%`;
|
||||||
|
@ -378,8 +384,8 @@
|
||||||
localStorage.audiomuted = audio.muted = musicmute.checked;
|
localStorage.audiomuted = audio.muted = musicmute.checked;
|
||||||
playMusic();
|
playMusic();
|
||||||
})
|
})
|
||||||
volumeStepDwn.addEventListener('click', () => volumeAdd(-0.05));
|
volumeStepDwn.addEventListener('click', volumeDec);
|
||||||
volumeStepUp.addEventListener('click', () => volumeAdd(0.05));
|
volumeStepUp.addEventListener('click', volumeInc);
|
||||||
|
|
||||||
updateVolumeLabel();
|
updateVolumeLabel();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue