Skip to content

Instantly share code, notes, and snippets.

@awxk
Forked from Zexxx/addallgametowishlist.js
Last active February 23, 2025 02:01
Show Gist options
  • Save awxk/1a77fbf0bf4198200c714a950d3f83df to your computer and use it in GitHub Desktop.
Save awxk/1a77fbf0bf4198200c714a950d3f83df to your computer and use it in GitHub Desktop.
(async function() {
function fetchJSONP(url, callbackName) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
const callback = `jsonpCallback_${Date.now()}`;
window[callback] = (data) => {
resolve(data);
delete window[callback];
script.remove();
};
script.src = `${url}?jsonp=${callback}`;
script.onerror = () => reject(new Error(`Failed to load JSONP: ${url}`));
document.body.appendChild(script);
});
}
async function fetchData() {
try {
const appListData = await fetchJSONP('//api.steampowered.com/ISteamApps/GetAppList/v2');
const userData = await fetch('//store.steampowered.com/dynamicstore/userdata/').then(res => res.json());
const allAppIds = new Set(
appListData.applist.apps.map(({ appid }) => Number(appid)).filter(appid => !isNaN(appid))
);
const wishlisted = new Set(userData.rgWishlist || []);
const ownedApps = new Set(userData.rgOwnedApps || []);
const ownedPackages = new Set(userData.rgOwnedPackages || []);
const filteredApps = [...allAppIds].filter(
appid => !wishlisted.has(appid) && !ownedApps.has(appid) && !ownedPackages.has(appid)
);
const uniqueApps = [...new Set(filteredApps)];
if (!uniqueApps.length) return console.info("No new games to wishlist.");
const totalTimeMs = uniqueApps.length * 150;
const hrs = Math.floor(totalTimeMs / 3600000);
const mins = Math.floor((totalTimeMs % 3600000) / 60000);
const secs = Math.floor((totalTimeMs % 60000) / 1000);
const ms = totalTimeMs % 1000;
console.log(`Starting wishlist process... ${uniqueApps.length} apps to add. Estimated time: ${hrs}h ${mins}m ${secs}s ${ms}ms`);
for (let i = 0; i < uniqueApps.length; i++) {
await addToWishlist(uniqueApps[i]);
}
console.info("Wishlist process completed.");
} catch (error) {
console.error("Error fetching data:", error);
}
}
async function addToWishlist(appid) {
return new Promise(resolve => {
setTimeout(() => {
const xhr = new XMLHttpRequest();
xhr.open('POST', '//store.steampowered.com/api/addtowishlist');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = resolve;
xhr.onerror = resolve;
xhr.send(`appid=${appid}&sessionid=${g_sessionID}`);
}, 150);
});
}
fetchData();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment