Skip to content

Instantly share code, notes, and snippets.

@AkdM
Last active April 15, 2021 16:33
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/35cb3c5acca9170037ab1716b487cf55 to your computer and use it in GitHub Desktop.
Save AkdM/35cb3c5acca9170037ab1716b487cf55 to your computer and use it in GitHub Desktop.
AMD.js
// ==UserScript==
// @name AMD Button
// @version 0.1
// @description YAY
// @author AkdM
// @match https://www.amd.com/*/direct-buy/*
// @icon https://www.google.com/s2/favicons?domain=amd.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const inject = fn => {
const script = document.createElement('script')
script.text = `(${fn.toString()})();`
document.documentElement.appendChild(script)
};
const initButton = () => {
Drupal.ajax.bindAjaxLinks(document.body);
};
const checkButton = () => {
let div;
(async () => {
if (document.querySelector(".product-out-of-stock")) {
const productId = document.location.pathname.split("/")[3];
const button = document.createElement("button");
button.className = "btn-shopping-cart btn-shopping-neutral use-ajax";
button.innerHTML = "Add to cart";
button.setAttribute("href", `/en/direct-buy/add-to-cart/${productId}`);
const fixedByDiv = document.createElement("div");
fixedByDiv.innerText = `Fuck Bavarnold`;
div = document.createElement("div");
div.appendChild(button);
div.appendChild(fixedByDiv);
document.querySelector(".product-out-of-stock").replaceWith(div);
inject(initButton);
}
})();
};
checkButton();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment