cake cart better

let cake cart better

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         cake cart better
// @namespace    https://github.com/Benzenoil/my_tampermonkey_inall
// @version      0.1.1
// @description  let cake cart better
// @author       benzenoil
// @include      https://cake.jp/cart/
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';
  var cartItems = document.querySelectorAll('section.item');
  var dataLayer = window.dataLayer;
  if (dataLayer.length > 0) {
    var cartItemDataList = window.dataLayer[0].cartItemDataList;
  }
  if (cartItemDataList) {
    cartItems.forEach(function (item, index) {
      var thisItem = cartItemDataList[index];
      var itemUrl = 'https://cake.jp/item/' + thisItem.itemCode;
      var imgElement = item.getElementsByTagName('img');
      if (imgElement.length > 0) {
        var aElement = document.createElement('a');
        aElement.setAttribute('href', itemUrl);
        aElement.setAttribute('target', '_blank');
        var parNode = imgElement[0].parentNode;
        parNode.insertBefore(aElement, imgElement[0]);
        aElement.appendChild(imgElement[0]);
      }
    });
  } else {
    cartItems.forEach(function (item) {
      var itemId = item.querySelector("input[name='item_id']").value;
      var itemUrl = 'https://cake.jp/item/' + itemId;
      var imgElement = item.getElementsByTagName('img');
      if (imgElement.length > 0) {
        var aElement = document.createElement('a');
        aElement.setAttribute('href', itemUrl);
        aElement.setAttribute('target', '_blank');
        var parNode = imgElement[0].parentNode;
        parNode.insertBefore(aElement, imgElement[0]);
        aElement.appendChild(imgElement[0]);
      }
    });
  }
  // add a link to head icon
  var headLogo = document.querySelector('.carthead_logo > svg');
  var headLogoParNode = headLogo.parentNode;
  var headLogoAEle = document.createElement('a');
  headLogoAEle.setAttribute('href', 'https://cake.jp/');
  headLogoParNode.insertBefore(headLogoAEle, headLogo);
  headLogoAEle.appendChild(headLogo);
})();