Skip to content

Instantly share code, notes, and snippets.

@TheEmpty
Created December 11, 2020 09:40
Show Gist options
  • Save TheEmpty/c22b2a29ad5a0db1ad79d0c2f5ba6939 to your computer and use it in GitHub Desktop.
Save TheEmpty/c22b2a29ad5a0db1ad79d0c2f5ba6939 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Costco PS5
// @namespace https://myles.empty.best/
// @version 0.1
// @description Bundle me
// @author Myles "Empty" Best
// @match https://www.costco.com/LogonForm
// @match https://www.costco.com/*
// @grant none
// ==/UserScript==
// NOTE: Designed for PS5 not being in cart, unsure of how it will
// perform if in cart.
// Load https://www.costco.com/sony-playstation-5-gaming-console-bundle.product.100691489.html and wait.
//////////////////////////////////////////////////////////
// CONFIGURE THIS BEFORE RUNNING OR IT WILL FUCK YOU UP //
//////////////////////////////////////////////////////////
var COSTCO_USERNAME="youremail@address.com"
var COSTCO_PASSWORD="yourpassword"
////////////////////////////////////
// AND DON'T MESS WITH THIS BELOW //
////////////////////////////////////
async function wait_for(query) {
while(true) {
var node = $(query);
if(node.length != 0 && node.is(":visible")) {
break;
}
console.log("" + query + " not available yet, waiting.");
await new Promise(r => setTimeout(r, 500));
}
}
async function press_button(query) {
await wait_for(query);
$(query).click();
console.log("Button " + query + " pressed");
}
async function reload_later() {
await new Promise(r => setTimeout(r, 300000));
window.location.reload();
}
(function() {
if(window.location.pathname != "/LogonForm") {
if($("a[href='https://www.costco.com/LogonForm']:visible").length != 0) {
window.location = "https://www.costco.com/LogonForm";
return
}
}
if(window.location.pathname == "/LogonForm") {
$("#logonId").val(COSTCO_USERNAME);
$("#logonPassword").val(COSTCO_PASSWORD);
$("#LogonForm").find("[type=submit]").click();
return
}
if(window.location.pathname == "/") {
window.location = "https://www.costco.com/sony-playstation-5-gaming-console-bundle.product.100691489.html";
return
}
if(window.location.pathname == "/AjaxManageShoppingCartCmd") {
window.location = "https://www.costco.com/CheckoutCartDisplayView";
return
}
if(window.location.pathname == "/sony-playstation-5-gaming-console-bundle.product.100691489.html") {
press_button("#add-to-cart-btn");
reload_later();
return;
}
if(window.location.pathname == "/CheckoutCartDisplayView") {
press_button("#shopCartCheckoutSubmitButton");
return;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment