cake cart better

let cake cart better

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
})();