Skip to content

Instantly share code, notes, and snippets.

@PartAlert

PartAlert/amd.js Secret

Last active April 12, 2023 13:39
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save PartAlert/a9e8bb6f3b6709ba3a56665164f03978 to your computer and use it in GitHub Desktop.
Save PartAlert/a9e8bb6f3b6709ba3a56665164f03978 to your computer and use it in GitHub Desktop.
License: The MIT License
(async () => {
const urlMatch = location.href.match(/^https:\/\/www.amd.com\/.{2}\/direct-buy\/(\d{10})?/);
if (urlMatch == null) {
const err = 'You must run this script from www.AMD.com.\nThe script will make the add to cart button appear.';
alert(err);
throw new Error(err);
}
const pid = urlMatch[1];
const products = document.querySelectorAll('.view-shop-product-search .views-row');
products.forEach(p => {
const idMatch = p.querySelector('.shop-full-specs-link a').getAttribute('href').match(/\d{10}/);
if (idMatch == null) return;
if (p.querySelector('.shop-links button') != null) return;
p.querySelector('.shop-links').insertAdjacentHTML('beforeend', `<button class="btn-shopping-cart btn-shopping-neutral use-ajax" data-progress-type="fullscreen" href="/en/direct-buy/add-to-cart/${idMatch[0]}">PA | Add To Cart</button>`)
});
const details = document.querySelector('#product-details-info .product-page-description');
if (details && pid && !details.querySelector('button')) {
details.insertAdjacentHTML('beforeend', `<button class="btn-shopping-cart btn-shopping-neutral use-ajax" data-progress-type="fullscreen" href="/en/direct-buy/add-to-cart/${pid}">PA | Add to Cart</button>`)
}
Drupal.ajax.bindAjaxLinks(document);
if (details && details.querySelector('button')) {
details.querySelector('button').click();
}
})();
javascript:(async () => { s=document.createElement('script'); s.innerHTML=(await (await fetch(`https://gist.githubusercontent.com/PartAlert/a9e8bb6f3b6709ba3a56665164f03978/raw/amd.js?v=${new Date().getTime()}`)).text()); document.body.appendChild(s); })()
@arnaudjolly
Copy link

Hello, is it possible that collecting the language (as well as the pid) in the url to be reused in the button href may help ?

const urlMatch = location.href.match(/^https:\/\/www.amd.com\/(.{2})\/direct-buy\/(\d{10})?/);
//...
const [,lang,pid] = urlMatch;

// and in the button hrefs:
// href="/${lang}/direct-buy/add-to-cart/${idMatch[0]}"
// href="/${lang}/direct-buy/add-to-cart/${pid}"

Or maybe the lang parameter in the /add-to-cart/ call doesn't matter ?

@PartAlert
Copy link
Author

It shouldn't make any difference.

@edyee
Copy link

edyee commented May 1, 2021

hi is there any script for amazonuk or currys uk .... so we can buy cards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment