diff --git a/js/pages/playerInfo.js b/js/pages/playerInfo.js index 87cd134..84f096b 100644 --- a/js/pages/playerInfo.js +++ b/js/pages/playerInfo.js @@ -40,19 +40,25 @@ function PlayerInfoPage(params, container) { function refresh() { Rcon.getPlayers(function (players) { + // Guard against navigation away while waiting for RCON response + var nf = document.getElementById('pi-notfound'); + var fields = document.getElementById('pi-fields'); + var actions = document.getElementById('pi-actions'); + if (!nf || !fields || !actions) return; + var info = null; for (var i = 0; i < players.length; i++) { if (String(players[i].SteamID) === userid) { info = players[i]; break; } } if (!info) { - document.getElementById('pi-notfound').style.display = 'block'; - document.getElementById('pi-fields').innerHTML = ''; - document.getElementById('pi-actions').style.display = 'none'; + nf.style.display = 'block'; + fields.innerHTML = ''; + actions.style.display = 'none'; return; } - document.getElementById('pi-notfound').style.display = 'none'; - document.getElementById('pi-actions').style.display = 'block'; + nf.style.display = 'none'; + actions.style.display = 'block'; // Fix known Rust RCON quirk: VoiationLevel → ViolationLevel if (info.VoiationLevel !== undefined) { @@ -64,7 +70,8 @@ function PlayerInfoPage(params, container) { delete info.CurrentLevel; delete info.UnspentXp; - document.getElementById('pi-username').textContent = info.DisplayName || userid; + var un = document.getElementById('pi-username'); + if (un) un.textContent = info.DisplayName || userid; var fieldsHtml = ''; for (var key in info) { @@ -79,7 +86,7 @@ function PlayerInfoPage(params, container) { fieldsHtml += '
' + key + ': ' + value + '