cake cart better

let cake cart better

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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