Last active
May 5, 2022 06:04
-
-
Save antoni-g/7a45687275c37e147c99736495cc2536 to your computer and use it in GitHub Desktop.
Best Buy add to cart
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
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