diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-06-19 02:02:40 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2021-06-24 14:44:14 +0200 |
commit | 68d2a6dfae86a71c8ee5d813931ff9b9def06939 (patch) | |
tree | eeb1c64cfd89a552f2f2ec1bdbba321e97eab7a1 /public | |
parent | 7828eadaf862b6a75cb85fafcdd2d5f3b803702d (diff) | |
download | server-68d2a6dfae86a71c8ee5d813931ff9b9def06939.tar.gz |
Add YOUR TURN title bar blinker.
Diffstat (limited to 'public')
-rw-r--r-- | public/common/client.js | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/public/common/client.js b/public/common/client.js index fdbc540..4aea900 100644 --- a/public/common/client.js +++ b/public/common/client.js @@ -73,6 +73,29 @@ function drag_element_with_mouse(element_sel, grabber_sel) { grabber.addEventListener('mousedown', md); } +/* YOUR TURN BLINKER */ + +let is_your_turn = false; +let your_turn_timer = 0; +let your_turn_title = document.title; + +function start_your_turn_blinker() { + let tick = true; + if (!document.hasFocus()) { + your_turn_timer = setInterval(function () { + document.title = tick ? "YOUR TURN" : your_turn_title; + tick = !tick; + }, 1000); + } +} + +function stop_your_turn_blinker() { + document.title = your_turn_title; + clearInterval(your_turn_timer); +} + +window.addEventListener("focus", stop_your_turn_blinker); + function add_chat_lines(log) { function format_time(date) { let mm = date.getMinutes(); @@ -273,10 +296,16 @@ function init_client(roles) { function on_update_bar() { document.getElementById("prompt").textContent = game.prompt; - if (game.actions) + if (game.actions) { document.querySelector(".grid_top").classList.add("your_turn"); - else + if (!is_your_turn) + start_your_turn_blinker(); + is_your_turn = true; + } else { document.querySelector(".grid_top").classList.remove("your_turn"); + stop_your_turn_blinker(); + is_your_turn = false; + } } function on_update_log() { |