From 3371ae0b738c387aaa7d641f785207889afbcc23 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 25 Feb 2023 14:09:27 +0100 Subject: Make user name and player presence lists more robust. Cope with special characters like + etc. --- public/common/play.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'public') diff --git a/public/common/play.js b/public/common/play.js index 964889b..77fcaab 100644 --- a/public/common/play.js +++ b/public/common/play.js @@ -375,9 +375,8 @@ function on_game_over() { function init_player_names(players) { for (let i = 0; i < roles.length; ++i) { - let sel = "#" + roles[i].id + " .role_user" let p = players.find(p => p.role === roles[i].role) - document.querySelector(sel).textContent = p ? p.name : "NONE" + document.getElementById(roles[i].id).querySelector(".role_user").textContent = p ? p.name : "NONE" } } @@ -460,12 +459,10 @@ function connect_play() { break case 'presence': + let list = Array.isArray(arg) ? arg : Object.keys(arg) for (let i = 0; i < roles.length; ++i) { let elt = document.getElementById(roles[i].id) - if (roles[i].role in arg) - elt.classList.add("present") - else - elt.classList.remove("present") + elt.classList.toggle("present", list.includes(roles[i].role)) } break -- cgit v1.2.3