From 68d2a6dfae86a71c8ee5d813931ff9b9def06939 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 19 Jun 2021 02:02:40 +0200 Subject: Add YOUR TURN title bar blinker. --- public/common/client.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'public') 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() { -- cgit v1.2.3