Skip to content

Instantly share code, notes, and snippets.

@AkdM

AkdM/addToCart.js

Last active Apr 8, 2021
Embed
What would you like to do?
Add to Bookmark
javascript: (async function () {
const t = (t) => (document.querySelector(".page-title").innerText = t);
try {
t("looking for product id...");
var e = (() => document.location.pathname.split("/").filter((t) => /\d{10}/.test(t))[0])();
t("adding to cart..."), await ((t) => fetch(`https://www.amd.com/en/direct-buy/add-to-cart/${t}`, { credentials: "include", method: "GET", mode: "cors", redirect: "error" }))(e), t("added to cart, fetching checkout URL...");
var a = await (async () => {
var t = await fetch("https://www.amd.com/en/direct-buy/shopping-cart/modal?_wrapper_format=drupal_modal", { credentials: "include", method: "POST", mode: "cors" });
return (await t.text()).match(/\/.{2}\\\/direct-buy\\\/checkout\\\/payment\\\/\d*\\\/.{2}/)[0].replace(/\\/g, "");
})();
t("redirecting to checkout..."), ((t) => (window.location = t))(a);
} catch (e) {
t(`something went wrong, try again! .... ${e.message} @ ${e.stack}`);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment