Skip to content

Commit

Permalink
Merge pull request #215 from xPaw/market-progress
Browse files Browse the repository at this point in the history
Add progress bar for market operations
  • Loading branch information
Nuklon authored Jul 17, 2024
2 parents 35961ee + ca09719 commit 99cb913
Showing 1 changed file with 78 additions and 33 deletions.
111 changes: 78 additions & 33 deletions code.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2405,25 +2405,49 @@
//#region Market
if (currentPage == PAGE_MARKET || currentPage == PAGE_MARKET_LISTING) {
var marketListingsRelistedAssets = [];
let marketProgressBar;

function increaseMarketProgressMax() {
let value = marketProgressBar.max;

// Reset the progress bar if it already completed
if (marketProgressBar.value === value) {
marketProgressBar.value = 0;
value = 0;
}

marketProgressBar.max = value + 1;
marketProgressBar.removeAttribute('hidden');
}

function increaseMarketProgress() {
marketProgressBar.value += 1;

if (marketProgressBar.value === marketProgressBar.max) {
marketProgressBar.setAttribute('hidden', 'true');
}
}

var marketListingsQueue = async.queue(function(listing, next) {
marketListingsQueueWorker(listing,
false,
function(success, cached) {
if (success) {
setTimeout(function() {
next();
},
cached ? 0 : getRandomInt(1000, 1500));
increaseMarketProgress();
next();
},
cached ? 0 : getRandomInt(1000, 1500));
} else {
setTimeout(function() {
marketListingsQueueWorker(listing,
true,
function(success, cached) {
next(); // Go to the next queue item, regardless of success.
});
},
cached ? 0 : getRandomInt(30000, 45000));
marketListingsQueueWorker(listing,
true,
function(success, cached) {
increaseMarketProgress();
next(); // Go to the next queue item, regardless of success.
});
},
cached ? 0 : getRandomInt(30000, 45000));
}
});
}, 1);
Expand Down Expand Up @@ -2613,18 +2637,20 @@
function(success) {
if (success) {
setTimeout(function() {
next();
},
getRandomInt(1000, 1500));
increaseMarketProgress();
next();
},
getRandomInt(1000, 1500));
} else {
setTimeout(function() {
marketOverpricedQueueWorker(item,
true,
function(success) {
next(); // Go to the next queue item, regardless of success.
});
},
getRandomInt(30000, 45000));
marketOverpricedQueueWorker(item,
true,
function(success) {
increaseMarketProgress();
next(); // Go to the next queue item, regardless of success.
});
},
getRandomInt(30000, 45000));
}
});
},
Expand Down Expand Up @@ -2714,6 +2740,7 @@
appid: assetInfo.appid,
sellPrice: price
});
increaseMarketProgressMax();
}
}

Expand All @@ -2723,18 +2750,20 @@
function(success) {
if (success) {
setTimeout(function() {
next();
},
getRandomInt(50, 100));
increaseMarketProgress();
next();
},
getRandomInt(50, 100));
} else {
setTimeout(function() {
marketRemoveQueueWorker(listingid,
true,
function(success) {
next(); // Go to the next queue item, regardless of success.
});
},
getRandomInt(30000, 45000));
marketRemoveQueueWorker(listingid,
true,
function(success) {
increaseMarketProgress();
next(); // Go to the next queue item, regardless of success.
});
},
getRandomInt(30000, 45000));
}
});
},
Expand Down Expand Up @@ -2775,6 +2804,7 @@
$.get(window.location.origin + '/market/mylistings?count=100&start=' + listing,
function(data) {
if (!data || !data.success) {
increaseMarketProgress();
next();
return;
}
Expand All @@ -2788,10 +2818,12 @@
// g_rgAssets
unsafeWindow.MergeWithAssetArray(data.assets); // This is a method from Steam.

increaseMarketProgress();
next();
},
'json')
.fail(function(data) {
increaseMarketProgress();
next();
return;
});
Expand Down Expand Up @@ -2873,6 +2905,7 @@
contextid: assetInfo.contextid,
assetid: assetInfo.assetid
});
increaseMarketProgressMax();
}
}

Expand Down Expand Up @@ -2949,9 +2982,13 @@
page: pageSize,
};

var list = new List(market_listing_see.parent().attr('id'), options);
list.on('searchComplete', updateMarketSelectAllButton);
marketLists.push(list);
try {
var list = new List(market_listing_see.parent().get(0), options);
list.on('searchComplete', updateMarketSelectAllButton);
marketLists.push(list);
} catch (e) {
console.error(e);
}
}

// Adds checkboxes to market listings.
Expand Down Expand Up @@ -3005,6 +3042,7 @@

while (currentCount < totalCount) {
marketListingsItemsQueue.push(currentCount);
increaseMarketProgressMax();
currentCount += 100;
}
} else {
Expand Down Expand Up @@ -3043,6 +3081,7 @@
contextid: assetInfo.contextid,
assetid: assetInfo.assetid
});
increaseMarketProgressMax();
})
}
}
Expand Down Expand Up @@ -3190,6 +3229,9 @@

// Initialize the market UI.
function initializeMarketUI() {
$('.market_header_text').append('<progress id="see_market_progress" value="1" max="1" hidden>');
marketProgressBar = document.getElementById('see_market_progress');

// Sell orders.
$('.my_market_header').first().append(
'<div class="market_listing_buttons">' +
Expand Down Expand Up @@ -3336,6 +3378,7 @@
if ($('.market_select_item', $(marketList.matchingItems[i].elm)).prop('checked')) {
var listingid = replaceNonNumbers(marketList.matchingItems[i].values().market_listing_item_name);
marketRemoveQueue.push(listingid);
increaseMarketProgressMax();
}
}
});
Expand Down Expand Up @@ -3688,6 +3731,8 @@
'.separator-small {display:inline-block;width:1px;}' +
'.see_inventory_buttons {display:flex;flex-wrap:wrap;gap:10px;}' +
'.see_inventory_buttons > .see_inventory_buttons {flex-basis: 100%;}' +
'#see_market_progress { display: block; width: 50%; height: 20px; }' +
'#see_market_progress[hidden] { visibility: hidden; }' +
'.pagination { padding-left: 0px; }' +
'.pagination li { display:inline-block; padding: 5px 10px;background: rgba(255, 255, 255, 0.10); margin-right: 6px; border: 1px solid #666666; }' +
'.pagination li.active { background: rgba(255, 255, 255, 0.25); }');
Expand Down

0 comments on commit 99cb913

Please sign in to comment.