Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve getting inventory url on market page #208

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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