From be5ff6ba9fb895b08c257cc1c5e849a680a95543 Mon Sep 17 00:00:00 2001 From: Sainan Date: Mon, 6 May 2024 13:23:01 +0200 Subject: [PATCH] feat(webui): add list of owned warframes & weapons with "Make Rank 30" option --- static/webui/index.html | 44 +++++++++------- static/webui/script.js | 111 +++++++++++++++++++++++++++++++++++----- 2 files changed, 124 insertions(+), 31 deletions(-) diff --git a/static/webui/index.html b/static/webui/index.html index 1df68c71..ea91f01b 100644 --- a/static/webui/index.html +++ b/static/webui/index.html @@ -26,28 +26,34 @@

Hello, ! Logout

-
-
-
Acquire Warframe
-
-
- +
+
+
+
Warframes
+
+ + +
+ + + +
-
- -
- +
-
-
Acquire Weapon
-
-
- +
+
+
Weapons
+
+ + +
+ + + +
-
- -
- +
diff --git a/static/webui/script.js b/static/webui/script.js index df8fdf03..52ff2ce3 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -24,6 +24,7 @@ function loginFromLocalStorage() { $("#main-view").removeClass("d-none"); $(".displayname").text(data.DisplayName); window.accountId = data.id; + updateInventory(); }); req.fail(() => { logout(); @@ -42,18 +43,82 @@ if (localStorage.getItem("email") && localStorage.getItem("password")) { loginFromLocalStorage(); } -const req = $.get("/custom/getItemLists"); -req.done(data => { - for (const [type, items] of Object.entries(data)) { - items.forEach(item => { - const option = document.createElement("option"); - option.setAttribute("data-key", item.uniqueName); - option.value = item.name; - document.getElementById("datalist-" + type).appendChild(option); - }); - } +window.itemListPromise = new Promise(resolve => { + const req = $.get("/custom/getItemLists"); + req.done(data => { + const itemMap = {}; + for (const [type, items] of Object.entries(data)) { + items.forEach(item => { + const option = document.createElement("option"); + option.setAttribute("data-key", item.uniqueName); + option.value = item.name; + document.getElementById("datalist-" + type).appendChild(option); + itemMap[item.uniqueName] = { ...item, type }; + }); + } + resolve(itemMap); + }); }); +function updateInventory() { + const req = $.get("/api/inventory.php?accountId=" + window.accountId); + req.done(data => { + window.itemListPromise.then(itemMap => { + document.getElementById("warframe-list").innerHTML = ""; + data.Suits.forEach(item => { + const tr = document.createElement("tr"); + { + const td = document.createElement("td"); + td.textContent = itemMap[item.ItemType].name; + tr.appendChild(td); + } + { + const td = document.createElement("td"); + td.classList = "text-end"; + if (item.XP < 1_600_000) { + const a = document.createElement("a"); + a.href = "#"; + a.onclick = function () { + addGearExp("Suits", item.ItemId.$oid, 1_600_000 - item.XP); + }; + a.textContent = "Make Rank 30"; + td.appendChild(a); + } + tr.appendChild(td); + } + document.getElementById("warframe-list").appendChild(tr); + }); + + document.getElementById("weapon-list").innerHTML = ""; + ["LongGuns", "Pistols", "Melee"].forEach(category => { + data[category].forEach(item => { + const tr = document.createElement("tr"); + { + const td = document.createElement("td"); + td.textContent = itemMap[item.ItemType].name; + tr.appendChild(td); + } + { + const td = document.createElement("td"); + td.classList = "text-end"; + if (item.XP < 800_000) { + const a = document.createElement("a"); + a.href = "#"; + a.onclick = function () { + addGearExp(category, item.ItemId.$oid, 800_000 - item.XP); + }; + a.textContent = "Make Rank 30"; + td.appendChild(a); + } + tr.appendChild(td); + } + document.getElementById("weapon-list").appendChild(tr); + }); + }); + }); + }); +} + function getKey(input) { return document .getElementById(input.getAttribute("list")) @@ -77,8 +142,8 @@ function doAcquireWarframe() { }) }); req.done(() => { - alert("Warframe added to your inventory! Visit navigation to force an inventory update."); document.getElementById("warframe-to-acquire").value = ""; + updateInventory(); }); } @@ -102,11 +167,33 @@ function doAcquireWeapon() { }) }); req.done(() => { - alert("Weapon added to your inventory! Visit navigation to force an inventory update."); document.getElementById("weapon-to-acquire").value = ""; + updateInventory(); }); } $("#weapon-to-acquire").on("input", () => { $("#weapon-to-acquire").removeClass("is-invalid"); }); + +function addGearExp(category, oid, xp) { + const data = { + Missions: { + Tag: "SolNode0", + Completes: 0 + } + }; + data[category] = [ + { + ItemId: { $oid: oid }, + XP: xp + } + ]; + $.post({ + url: "/api/missionInventoryUpdate.php?accountId=" + window.accountId, + contentType: "text/plain", + data: JSON.stringify(data) + }).done(function () { + updateInventory(); + }); +}