From 82a487d3dd13a963857730e4357d19bd50250dc2 Mon Sep 17 00:00:00 2001 From: Tristan Schneider Date: Sun, 28 Jan 2024 16:49:53 +0100 Subject: [PATCH] handle span colour when there are fewer spans than users --- owe.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/owe.js b/owe.js index 9d2712f..e335b24 100644 --- a/owe.js +++ b/owe.js @@ -31,11 +31,14 @@ function loadSentences(alertIfNew = false, increaseUnread = true) { // color var spans = document.querySelector(".sentences").getElementsByTagName("span"); - // we expect this to be from the user who's turn it is now - var histurnspan = spans[spans.length - config_data.users.length]; - //console.log(histurnspan.getAttribute("style")); - document.getElementById("wordinput").setAttribute("style", histurnspan.getAttribute("style")); + if (spans.length >= config_data.users.length) { + var histurnspan = spans[spans.length - config_data.users.length]; + //console.log(histurnspan.getAttribute("style")); + document.getElementById("wordinput").setAttribute("style", histurnspan.getAttribute("style")); + } else { + console.error('Not enough spans available for users.'); + } initializeLoginArea(); }); });