Skip to content

Instantly share code, notes, and snippets.

@chrisjpatty
Last active May 19, 2021 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisjpatty/2b265dd5dca1e3b8209fc88ebc73f575 to your computer and use it in GitHub Desktop.
Save chrisjpatty/2b265dd5dca1e3b8209fc88ebc73f575 to your computer and use it in GitHub Desktop.
Gamestop PS5 Stock Check Bot
(async () => {
Notification.requestPermission().then(async function(result) {
const getTime = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
}
const notify = (message) => {
new Notification('PS5 Bot', { body: message });
}
const wait = (time) => {
return new Promise((resolve) => {
setTimeout(resolve, time);
});
};
notify("Successfully subscribed to notifications")
const alertSelector = ".alert.add-to-basket-alert.text-center";
const cartSelector = ".add-to-cart.btn.btn-primary";
const checkForAdd = async () => {
console.log("Checking for stock")
document.getElementById("option-PRP-226298").click();
await wait(1000);
document.getElementById("option-PRP-226298").click();
await wait(1000);
document.querySelector(cartSelector).click();
await wait(800);
const hasAlert = document.querySelector(alertSelector)
if(hasAlert){
// Wait a random amount of time before rechecking so it's less obvious that you're a bot.
const nextWaitTime = getTime(8000, 12000);
console.log("Waiting for " + nextWaitTime + " seconds before rechecking")
await wait(nextWaitTime)
await checkForAdd()
}else{
notify("🚨 HURRY!!! THE PS5 HAS BEEN ADDED TO YOUR CART!!! 🚨")
}
};
await checkForAdd()
});
})();
@chrisjpatty
Copy link
Author

Just updated the timing to not run exactly every 10 seconds so it's less obvious that it's a bot.

@chrisjpatty
Copy link
Author

Reduced the wait time before checking if adding failed to reduce the chance of a false positive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment