summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-04-13 21:30:24 +0200
committerTor Andersson <tor@ccxvii.net>2024-04-13 21:30:24 +0200
commite4696a5cb03351e4b7772c614be5dae43e685ae4 (patch)
tree53ab4da83d096bd9dd844c33a34db27fa2ba8c0a
parent21d21a8af3e62f3b4c7885913533ac3c8212b511 (diff)
downloadserver-e4696a5cb03351e4b7772c614be5dae43e685ae4.tar.gz
WIP sounds more control?
-rw-r--r--public/common/client.js26
-rw-r--r--public/join.js10
2 files changed, 28 insertions, 8 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)
diff --git a/public/join.js b/public/join.js
index 8298837..59b2a63 100644
--- a/public/join.js
+++ b/public/join.js
@@ -64,10 +64,12 @@ function hide_invite() {
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 (window.localStorage.play_sound) {
+ if (!sound_effects[type])
+ sound_effects[type] = new Audio("/sounds/" + type + ".mp3")
+ sound_effects[type].currentTime = 0
+ sound_effects[type].play()
+ }
}
let blink_title = document.title