diff options
Diffstat (limited to 'public/common/client.js')
-rw-r--r-- | public/common/client.js | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/public/common/client.js b/public/common/client.js index ef1a0bc..871393a 100644 --- a/public/common/client.js +++ b/public/common/client.js @@ -123,10 +123,14 @@ function drag_element_with_mouse(element_sel, grabber_sel) { let sound_effects = {} function play_sound(type) { - if (!sound_effects[type]) - sound_effects[type] = new Audio("/sounds/" + type + ".mp3") - sound_effects[type].currentTime = 0 - sound_effects[type].play() + if (document.hasFocus()) + return + if (window.localStorage.play_sound | 0) { + if (!sound_effects[type]) + sound_effects[type] = new Audio("/sounds/" + type + ".mp3") + sound_effects[type].currentTime = 0 + sound_effects[type].play() + } } /* TITLE BLINKER */ @@ -843,6 +847,18 @@ function add_main_menu_item_link(text, url) { popup.insertBefore(item, sep) } +function add_main_menu_item_toggle(property, on, off) { + let popup = document.querySelector("#toolbar details menu") + let sep = popup.querySelector(".separator") + let item = document.createElement("li") + item.textContent = (window.localStorage[property] | 0) ? on : off + item.onclick = function (evt) { + window.localStorage[property] = 1 - (window.localStorage[property] | 0) + item.textContent = (window.localStorage[property] | 0) ? on : off + } + popup.insertBefore(item, sep) +} + add_main_menu_separator() if (params.mode === "play" && params.role !== "Observer") { add_main_menu_item_link("Go home", "/games/active") @@ -851,6 +867,8 @@ if (params.mode === "play" && params.role !== "Observer") { add_main_menu_item_link("Go home", "/") } +add_main_menu_item_toggle("play_sound", "Mute sound", "Play sound") + function close_toolbar_menus(self) { for (let node of document.querySelectorAll("#toolbar > details")) if (node !== self) |