Skip to content

Commit

Permalink
Merge pull request #197 from xPaw/v_currencyformat
Browse files Browse the repository at this point in the history
Use Valve's v_currencyformat
  • Loading branch information
Nuklon authored Jul 14, 2024
2 parents 9d731ff + 46844b3 commit fcc2dbc
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions code.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@
market.walletInfo.wallet_currency :
3;

var currencySymbol = unsafeWindow.GetCurrencySymbol(unsafeWindow.GetCurrencyCode(currencyId));
const currencyCountry =
isLoggedIn &&
market != null &&
market.walletInfo != null &&
market.walletInfo.wallet_country != null ?
market.walletInfo.wallet_country :
'US';

const currencyCode = unsafeWindow.GetCurrencyCode(currencyId);

function SteamMarket(appContext, inventoryUrl, walletInfo) {
this.appContext = appContext;
Expand Down Expand Up @@ -216,6 +224,10 @@
//#endregion

//#region Price helpers
function formatPrice(valueInCents) {
return unsafeWindow.v_currencyformat(valueInCents, currencyCode, currencyCountry);
}

function getPriceInformationFromItem(item) {
var isTradingCard = getIsTradingCard(item);
var isFoilTradingCard = getIsFoilTradingCard(item);
Expand Down Expand Up @@ -1130,11 +1142,9 @@

if (totalPriceWithFeesOnMarket > 0) {
totals.innerHTML += '<div><strong>Total listed for ' +
(totalPriceWithFeesOnMarket / 100.0).toFixed(2) +
currencySymbol +
formatPrice(totalPriceWithFeesOnMarket) +
', you will receive ' +
(totalPriceWithoutFeesOnMarket / 100).toFixed(2) +
currencySymbol +
formatPrice(totalPriceWithoutFeesOnMarket) +
'.</strong></div>';
}
if (totalScrap > 0) {
Expand All @@ -1158,10 +1168,9 @@
' - ' +
itemName +
' listed for ' +
(market.getPriceIncludingFees(task.sellPrice) / 100.0).toFixed(2) +
currencySymbol +
formatPrice(market.getPriceIncludingFees(task.sellPrice)) +
', you will receive ' +
(task.sellPrice / 100.0).toFixed(2) + currencySymbol +
formatPrice(task.sellPrice) +
'.');

$('#' + task.item.appid + '_' + task.item.contextid + '_' + itemId)
Expand Down Expand Up @@ -2060,8 +2069,7 @@
'">' +
'<span class="item_market_action_button_edge item_market_action_button_left"></span>' +
'<span class="item_market_action_button_contents">' +
(e / 100.0) +
currencySymbol +
formatPrice(e) +
'</span>' +
'<span class="item_market_action_button_edge item_market_action_button_right"></span>' +
'<span class="item_market_action_button_preload"></span>' +
Expand Down Expand Up @@ -2349,7 +2357,7 @@

var itemPrice = sellPrice == 65535 ?
'∞' :
(market.getPriceIncludingFees(sellPrice) / 100.0).toFixed(2) + currencySymbol;
formatPrice(market.getPriceIncludingFees(sellPrice));

var elementName = (currentPage == PAGE_TRADEOFFER ? '#item' : '#') +
item.appid +
Expand Down Expand Up @@ -2513,7 +2521,7 @@
// The 'histogram.highest_buy_order' is not reliable as Steam is caching this value, but it gives some idea for older titles/listings.
var highestBuyOrderPrice = (histogram == null || histogram.highest_buy_order == null ?
'-' :
((histogram.highest_buy_order / 100) + currencySymbol));
formatPrice(histogram.highest_buy_order));
$('.market_table_value > span:nth-child(1) > span:nth-child(1) > span:nth-child(1)',
listingUI).append(' ➤ <span title="This is likely the highest buy order price.">' +
highestBuyOrderPrice +
Expand Down Expand Up @@ -2550,7 +2558,7 @@
listingUI.addClass('price_' + sellPriceWithOffset);

$('.market_listing_my_price', listingUI).last().prop('title',
'The best price is ' + (sellPriceWithoutOffsetWithFees / 100.0) + currencySymbol + '.');
'The best price is ' + formatPrice(sellPriceWithoutOffsetWithFees) + '.');

if (sellPriceWithoutOffsetWithFees < price) {
logConsole('Sell price is too high.');
Expand Down Expand Up @@ -2854,7 +2862,7 @@
}
}

$('#my_market_selllistings_number').append('<span id="my_market_sellistings_total_price">, ' + (totalPriceBuyer / 100.0).toFixed(2) + currencySymbol + ' ➤ ' + (totalPriceSeller / 100.0).toFixed(2) + currencySymbol + '</span>');
$('#my_market_selllistings_number').append('<span id="my_market_sellistings_total_price">, ' + formatPrice(totalPriceBuyer) + ' ➤ ' + formatPrice(totalPriceSeller) + '</span>');
}


Expand Down Expand Up @@ -3435,7 +3443,7 @@
return a[1] - b[1];
}).reverse();

var totalText = '<strong>Number of unique items: ' + sortable.length + ', worth ' + (totalPrice / 100).toFixed(2) + currencySymbol + '<br/><br/></strong>';
var totalText = '<strong>Number of unique items: ' + sortable.length + ', worth ' + formatPrice(totalPrice) + '<br/><br/></strong>';
var totalNumOfItems = 0;
for (var i = 0; i < sortable.length; i++) {
totalText += sortable[i][1] + 'x ' + sortable[i][0] + '<br/>';
Expand Down

0 comments on commit fcc2dbc

Please sign in to comment.