Skip to content

Commit

Permalink
Merge pull request #174 from xPaw/fix-select-info
Browse files Browse the repository at this point in the history
Fix multi selection creating infinite timers
  • Loading branch information
Nuklon authored Mar 26, 2023
2 parents e20255e + 70eca97 commit 872ac29
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions code.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1712,9 +1712,20 @@
}
},
selected: function(e, ui) {
updateInventorySelection(ui.selected);
updateButtons();
}
});

if (typeof unsafeWindow.CInventory !== 'undefined') {
var originalSelectItem = unsafeWindow.CInventory.prototype.SelectItem;

unsafeWindow.CInventory.prototype.SelectItem = function(event, elItem, rgItem, bUserAction) {
originalSelectItem.apply(this, arguments);

updateButtons();
updateInventorySelection(rgItem);
}
}
}

// Gets the selected items in the inventory.
Expand Down Expand Up @@ -1876,28 +1887,18 @@
});
}

function updateInventorySelection(item) {
function updateButtons() {
updateSellSelectedButton();
updateTurnIntoGemsButton();
updateOpenBoosterPacksButton();
}

// Wait until g_ActiveInventory.selectedItem is identical to the selected UI item.
// This also makes sure that the new - and correct - item_info (iteminfo0 or iteminfo1) is visible.
var selectedItemIdUI = $('div', item).attr('id');
var selectedItemIdInventory = getActiveInventory().selectedItem.appid +
'_' +
getActiveInventory().selectedItem.contextid +
'_' +
getActiveInventory().selectedItem.assetid;
if (selectedItemIdUI !== selectedItemIdInventory) {
setTimeout(function() {
updateInventorySelection(item);
}, 250);
function updateInventorySelection(selectedItem) {
var item_info = $('#iteminfo' + unsafeWindow.iActiveSelectView);

if (!item_info.length)
return;
}

var item_info = $('.inventory_iteminfo:visible').first();
if (item_info.html().indexOf('checkout/sendgift/') > -1) // Gifts have no market information.
return;

Expand All @@ -1912,11 +1913,11 @@
//$('#' + item_info_id + '_item_market_actions > div:nth-child(1) > div:nth-child(2)')
// .remove(); // Starting at: x,xx.

var market_hash_name = getMarketHashName(getActiveInventory().selectedItem);
var market_hash_name = getMarketHashName(selectedItem);
if (market_hash_name == null)
return;

var appid = getActiveInventory().selectedItem.appid;
var appid = selectedItem.appid;
var item = {
appid: parseInt(appid),
description: {
Expand All @@ -1928,7 +1929,7 @@
false,
function(err, histogram) {
if (err) {
logConsole('Failed to get orders histogram for ' + (getActiveInventory().selectedItem.name || getActiveInventory().selectedItem.description.name));
logConsole('Failed to get orders histogram for ' + (selectedItem.name || selectedItem.description.name));
return;
}

Expand All @@ -1950,21 +1951,18 @@
ownerActions.append('<a class="btn_small btn_grey_white_innerfade" href="/market/listings/' + appid + '/' + market_hash_name + '"><span>View in Community Market</span></a>');
$('#' + item_info_id + '_item_market_actions > div:nth-child(1) > div:nth-child(1)').hide();

var isBoosterPack = getActiveInventory().selectedItem.name.toLowerCase().endsWith('booster pack');
var isBoosterPack = selectedItem.name.toLowerCase().endsWith('booster pack');
if (isBoosterPack) {
var tradingCardsUrl = "/market/search?q=&category_753_Game%5B%5D=tag_app_" + getActiveInventory().selectedItem.market_fee_app + "&category_753_item_class%5B%5D=tag_item_class_2&appid=753";
var tradingCardsUrl = "/market/search?q=&category_753_Game%5B%5D=tag_app_" + selectedItem.market_fee_app + "&category_753_item_class%5B%5D=tag_item_class_2&appid=753";
ownerActions.append('<br/> <a class="btn_small btn_grey_white_innerfade" href="' + tradingCardsUrl + '"><span>View trading cards in Community Market</span></a>');
}


// Generate quick sell buttons.
var itemId = getActiveInventory().selectedItem.assetid || getActiveInventory().selectedItem.id;

// Ignored queued items.
if (getActiveInventory().selectedItem.queued != null) {
if (selectedItem.queued != null) {
return;
}

// Generate quick sell buttons.
var prices = [];

if (histogram != null && histogram.highest_buy_order != null) {
Expand Down Expand Up @@ -2018,7 +2016,7 @@
totalNumberOfQueuedItems++;

sellQueue.push({
item: getActiveInventory().selectedItem,
item: selectedItem,
sellPrice: price
});
});
Expand All @@ -2031,7 +2029,7 @@
totalNumberOfQueuedItems++;

sellQueue.push({
item: getActiveInventory().selectedItem,
item: selectedItem,
sellPrice: price
});
});
Expand Down

0 comments on commit 872ac29

Please sign in to comment.