From 04fb6518809b92edfb85d1ba215cacd2754ac76c Mon Sep 17 00:00:00 2001 From: peshomir Date: Thu, 7 Mar 2024 13:56:42 +0000 Subject: [PATCH] deploy: 5c934ce8fb7f5e336ab9f483833d797dadca01d5 --- fx_core.js | 33 +++++++++++++++++++++++---------- index.html | 10 +++++----- main.css | 11 +++++++++++ 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/fx_core.js b/fx_core.js index 59755ad..9065a71 100644 --- a/fx_core.js +++ b/fx_core.js @@ -1,5 +1,6 @@ -const fx_version = '0.6.1.8'; // FX Client Version -const fx_update = 'Mar 5'; // FX Client Last Updated +const dictionary = {"gIsSingleplayer":"j1","gIsTeamGame":"ha","playerId":"eu","playerNames":"k5","playerBalances":"ev","playerTerritories":"fP","uiOffset":"nf"}; +const fx_version = '0.6.1.9'; // FX Client Version +const fx_update = 'Mar 7'; // FX Client Last Updated if (localStorage.getItem("fx_winCount") == undefined || localStorage.getItem("fx_winCount") == null) { var wins_counter = 0; @@ -8,6 +9,13 @@ if (localStorage.getItem("fx_winCount") == undefined || localStorage.getItem("fx var wins_counter = localStorage.getItem("fx_winCount"); } +const getVar = varName => window[dictionary[varName]]; + +// https://stackoverflow.com/a/6234804 +function escapeHtml(unsafe) { + return unsafe.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); +} + function KeybindsInput(containerElement) { this.container = containerElement; this.keys = [ "key", "type", "value" ]; @@ -216,7 +224,7 @@ WindowManager.add({ beforeOpen: function() {} }); document.getElementById("canvasA").addEventListener("mousedown", WindowManager.closeAll); -document.getElementById("canvasA").addEventListener("touchstart", WindowManager.closeAll); +document.getElementById("canvasA").addEventListener("touchstart", WindowManager.closeAll, { passive: true }); document.addEventListener("keydown", event => { if (event.key === "Escape") WindowManager.closeAll(); }); var settingsGearIcon = document.createElement('img'); settingsGearIcon.setAttribute('src', 'assets/geari_white.png'); @@ -224,12 +232,18 @@ settingsGearIcon.setAttribute('src', 'assets/geari_white.png'); const playerList = new (function () { const playersIcon = document.createElement('img'); playersIcon.setAttribute('src', 'assets/players_icon.png'); + document.getElementById("playerlist_content").addEventListener("click", event => { + const playerId = event.target.closest("tr[data-player-id]")?.getAttribute("data-player-id"); + if (!playerId) return; + if (getVar("gIsTeamGame")) WindowManager.closeWindow("playerList"), displayDonationsHistory(playerId); + }); this.display = function displayPlayerList(playerNames) { let listContent = ""; for (let i = 0; i < playerNames.length; i++) { - listContent += `${i}. ${playerNames[i]}
` + listContent += `${i}. ${escapeHtml(playerNames[i])}` } - document.getElementById("playerlist_text").innerHTML = listContent; + document.getElementById("playerlist_content").innerHTML = listContent; + document.getElementById("playerlist_content").setAttribute("class", getVar("gIsTeamGame") ? "clickable" : ""); WindowManager.openWindow("playerList"); } this.hoveringOverButton = false; @@ -260,19 +274,18 @@ var donationsTracker = new (function(){ }; this.reset = function() { for (var i = 0; i < 512; i++) this.donationHistory[i] = []; }; }); -// usage from inside: displayDonationsHistory(Y, gE); -function displayDonationsHistory(playerID, playerNames, isSingleplayer) { +function displayDonationsHistory(playerID, playerNames = getVar("playerNames"), isSingleplayer = getVar("gIsSingleplayer")) { var history = donationsTracker.getRecipientHistoryOf(playerID); console.log("History for " + playerNames[playerID] + ":"); console.log(history); - document.querySelector("#donationhistory h1").innerHTML = "Donation history for " + playerNames[playerID]; + document.querySelector("#donationhistory h1").innerHTML = "Donation history for " + escapeHtml(playerNames[playerID]); var historyText = ""; history.reverse(); if (history.length > 0) history.forEach(function(historyItem, index) { historyText += `${(history.length - index)}. `; if (playerID === historyItem[1]) - historyText += `Received ${historyItem[2]} resources from ${playerNames[historyItem[0]]}
`; - else historyText += `Sent ${historyItem[2]} resources to ${playerNames[historyItem[1]]}
`; + historyText += `Received ${historyItem[2]} resources from ${escapeHtml(playerNames[historyItem[0]])}
`; + else historyText += `Sent ${historyItem[2]} resources to ${escapeHtml(playerNames[historyItem[1]])}
`; }); else historyText = "Nothing to display"; document.querySelector("#donationhistory p#donationhistory_text").innerHTML = historyText; diff --git a/index.html b/index.html index 8a0354b..f4c1d52 100644 --- a/index.html +++ b/index.html @@ -34,7 +34,7 @@ - +