summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2025-02-01 12:32:20 +0100
committerTor Andersson <tor@ccxvii.net>2025-02-02 12:47:38 +0100
commit243b7bdb7b82eba14ff2ae682134e98d6366bff6 (patch)
tree424a3d29647ae336ff32f8c995fe0a98ba579e7e
parente101c7a58b3cfdbf6164ad0097d907e9bdf39602 (diff)
downloadserver-243b7bdb7b82eba14ff2ae682134e98d6366bff6.tar.gz
Use mark in browser title instead of blinking text.
-rw-r--r--public/common/client.js53
1 files changed, 27 insertions, 26 deletions
diff --git a/public/common/client.js b/public/common/client.js
index 1b45cf8..393eb0a 100644
--- a/public/common/client.js
+++ b/public/common/client.js
@@ -120,30 +120,15 @@ function drag_element_with_mouse(element_sel, grabber_sel) {
/* TITLE BLINKER */
-let blink_title = document.title
-let blink_timer = 0
-
-function start_blinker(message) {
- let tick = false
- if (blink_timer)
- stop_blinker()
- if (!document.hasFocus()) {
- document.title = message
- blink_timer = setInterval(function () {
- document.title = tick ? message : blink_title
- tick = !tick
- }, 1000)
- }
-}
+var game_title = document.title
-function stop_blinker() {
- document.title = blink_title
- clearInterval(blink_timer)
- blink_timer = 0
+function update_title() {
+ if (is_your_turn || (chat && chat.has_unread))
+ document.title = "\u2bc8 " + game_title
+ else
+ document.title = game_title
}
-window.addEventListener("focus", stop_blinker)
-
/* CHAT */
let chat = null
@@ -245,16 +230,22 @@ function fetch_chat() {
function update_chat_new() {
let button = document.getElementById("chat_button")
- start_blinker("NEW MESSAGE")
- if (chat && chat.is_visible)
+ if (chat && chat.is_visible) {
+ if (!document.hasFocus())
+ chat.has_unread = true
fetch_chat()
- else
+ } else {
+ chat.has_unread = true
button.classList.add("new")
+ }
+ update_title()
}
function update_chat_old() {
let button = document.getElementById("chat_button")
document.getElementById("chat_button").classList.remove("new")
+ chat.has_unread = false
+ update_title()
}
function show_chat() {
@@ -264,6 +255,10 @@ function show_chat() {
document.getElementById("chat_input").focus()
chat.is_visible = true
fetch_chat()
+ if (chat.has_unread) {
+ chat.has_unread = false
+ update_title()
+ }
}
}
@@ -282,6 +277,13 @@ function toggle_chat() {
show_chat()
}
+window.addEventListener("focus", function () {
+ if (chat && chat.is_visible && chat.has_unread) {
+ chat.has_unread = false
+ update_title()
+ }
+})
+
/* NOTEPAD */
let notepad = null
@@ -593,14 +595,13 @@ function on_update_header() {
document.querySelector("header").classList.remove("replay")
if (view.actions) {
document.querySelector("header").classList.add("your_turn")
- if (!is_your_turn || old_active !== view.active)
- start_blinker("YOUR TURN")
is_your_turn = true
} else {
document.querySelector("header").classList.remove("your_turn")
is_your_turn = false
}
old_active = view.active
+ update_title()
}
function on_update_roles() {