Advertisement
Guest User

AMD Script

a guest
Jun 17th, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. function appendAddToCartButton() {
  2. const productPage = document.getElementById("product-details-info");
  3. if (productPage == null) {
  4. const elements = Array.from(document.getElementsByClassName("view view-shop-product-search view-id-shop_product_search view-display-id-direct-buy-catalog")[0].getElementsByClassName("views-row"));
  5. Array.from(elements).forEach((item) => {
  6. if (item.getElementsByClassName("btn-shopping-cart btn-shopping-neutral use-ajax").length == 0) {
  7. var itemId = item.getElementsByClassName("shop-image-link")[0].getAttribute("href").replace(/^\D+/g, '').split("/")[0];
  8. var button = document.createElement("button");
  9. button.setAttribute("class", "btn-shopping-cart btn-shopping-neutral use-ajax");
  10. button.setAttribute("data-progress-type", "fullscreen");
  11. button.setAttribute("href", "/en/direct-buy/add-to-cart/" + itemId);
  12. button.setAttribute("style", "color: white !important;background-color: #636466 !important;border: 2px solid #282828 !important;");
  13. button.innerHTML = "Add to Cart*";
  14. item.getElementsByClassName("shop-links")[0].innerHTML = "";
  15. item.getElementsByClassName("shop-links")[0].appendChild(button);
  16. }
  17. });
  18. } else {
  19. if (document.getElementsByClassName("btn-shopping-cart btn-shopping-neutral use-ajax").length == 0) {
  20. if (productPage.getElementsByClassName("product-out-of-stock").length > 0) {
  21. document.getElementsByClassName("product-out-of-stock")[0].remove();
  22. var itemId = window.location.href.replace(/^\D+/g, '').split("/")[0];
  23. var button = document.createElement("button");
  24. button.setAttribute("class", "btn-shopping-cart btn-shopping-neutral use-ajax");
  25. button.setAttribute("href", "/en/direct-buy/add-to-cart/" + itemId);
  26. button.setAttribute("style", "color: white !important;background-color: #636466 !important;border: 2px solid #282828 !important;");
  27. button.innerHTML = "Add to cart*";
  28. document.getElementsByClassName("product-page-description")[0].appendChild(button);
  29. }
  30. }
  31. }
  32. Drupal.ajax.bindAjaxLinks(document);
  33. return productPage;
  34. }
  35.  
  36. if (window.location.href.includes("direct-buy")) {
  37. if (appendAddToCartButton() != null) {
  38. document.getElementsByClassName("btn-shopping-cart btn-shopping-neutral use-ajax")[0].click();
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement