const ItemID = window.location.pathname.split('/')[2] const UserID = JSON.parse(window.localStorage.getItem('p+account_info')).ID const ItemGrid = document.getElementById('assets') const Categories = document.getElementById('store-categories').children[0] var Settings; var Inventory = null; var Utilities; let EventItemsShown = false chrome.storage.sync.get(['PolyPlus_Settings'], async function(result){ Settings = result.PolyPlus_Settings || {}; Utilities = await import(chrome.runtime.getURL('resources/utils.js')); Utilities = Utilities.default if (Settings.IRLPriceWithCurrency.Enabled === true) { Array.from(ItemGrid.children).forEach(element => { LoadIRLPrices(element) }); } if (Settings.StoreOwnTagOn === true) { Inventory = (await (await fetch('https://api.polytoria.com/v1/users/' + UserID + '/inventory?type=hat&limit=100')).json()).inventory Inventory.concat(await (await fetch('https://api.polytoria.com/v1/users/' + UserID + '/inventory?type=face&limit=100')).json()).inventory Inventory.concat(await (await fetch('https://api.polytoria.com/v1/users/' + UserID + '/inventory?type=tool&limit=100')).json()).inventory console.log(Inventory) Array.from(ItemGrid.children).forEach(element => { LoadOwnedTags(element) }); } if (Settings.EventItemsCatOn === true) { EventItems() } }); const observer = new MutationObserver(async function (list){ if (Settings.EventItemsCatOn === true) { if (document.getElementById('event-items-pagination') === null) { ItemGrid.classList.add('itemgrid') ItemGrid.parentElement.classList.remove('col-lg-9') document.getElementById('pagination').style.display = 'block' if (document.getElementById('storecat-eventitems') !== null) { document.getElementById('storecat-eventitems').checked = false } } else { ItemGrid.classList.remove('itemgrid') ItemGrid.parentElement.classList.add('col-lg-9') document.getElementById('pagination').style.display = 'none' } } for (const record of list) { for (const element of record.addedNodes) { if (element.tagName === "DIV" && element.classList.value === 'mb-3 itemCardCont') { if (Settings.IRLPriceWithCurrency.Enabled === true) { LoadIRLPrices(element) } if (Settings.StoreOwnTagOn === true && Inventory !== null) { LoadOwnedTags(element) } } } observer.observe(ItemGrid, {attributes: false,childList: true,subtree: false}); } }); observer.observe(ItemGrid, {attributes: false,childList: true,subtree: false}); async function LoadIRLPrices(element) { if (element.tagName != "DIV" || element.querySelector('small.text-primary')) {return} const Parent = element.getElementsByTagName('small')[1] if (Parent.innerText !== "") { const Span = document.createElement('span') Span.classList = 'text-muted polyplus-price-tag' Span.style = 'font-size: 0.7rem; font-weight: lighter;' const Price = Parent.innerText.split(' ')[1] const IRLResult = await Utilities.CalculateIRL(Price, Settings.IRLPriceWithCurrency.Currency) Span.innerText = "($" + IRLResult.result + " " + IRLResult.display + ")" Parent.appendChild(Span) } } function LoadOwnedTags(element) { let Item = CheckInventory(parseInt(element.querySelector('[href^="/store/"]').getAttribute('href').split('/')[2])) if (Item !== null) { const Tag = document.createElement('span') Tag.classList = `badge ${ (Item.asset.isLimited === false) ? 'bg-primary' : 'bg-warning' } polyplus-own-tag` Tag.style = 'position: absolute;font-size: 0.9rem;top: 0px;left: 0px;padding: 5.5px;border-top-left-radius: var(--bs-border-radius-lg)!important;border-top-right-radius: 0px;border-bottom-left-radius: 0px;font-size: 0.65rem;' Tag.innerHTML = "" element.getElementsByTagName('img')[0].parentElement.appendChild(Tag) if (Item.asset.isLimited === true) { Tag.setAttribute('data-bs-toggle', 'tooltip') Tag.setAttribute('data-bs-title', '#' + Item.serial) Utilities.InjectResource('registerTooltips') } } } function CheckInventory(id) { let Item = null Inventory.forEach(element => { if (element.asset.id === id) { Item = element } }) return Item } function EventItems() { const Selector = document.createElement('div') Selector.classList = 'form-check store-category-check fw-bold' Selector.style.borderColor = '#B008B0' Selector.innerHTML = ` ` Categories.appendChild(Selector) let EventData = null let Events = [] let Groups = [] let Page = 0 Selector.children[0].addEventListener('click', async function() { Array.from(Categories.children).forEach(selector => { selector.classList.remove('active') }) Selector.classList.add('active') if (EventData === null) { EventData = await (await fetch('https://polyplus.vercel.app/data/eventItems.json')).json() Object.values(EventData.eventDetails).forEach((x, index) => {Events.push({ ...x, items: EventData.items.filter((x) => x.event === Object.keys(EventData.eventDetails)[index]).sort((a, b) => a.id - b.id) })}) while (Events.length > 0) { Groups.push(Events.splice(0, 5)) } } ItemGrid.classList.remove('itemgrid') ItemGrid.innerHTML = `