Skip to content

Instantly share code, notes, and snippets.

@antoni-g
Last active May 5, 2022 06:04
Show Gist options
  • Save antoni-g/7a45687275c37e147c99736495cc2536 to your computer and use it in GitHub Desktop.
Save antoni-g/7a45687275c37e147c99736495cc2536 to your computer and use it in GitHub Desktop.
Best Buy add to cart
let added = false
let carting = false
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function waitForButton() {
if (document.getElementsByClassName("go-to-cart-button")[0]) {
document.getElementsByClassName("go-to-cart-button")[0].childNodes[0].click()
carting = true
} else if (!added && document.querySelector('[id^="fulfillment-add-to-cart-button-"]').innerText.includes("Add to Cart")) {
document.getElementsByClassName("add-to-cart-button")[0].click()
added = true
}
}
while (!carting) {
waitForButton()
await sleep(100)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment