From 0051bed0aba547394cae662b9cf58f17fc8f040d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 14 Jul 2024 19:26:11 +0300 Subject: [PATCH] Improve getting inventory url on market page --- code.user.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/code.user.js b/code.user.js index 5530d17..216d73c 100644 --- a/code.user.js +++ b/code.user.js @@ -78,11 +78,7 @@ PAGE_INVENTORY); var market = new SteamMarket(unsafeWindow.g_rgAppContextData, - typeof unsafeWindow.g_strInventoryLoadURL !== 'undefined' && unsafeWindow.g_strInventoryLoadURL != null - ? unsafeWindow.g_strInventoryLoadURL - : typeof unsafeWindow.g_strProfileURL !== 'undefined' && unsafeWindow.g_strProfileURL != null - ? unsafeWindow.g_strProfileURL + '/inventory/json/' - : window.location.origin + '/my/inventory/json/', + getInventoryUrl(), isLoggedIn ? unsafeWindow.g_rgWalletInfo : undefined); var currencyId = @@ -112,6 +108,27 @@ this.inventoryUrlBase += '/'; } + + function getInventoryUrl() { + if (unsafeWindow.g_strInventoryLoadURL) { + return unsafeWindow.g_strInventoryLoadURL; + } + + let profileUrl = window.location.origin + '/my/'; + + if (unsafeWindow.g_strProfileURL) { + profileUrl = unsafeWindow.g_strProfileURL; + } else { + const avatar = document.querySelector( '#global_actions a.user_avatar' ); + + if (avatar) { + profileUrl = avatar.href; + } + } + + return profileUrl.replace(/\/$/, '') + '/inventory/json/'; + } + //#region Settings const SETTING_MIN_NORMAL_PRICE = 'SETTING_MIN_NORMAL_PRICE'; const SETTING_MAX_NORMAL_PRICE = 'SETTING_MAX_NORMAL_PRICE'; @@ -2603,14 +2620,13 @@ $('.actual_content', listingUI).css('background', COLOR_PENDING); setTimeout(function() { - var baseUrl = document.querySelector('a.submenuitem[href$="/inventory/"]').href + 'json/'; var itemName = $('.market_listing_item_name_link', listingUI).first().attr('href'); var marketHashNameIndex = itemName.lastIndexOf('/') + 1; var marketHashName = itemName.substring(marketHashNameIndex); var decodedMarketHashName = decodeURIComponent(itemName.substring(marketHashNameIndex)); var newAssetId = -1; - unsafeWindow.RequestFullInventory(baseUrl + item.appid + "/" + item.contextid + "/", {}, null, null, function(transport) { + unsafeWindow.RequestFullInventory(market.inventoryUrl + item.appid + "/" + item.contextid + "/", {}, null, null, function(transport) { if (transport.responseJSON && transport.responseJSON.success) { var inventory = transport.responseJSON.rgInventory;