Last active
December 11, 2020 09:41
-
-
Save TheEmpty/7c751bd38ad05c70374ef9a618dc1809 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Amazon.com auto-place PS5 Order | |
// @namespace http://myles.empty.best | |
// @version 0.1 | |
// @description more bags | |
// @author Myles "Empty" Best | |
// @match https://www.amazon.com/dp/B08FC5L3RG | |
// @match https://www.amazon.com/gp/buy/spc/handlers/display.html | |
// @require http://code.jquery.com/jquery-3.4.1.min.js | |
// @grant none | |
// ==/UserScript== | |
// ONLY WORKS ON PAGE https://www.amazon.com/dp/B08FC5L3RG | |
// So load https://www.amazon.com/dp/B08FC5L3RG and wait | |
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, 10 * 1000)); | |
console.log("refresh"); | |
document.location.reload(); | |
} | |
async function product_page() { | |
await wait_for("#add-to-wishlist-button-submit"); | |
reload_later(); | |
await wait_for("#price-inside-buybox"); | |
var price = $("#price_inside_buybox").innerText.substring(1,$("#price_inside_buybox").innerText.length); | |
console.log("Available for " + price); | |
if(price <= 550) { | |
await press_button("#add-to-cart-button"); | |
document.location = "https://www.amazon.com/gp/buy/spc/handlers/display.html?hasWorkingJavascript=1"; | |
} | |
} | |
if(location.pathname == "/dp/B08FC5L3RG") { | |
product_page(); | |
} else if(location.pathname == "/gp/buy/spc/handlers/display.html") { | |
press_button("#placeYourOrder1"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment