Skip to content

Commit

Permalink
auto float loading on the tradeoffers page resolves #100
Browse files Browse the repository at this point in the history
  • Loading branch information
gergelyszabo94 committed Dec 16, 2019
1 parent 2020fba commit b901bbb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion extension/chrome/js/background_scripts/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {

fetch(getRequest).then((response) => {
if (!response.ok) {
sendResponse('error');
console.log(`Error code: ${response.status} Status: ${response.statusText}`);
sendResponse('error');
}
else return response.json();
}).then((body) => {
Expand Down
19 changes: 18 additions & 1 deletion extension/chrome/js/content_scripts/steam/tradeoffers.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function getIDsFromElement(element) {
};
}

function selectItemElementByIDs(classid, instanceid) {
return document.querySelector(`[data-economy-item="classinfo/730/${classid}/${instanceid}"`);
}

function getItemByIDs(items, IDs) {
if (IDs.instanceid !== null) return items.filter(item => item.classid === IDs.classid && item.instanceid === IDs.instanceid)[0];
else return items.filter(item => item.classid === IDs.classid)[0];
Expand All @@ -98,7 +102,20 @@ function addItemInfo(items) {
makeItemColorful(itemElement, item, result.colorfulItems);
addSSTandExtIndicators(itemElement, item);
addPriceIndicator(itemElement, item.price);
if (result.autoFloatOffer) addFloatIndicator(itemElement, item.floatInfo);

if (result.autoFloatOffer && item.inspectLink !== null) {
if (item.floatInfo === null && itemTypes[item.type.key].float) {
floatQueue.jobs.push({
type: 'offersPage',
assetID: item.assetid,
classid: item.classid,
instanceid: item.instanceid,
inspectLink: item.inspectLink
});
if (!floatQueue.active) workOnFloatQueue();
}
else addFloatIndicator(itemElement, item.floatInfo);
}

// marks the item "processed" to avoid additional unnecessary work later
itemElement.setAttribute('data-processed', 'true');
Expand Down
7 changes: 6 additions & 1 deletion extension/chrome/js/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,9 @@ function addFloatDataToPage(job, floatQueue, floatInfo) {
setStickerInfo(job.listingID, floatInfo.stickers);
addPatterns(job.listingID, floatInfo);
}
else if (job.type === 'offersPage') {
addFloatIndicator(selectItemElementByIDs(job.classid, job.instanceid), floatInfo);
}
}

function getFloatInfoFromCache(assetIDs) {
Expand Down Expand Up @@ -1476,9 +1479,11 @@ function extractItemsFromOffers(offers) {
if (offers !== undefined || null) {
offers.forEach(offer => {
if (offer.items_to_give !== undefined) offer.items_to_give.forEach(item => {
item.owner = getPoperStyleSteamIDFromOfferStyle(offer.accountid_other);
itemsToReturn.push(item)
});
if (offer.items_to_receive !== undefined) offer.items_to_receive.forEach(item => {
item.owner = getPoperStyleSteamIDFromOfferStyle(offer.accountid_other);
itemsToReturn.push(item)
});
});
Expand Down Expand Up @@ -1659,6 +1664,6 @@ function prettyTimeAgo(unixTimestamp) {
else if (differenceSeconds >= (86400 * 30) && differenceSeconds < (86400 * 60)) prettyString = 'Over a month ago';
else if (differenceSeconds >= (86400 * 60) && differenceSeconds < (86400 * 365)) prettyString = `${Math.trunc(differenceSeconds / (86400 * 30))} months ago`;
else prettyString = 'Over a year ago';

return prettyString;
}

0 comments on commit b901bbb

Please sign in to comment.