feat: "Trade Valuation" feature (thanks to LOVE)

This commit is contained in:
Index 2024-09-29 14:57:57 -05:00
parent 849e2dde84
commit 12e3a38e8d
6 changed files with 137 additions and 6 deletions

View file

@ -0,0 +1,106 @@
var Settings;
var Utilities;
(async () => {
Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
Utilities = Utilities.default;
chrome.storage.sync.get(['PolyPlus_Settings'], async function(result){
Settings = result.PolyPlus_Settings
if (
Settings.ValueListInfo &&
Settings.ValueListInfo.Enabled == true &&
Settings.ValueListInfo.TradeValuation == true
) {
const ColumnLabels = [
"name",
"short",
"value",
"type",
"trend",
"demand",
"tags"
]
const TagColors = {
"Projected": "warning",
"Hoarded": "success",
"Rare": "primary",
"Freaky": "danger"
}
/*
Table to JSON function (slightly modified for my use-case)
https://stackoverflow.com/questions/9927126/how-to-convert-the-following-table-to-json-with-javascript#answer-60196347
*/
const ExtractTableJSON = function(table) {
var data = [];
for (var i = 1; i < table.rows.length; i++) {
var tableRow = table.rows[i];
var rowData = {
tags: []
};
for (var j = 0; j < tableRow.cells.length; j++) {
let Value = tableRow.cells[j].children[0].children[0].innerText;
if (ColumnLabels[j] === "name") {
const LinkValue = tableRow.cells[j].getElementsByTagName('a')[0]
if (LinkValue) {
rowData.id = LinkValue.href.split('https://www.google.com/url?q=')[1].split('&')[0].split('/')[4]
}
}
if (ColumnLabels[j] === "tags") {
Array.from(tableRow.cells[j].children).forEach(tag => {
/*
The regex for the emoji character codes replacement was made by AI, such a time saver lol
*/
rowData.tags.push(tag.children[0].innerHTML.replace(/\s/g,'').replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, ''))
})
} else {
rowData[ColumnLabels[j]] = Value
}
}
data.push(rowData);
}
return data;
}
const ValueListDocument = new DOMParser().parseFromString(await (await fetch('https://docs.google.com/feeds/download/documents/Export?exportFormat=html&format=html&id=1W7JN74MU-9Dbd-9xNnjxE18hQVBPXWuwjK5DGSnuQR4')).text(), 'text/html')
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 ValueJSON = ExtractTableJSON(ValueListDocument.getElementsByTagName('table')[0])
for (let card of Array.from(document.querySelectorAll('.card:has(a[href^="/store"])'))) {
const ItemValuations = Array.from(card.querySelectorAll('a[href^="/store"]')).map((item) => ValueJSON.filter((x) => x.id == item.getAttribute('href').split('/')[2])[0]||null).filter((x)=>x!=null&&x.tags[0]!="")
if (ItemValuations.length > 0) {
/* this code is so bad I never want to look at it again */
const QuestionMarkTooltip = document.createElement('i')
QuestionMarkTooltip.classList = 'fa fa-question-circle'
QuestionMarkTooltip.setAttribute('data-bs-toggle', 'tooltip')
QuestionMarkTooltip.setAttribute('data-bs-html', 'true')
ItemValuations.map((item) => {console.log(item.tags)})
QuestionMarkTooltip.setAttribute('data-bs-title', ItemValuations.map((item, i) => `
<b style="text-align: left !important;">${item.name}</b><br>
${ item.tags.map((x) => `
<span class="badge bg-${ GetTagColor(x) }">${x}</span>
`).join('')}
<br>
`).join(''))
card.getElementsByClassName('card-header')[0].appendChild(QuestionMarkTooltip)
}
}
Utilities.InjectResource("registerTooltips")
}
});
})();

View file

@ -89,7 +89,11 @@ const DefaultSettings = {
LeaderboardsOn: true
},
CollectibleInventoryCatOn: true,
ShowValueListDataOn: true,
ValueListInfo: {
Enabled: true,
ItemValuation: true,
TradeValuation: true
},
ImprovedAchievements: {
Enabled: true,
ProgressBarOn: true,

View file

@ -56,7 +56,11 @@ var Utilities;
HoardersList(parseInt(Settings.HoardersList.MinCopies), Settings.HoardersList.AvatarsEnabled);
}
if (Settings.ShowValueListDataOn && Settings.ShowValueListDataOn === true) {
if (
Settings.ValueListInfo &&
Settings.ValueListInfo.Enabled == true &&
Settings.ValueListInfo.ItemValuation == true
) {
ValueListData()
}
}

View file

@ -131,6 +131,11 @@
{
"matches": ["https://polytoria.com/u/**"],
"js": ["/js/the-great-divide.js"]
},
{
"matches": ["https://polytoria.com/trade/view/**"],
"js": ["/js/account/trade-valuation.js"]
}
],
"background": {

View file

@ -109,7 +109,11 @@ export default {
LeaderboardsOn: true
},
CollectibleInventoryCatOn: true,
ShowValueListDataOn: true,
ValueListInfo: {
Enabled: true,
ItemValuation: true,
TradeValuation: true
},
ImprovedAchievements: {
Enabled: true,
ProgressBarOn: true,

View file

@ -697,7 +697,7 @@
Sort a player's inventory by all of their limited-edition collectibles!
</span>
</div>
<div class="setting-container" id="collectibles-inventory-category">
<div class="setting-container" id="value-list-info">
<span class="badge bg-primary mb-1">New in v1.3!</span>
<br>
<span class="indicator">&nbsp;</span>
@ -705,15 +705,23 @@
"List of Values Everlast" Integration
</span>
<div class="setting-buttons">
<button class="btn btn-sm toggle-btn" data-setting="ShowValueListDataOn">Toggle</button>
<button class="btn btn-sm toggle-btn" data-setting="Enabled" data-parent="ValueListInfo">Toggle</button>
</div>
<br />
<span class="desc">
Quickly see a collectible's evaluation by the community-trusted "List-of-Values Everlast" guild!
Quickly see a collectible's evaluation by the community-trusted "List-of-Values Everlast" guild! Credits to them for all value information provided by the extension.
</span>
<span class="note">
* This feature will be expanded to allow you to pick from a list of value lists (list-inception), if any prominent value lists pop-up in the future!
</span>
<span class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="item-view-valuation" data-setting="ItemValuation" data-parent="ValueListInfo" />
<label class="form-check-label" for="item-view-valuation"> Show Value Info on Item View Page </label>
</span>
<span class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="trade-valuation" data-setting="TradeValuation" data-parent="ValueListInfo" />
<label class="form-check-label" for="trade-valuation"> Show Value Info for all items on Trade View Page </label>
</span>
</div>
<div class="setting-container" id="readd-copyable-places">
<span class="badge bg-primary mb-1">New in v1.3!</span>