Persist audio toggle setting

This commit is contained in:
Laurence Juden 2022-08-25 16:52:17 +02:00
parent 5542b5e9a6
commit 8e2074d29d

View File

@ -69,10 +69,20 @@
</body> </body>
<script> <script>
const SOUND_ENABLED_KEY = "soundEnabled"
document.querySelector('#sound_toggle').checked = isSoundEnabled();
const HEALTH_PING_INTERVAL = 5 // seconds const HEALTH_PING_INTERVAL = 5 // seconds
let serverStatus = 'offline' let serverStatus = 'offline'
function isSoundEnabled() {
if (localStorage.getItem(SOUND_ENABLED_KEY) === 'false') {
return false
}
return true
}
function setStatus(statusType, msg, msgType) { function setStatus(statusType, msg, msgType) {
let el = '' let el = ''
@ -230,6 +240,12 @@ async function makeImage() {
} }
} }
function handleAudioEnabledChange(e) {
localStorage.setItem(SOUND_ENABLED_KEY, e.target.checked.toString())
}
document.querySelector('#sound_toggle').addEventListener('click', handleAudioEnabledChange)
document.querySelector('#makeImage').addEventListener('click', makeImage) document.querySelector('#makeImage').addEventListener('click', makeImage)
let config = document.querySelector('#config') let config = document.querySelector('#config')