From d0a2223e76924be146d66cecddf46d0478aa3af1 Mon Sep 17 00:00:00 2001 From: Index Date: Mon, 8 Jul 2024 19:13:10 -0500 Subject: [PATCH] feat: "Hoarded Items" card on collectibles inv tab --- js/account/inventory.js | 48 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/js/account/inventory.js b/js/account/inventory.js index 2766fdb..59ac829 100755 --- a/js/account/inventory.js +++ b/js/account/inventory.js @@ -6,6 +6,8 @@ Username = window.location.pathname.split('/')[2]; let UserID; let ItemGrid; +let _Utilities; + if (window.location.pathname.split('/')[3] === 'inventory') { !(async () => { UserID = (await (await fetch('https://api.polytoria.com/v1/users/find?username=' + Username )).json()).id; @@ -14,7 +16,10 @@ if (window.location.pathname.split('/')[3] === 'inventory') { /* Rewritten item wishlist function will take in the data with a parameter instead */ - chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ + chrome.storage.sync.get(['PolyPlus_Settings'], async function(result){ + _Utilities = await import(chrome.runtime.getURL('resources/utils.js')); + _Utilities = _Utilities.default + Settings = result.PolyPlus_Settings const Nav = document.getElementsByClassName('nav-pills')[0]; @@ -67,6 +72,19 @@ if (window.location.pathname.split('/')[3] === 'inventory') { }); CollectibleNav.children[0].classList.add('active'); + let HoardedCard = document.createElement('li'); + HoardedCard.classList.add('nav-item'); + HoardedCard.classList.add('text-center'); + HoardedCard.innerHTML = ` +
+ Hoarded Items +
+
+
+
+ `; + Nav.appendChild(HoardedCard); + CollectibleCategory() } } @@ -276,8 +294,14 @@ async function CollectibleCategory() { } } + const ItemMultiples = [] Collectibles.forEach(item => { - item = item + const Multiple = ItemMultiples.findIndex((x) => x.asset.id === item.asset.id) + if (Multiple !== -1) { + ItemMultiples[Multiple].copies++ + ItemMultiples[Multiple].serials.push(item.serial) + } else { ItemMultiples.push({asset: item.asset, copies: 1, serials: [item.serial]}) } + const ItemColumn = document.createElement('div') ItemColumn.classList = 'px-0' ItemColumn.innerHTML = ` @@ -305,4 +329,24 @@ async function CollectibleCategory() { ` ItemGrid.appendChild(ItemColumn) }) + + const Hoarded = ItemMultiples.filter((x) => x.copies > 1) + + const HoardedCard = document.getElementById('p+hoarded_card') + Hoarded.forEach(item => { + const ListElement = document.createElement('div') + ListElement.classList = 'mb-1 mb-2' + ListElement.innerHTML = ` + + ${item.asset.name} + +
+ + ${item.copies} copies + + ` + HoardedCard.appendChild(ListElement) + }) + + _Utilities.InjectResource("registerTooltips") } \ No newline at end of file