From 70c9a5013d661e3969f1f963dd246cce215d86b7 Mon Sep 17 00:00:00 2001 From: Sainan Date: Mon, 6 May 2024 15:14:09 +0200 Subject: [PATCH] feat(webui): add list of owned warframes & weapons with "Make Rank 30" option (#170) --- src/controllers/api/loginController.ts | 2 +- static/webui/index.html | 44 +++++---- static/webui/script.js | 119 +++++++++++++++++++++---- 3 files changed, 130 insertions(+), 35 deletions(-) diff --git a/src/controllers/api/loginController.ts b/src/controllers/api/loginController.ts index 7dbef077..4cd7f6ef 100644 --- a/src/controllers/api/loginController.ts +++ b/src/controllers/api/loginController.ts @@ -18,7 +18,7 @@ const loginController: RequestHandler = async (request, response) => { const account = await Account.findOne({ email: loginRequest.email }); //{ _id: 0, __v: 0 } - if (!account && config.autoCreateAccount) { + if (!account && config.autoCreateAccount && loginRequest.ClientType != "webui") { try { const newAccount = await createAccount({ email: loginRequest.email, 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 6446c62c..52ff2ce3 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -15,7 +15,7 @@ function loginFromLocalStorage() { s: "W0RFXVN0ZXZlIGxpa2VzIGJpZyBidXR0cw==", // signature of some kind lang: "en", date: 1501230947855458660, // ??? - ClientType: "", + ClientType: "webui", PS: "W0RFXVN0ZXZlIGxpa2VzIGJpZyBidXR0cw==" // anti-cheat data }) }); @@ -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")) @@ -64,7 +129,7 @@ function getKey(input) { function doAcquireWarframe() { const uniqueName = getKey(document.getElementById("warframe-to-acquire")); if (!uniqueName) { - $("#warframe-to-acquire").addClass("is-invalid"); + $("#warframe-to-acquire").addClass("is-invalid").focus(); return; } const req = $.post({ @@ -77,7 +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(); }); } @@ -88,7 +154,7 @@ $("#warframe-to-acquire").on("input", () => { function doAcquireWeapon() { const uniqueName = getKey(document.getElementById("weapon-to-acquire")); if (!uniqueName) { - $("#weapon-to-acquire").addClass("is-invalid"); + $("#weapon-to-acquire").addClass("is-invalid").focus(); return; } const req = $.post({ @@ -101,10 +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(); + }); +}