summaryrefslogtreecommitdiff
path: root/public/common/client.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/common/client.js')
-rw-r--r--public/common/client.js83
1 files changed, 37 insertions, 46 deletions
diff --git a/public/common/client.js b/public/common/client.js
index 3bc8aff..f8a5e23 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
@@ -359,9 +361,9 @@ function toggle_notepad() {
show_notepad()
}
-/* REMATCH & REPLAY BUTTONS WHEN GAME OVER */
+/* REMATCH & REPLAY BUTTONS WHEN GAME IS FINISHED */
-function on_game_over() {
+function on_finished() {
remove_resign_menu()
add_icon_button(1, "replay_button", "sherlock-holmes-mirror",
@@ -545,8 +547,10 @@ function connect_play() {
if (typeof on_update === "function")
on_update()
on_update_log(view.log_start, game_log.length)
- if (view.game_over)
- on_game_over()
+ break
+
+ case "finished":
+ on_finished()
break
case "snapsize":
@@ -567,10 +571,6 @@ function connect_play() {
if (typeof on_reply === "function")
on_reply(arg[0], arg[1])
break
-
- case "save":
- window.localStorage[params.title_id + "/save"] = arg
- break
}
}
}
@@ -578,7 +578,6 @@ function connect_play() {
/* HEADER */
let is_your_turn = false
-let old_active = null
function on_update_header() {
if (typeof on_prompt === "function")
@@ -593,20 +592,20 @@ 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() {
if (view.active !== undefined)
for (let role in roles)
- roles[role].element.classList.toggle("active", view.active === role)
+ roles[role].element.classList.toggle("active",
+ view.active === role || view.active === "Both" || view.active.includes(role)
+ )
}
/* LOG */
@@ -742,14 +741,6 @@ function send_query(q, param) {
send_message("query", [ q, param ])
}
-function send_save() {
- send_message("save")
-}
-
-function send_restore() {
- send_message("restore", window.localStorage[params.title_id + "/save"])
-}
-
/* REPLAY */
function init_replay() {
@@ -766,7 +757,7 @@ function confirm_resign() {
}
function add_resign_menu() {
- if (Object.keys(roles).length > 1) {
+ if (Object.keys(roles).length === 2) {
let popup = document.querySelector("#toolbar details menu")
popup.insertAdjacentHTML("beforeend", '<li class="resign separator">')
popup.insertAdjacentHTML("beforeend", '<li class="resign" onclick="confirm_resign()">Resign')