Last active
May 19, 2021 19:02
-
-
Save chrisjpatty/2b265dd5dca1e3b8209fc88ebc73f575 to your computer and use it in GitHub Desktop.
Gamestop PS5 Stock Check Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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() | |
}); | |
})(); |
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
Just updated the timing to not run exactly every 10 seconds so it's less obvious that it's a bot.