diff --git a/js/background.js b/js/background.js index 1b0a584..49548b3 100755 --- a/js/background.js +++ b/js/background.js @@ -334,6 +334,104 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { } }, 5000); }) + } else if (request.action == "item_valuation") { + chrome.storage.local.get(['PolyPlus_ItemValuationData'], async function(result){ + const Cache = (result['PolyPlus_ItemValuationData']||{[request.itemID]:undefined}) + + // cache for 5 minutes + if (Cache[request.itemID] === undefined || (new Date().getTime() - Cache[request.itemID].requested > 300000)) { + let ValueDetails = (await (await fetch('https://polytoria.trade/api/trpc/getItem?batch=1&input={"0":' + request.itemID + '}',{mode:'no-cors'})).json()) + if (ValueDetails.result.length > 0) { + ValueDetails = ValueDetails[0].result.data + } + Cache[request.itemID] = { + data: ValueDetails, + requested: new Date().getTime() + } + + chrome.storage.local.set({['PolyPlus_GreatDivideStats']: Cache}, function(){}) + } + + chrome.tabs.query({ active: true, currentWindow: true }, function(tabs){ + chrome.scripting + .executeScript({ + target: {tabId: tabs[0].id}, + func: LoadValuation, + args: [Cache[request.itemID].data] + }) + }) + }) + + const LoadValuation = async function(valuation) { + const GetTagColor = function(label) { + if (TagColors[label] !== undefined) { + return TagColors[label] + } else if (TagColors[label.substring(1)] !== undefined) { + return TagColors[label.substring(1)] + } else { + return 'dark' + } + } + + const TagColors = { + "Projected": "warning", + "Hoarded": "success", + "Rare": "primary", + "Freaky": "danger" + } + + //const ValueDetails = (await (await fetch('https://polytoria.trade/api/trpc/getItem?batch=1&input={"0":' + ItemID + '}')).json()) + + if (valuation !== undefined) { + ValueCard.innerHTML = ` +
+ + + Value + + + ${valuation.value} + +
+
+ + % + Trend + + + ${valuation.trend} + +
+
+ + + Valuation Type + + + ${valuation.type} + +
+
+ + + Shorthand + + + ${valuation.short} + +
+
+ ${ ValueDetails.tags.map((x) => ` + ${x} + `).join('')} +
+ ` + } else { + ValueCard.innerHTML = ` + There is no evaluation for this item at this time. + ` + } + } } }); diff --git a/js/store/item-view.js b/js/store/item-view.js index d347f2f..8b5f82e 100755 --- a/js/store/item-view.js +++ b/js/store/item-view.js @@ -756,6 +756,51 @@ function CheckOwner() { }); } +async function ValueListDataNew() { + let Tabs = document.getElementById('store-tabs'); + + const ValueSection = document.createElement('div') + ValueSection.classList = 'mb-3' + ValueSection.innerHTML = ` +
+ Valuation (based off LOVE) +
+
+
+ + Loading... + + +
+
+ ` + Tabs.parentElement.insertBefore(ValueSection, Tabs) + + const ValueCard = document.getElementById('p+valuation_card').children[0] + + const TagColors = { + "Projected": "warning", + "Hoarded": "success", + "Rare": "primary", + "Freaky": "danger" + } + + const GetTagColor = function(label) { + if (TagColors[label] !== undefined) { + return TagColors[label] + } else if (TagColors[label.substring(1)] !== undefined) { + return TagColors[label.substring(1)] + } else { + return 'dark' + } + } + + await chrome.runtime.sendMessage({ + action: "item_valuation", + itemID: ItemID + }); +} + async function ValueListData() { let Tabs = document.getElementById('store-tabs');