minor: change LOVE valuation to use website API
temp disabled
This commit is contained in:
parent
5fc1c37383
commit
0e3be312a8
2 changed files with 143 additions and 0 deletions
|
|
@ -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 = `
|
||||
<div class="mb-1">
|
||||
<b class="text-success">
|
||||
<i class="pi pi-brick" style="width:1.2em"></i>
|
||||
Value
|
||||
</b>
|
||||
<span class="float-end">
|
||||
${valuation.value}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<b class="text-primary"">
|
||||
<i class="pi" style="width:1.2em">%</i>
|
||||
Trend
|
||||
</b>
|
||||
<span class="float-end">
|
||||
${valuation.trend}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<b>
|
||||
<i class="fa-duotone fa-triangle" style="width:1.2em"></i>
|
||||
Valuation Type
|
||||
</b>
|
||||
<span class="float-end">
|
||||
${valuation.type}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<b>
|
||||
<i class="fa-duotone fa-hand-wave" style="width:1.2em"></i>
|
||||
Shorthand
|
||||
</b>
|
||||
<span class="float-end">
|
||||
${valuation.short}
|
||||
</span>
|
||||
</div>
|
||||
<div class="d-flex" style="gap: 5px;">
|
||||
${ ValueDetails.tags.map((x) => `
|
||||
<span class="badge bg-${ GetTagColor(x) }">${x}</span>
|
||||
`).join('')}
|
||||
</div>
|
||||
`
|
||||
} else {
|
||||
ValueCard.innerHTML = `
|
||||
There is no evaluation for this item at this time.
|
||||
`
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = `
|
||||
<h6 class="section-title mt-3 mt-lg-0 mb-3 px-2">
|
||||
Valuation <a href="https://docs.google.com/document/d/1W7JN74MU-9Dbd-9xNnjxE18hQVBPXWuwjK5DGSnuQR4/" target="_blank">(based off LOVE)</a>
|
||||
</h6>
|
||||
<div class="card" id="p+valuation_card">
|
||||
<div class="card-body">
|
||||
<small class="d-block text-center text-muted" style="font-size: 0.8rem;">
|
||||
Loading...
|
||||
</small>
|
||||
<lottie-player id="avatar-loading" src="https://c0.ptacdn.com/static/images/lottie/poly-brick-loading.2b51aa85.json" background="transparent" speed="1" style="width: 20%;height: auto;margin: -16px auto 50px;margin-top: 0px;" loop="" autoplay=""></lottie-player>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
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');
|
||||
|
||||
|
|
|
|||
Reference in a new issue