Skip to content

Instantly share code, notes, and snippets.

@justxanderscode
Forked from awxk/addallgametowishlist.js
Created March 9, 2024 22:41
Show Gist options
  • Save justxanderscode/32f6c74af1d4ae62a864612333c42821 to your computer and use it in GitHub Desktop.
Save justxanderscode/32f6c74af1d4ae62a864612333c42821 to your computer and use it in GitHub Desktop.
(function() {
var wishlist = [];
jQuery.ajax({
type: 'GET',
url: '//api.steampowered.com/ISteamApps/GetAppList/v2',
dataType: 'jsonp',
success: function(result) {
jQuery.each(result['applist']['apps'], function(key, value) {
wishlist.push(value['appid']);
});
jQuery.ajax({
type: 'GET',
url: 'https://store.steampowered.com/dynamicstore/userdata/',
dataType: 'json',
success: function(result) {
var wishlisted = result['rgWishlist'];
var newWishlist = wishlist.filter(function(appid) {
return !wishlisted.includes(appid);
});
// Sort newWishlist in descending order based on appid
newWishlist.sort(function(a, b) { return b - a; });
var total = newWishlist.length;
if (total === 0) {
ShowAlertDialog('No new games to wishlist', 'All games are already wishlisted.');
return;
}
var loaded = 0;
var modal = ShowBlockingWaitDialog('Starting wishlist process...', 'Please wait until all requests finish. Ignore all the errors, let it finish.');
newWishlist.forEach(function(appid, index) {
setTimeout(function() {
jQuery.ajax({
type: 'POST',
dataType: 'text',
url: '//store.steampowered.com/api/addtowishlist',
data: {
appid: appid,
sessionid: g_sessionID,
},
success: function() {
loaded++;
if (loaded < total) {
modal.Dismiss();
modal = ShowBlockingWaitDialog('Adding to wishlist...', `[${loaded}/${total}] App ID ${appid} wishlisted.`);
}
},
error: function(httpReq, status, exception) {
modal.Dismiss();
ShowAlertDialog('Error', `[${loaded}/${total}] Failed to wishlist App ID ${appid}. Error: ${status}`);
},
complete: function() {
if (loaded === total) {
modal.Dismiss();
ShowAlertDialog('Wishlist process completed', 'Enjoy!');
}
}
});
}, index * 150); // Delay each wishlist request by 150 milliseconds
});
},
error: function(httpReq, status, exception) {
ShowAlertDialog('Failed to fetch wishlist data', 'Error: ' + status);
}
});
},
error: function(httpReq, status, exception) {
ShowAlertDialog('Failed to fetch app list', 'Error: ' + status);
},
jsonp: 'jsonp'
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment