Skip to content

Instantly share code, notes, and snippets.

@AkdM

AkdM/amd.js

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