Skip to content

Commit

Permalink
Merge pull request #208 from xPaw/inventoryurl
Browse files Browse the repository at this point in the history
Improve getting inventory url on market page
  • Loading branch information
Nuklon authored Jul 14, 2024
2 parents 84d8fe4 + 0051bed commit c5b059b
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions code.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit c5b059b

Please sign in to comment.