Skip to content

Instantly share code, notes, and snippets.

@PartAlert

PartAlert/amd.js Secret

Last active Oct 4, 2021
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@arnaudjolly arnaudjolly commented Apr 15, 2021

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

This comment has been minimized.

Copy link
Owner Author

@PartAlert PartAlert commented Apr 15, 2021

It shouldn't make any difference.

@edyee

This comment has been minimized.

Copy link

@edyee 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