From 46844b3e8a8096ae2070864e4bac27400a2683f6 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 25 Jun 2024 22:55:56 +0300 Subject: [PATCH] Use Valve's v_currencyformat --- code.user.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/code.user.js b/code.user.js index ba35bf1..c6f48bc 100644 --- a/code.user.js +++ b/code.user.js @@ -90,7 +90,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; @@ -218,6 +226,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); @@ -1116,11 +1128,9 @@ if (totalPriceWithFeesOnMarket > 0) { totals.innerHTML += '
Total listed for ' + - (totalPriceWithFeesOnMarket / 100.0).toFixed(2) + - currencySymbol + + formatPrice(totalPriceWithFeesOnMarket) + ', you will receive ' + - (totalPriceWithoutFeesOnMarket / 100).toFixed(2) + - currencySymbol + + formatPrice(totalPriceWithoutFeesOnMarket) + '.
'; } if (totalScrap > 0) { @@ -1144,10 +1154,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) @@ -2031,8 +2040,7 @@ '">' + '' + '' + - (e / 100.0) + - currencySymbol + + formatPrice(e) + '' + '' + '' + @@ -2320,7 +2328,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 + @@ -2484,7 +2492,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(' ➤ ' + highestBuyOrderPrice + @@ -2521,7 +2529,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.'); @@ -2824,7 +2832,7 @@ } } - $('#my_market_selllistings_number').append(', ' + (totalPriceBuyer / 100.0).toFixed(2) + currencySymbol + ' ➤ ' + (totalPriceSeller / 100.0).toFixed(2) + currencySymbol + ''); + $('#my_market_selllistings_number').append(', ' + formatPrice(totalPriceBuyer) + ' ➤ ' + formatPrice(totalPriceSeller) + ''); } @@ -3405,7 +3413,7 @@ return a[1] - b[1]; }).reverse(); - var totalText = 'Number of unique items: ' + sortable.length + ', worth ' + (totalPrice / 100).toFixed(2) + currencySymbol + '

'; + var totalText = 'Number of unique items: ' + sortable.length + ', worth ' + formatPrice(totalPrice) + '

'; var totalNumOfItems = 0; for (var i = 0; i < sortable.length; i++) { totalText += sortable[i][1] + 'x ' + sortable[i][0] + '
';