Skip to content

Instantly share code, notes, and snippets.

@AkdM
Last active April 8, 2021 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkdM/5d18ed9d720948ca213bbf19ee6f432b to your computer and use it in GitHub Desktop.
Save AkdM/5d18ed9d720948ca213bbf19ee6f432b to your computer and use it in GitHub Desktop.
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