Skip to content

Instantly share code, notes, and snippets.

@TheEmpty
Last active August 30, 2021 16:10
Show Gist options
  • Save TheEmpty/dcc80796b2af4797a21a6ca9b461b9b1 to your computer and use it in GitHub Desktop.
Save TheEmpty/dcc80796b2af4797a21a6ca9b461b9b1 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Target auto-pickup order
// @namespace http://myles.empty.best/
// @version 0.1
// @description GOGOGOGOGOGOGOGO
// @author Myles "Empty" Best
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @match https://www.target.com/p/playstation-5-console/-/A-81114595
// @match https://www.target.com/co-cart
// @match https://www.target.com/co-review
// @grant none
// ==/UserScript==
// Login,
// load https://www.target.com/p/playstation-5-console/-/A-81114595
// and wait
// for debug you can use
// @match https://www.target.com/p/dualsense-wireless-controller-for-playstation-5/-/A-81114477
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, 8 * 1000));
console.log("refresh");
document.location.reload();
}
async function product_page() {
await wait_for("[data-test=storeNameWithAddressPopover]");
reload_later();
var expect = 1;
if($(".cartLinkQuantity").length) {
expect = parseInt($(".cartLinkQuantity").innerText) + 1
}
await press_button("[data-test=orderPickupButton]");
await wait_for(".cartLinkQuantity");
// TODO check quantity
console.log("Redirecting");
document.location="https://www.target.com/co-cart";
}
function cart() {
press_button("[data-test=checkout-button]");
}
function order() {
press_button("[data-test=placeOrderButton]");
}
if(location.pathname == "/co-cart") {
cart();
order();
} else if(location.pathname == "/co-review") {
order();
} else {
product_page();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment