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
|
||||
updateVolumeLabel();
|
||||
}
|
||||
function volumeAdd(number) {
|
||||
volumeSet(Math.min(1, Math.max(0, audio.volume + number)));
|
||||
function volumeInc() {
|
||||
//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() {
|
||||
const percentage = `${Math.round(audio.volume * 100)}%`;
|
||||
|
@ -378,8 +384,8 @@
|
|||
localStorage.audiomuted = audio.muted = musicmute.checked;
|
||||
playMusic();
|
||||
})
|
||||
volumeStepDwn.addEventListener('click', () => volumeAdd(-0.05));
|
||||
volumeStepUp.addEventListener('click', () => volumeAdd(0.05));
|
||||
volumeStepDwn.addEventListener('click', volumeDec);
|
||||
volumeStepUp.addEventListener('click', volumeInc);
|
||||
|
||||
updateVolumeLabel();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue