Facebook
From Social Porcupine, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 175
  1. const zakekeButtonSelector = ".zakeke-button"
  2. window.addEventListener("load", function(event) {
  3.         const els = document.body.querySelectorAll(zakekeButtonSelector);
  4.         els.forEach(handleZakeke)
  5.   });
  6. function handleZakeke(el) {
  7.   const originalHref = el.getAttribute("href")
  8.         const box = el.closest('[data-pf-type="ProductBox"]')
  9.         const pfvariants = $(box).find('[data-pf-type="ProductVariant"]')
  10.         const selects = pfvariants.find("select")
  11.         const inputs = pfvariants.find("input")
  12.         const pfKey = Array.from(box.classList).find(item => item.includes("pf-"))
  13.         const productId = box.getAttribute("data-product-id")
  14.         function handleChange () {
  15.                   const currentVariant = __pageflyProducts[productId].pfCurrentVariant[pfKey]
  16.                   // custom code below
  17.                   el.setAttribute("href", originalHref + "&id=" + currentVariant.id)
  18.         }
  19.         if (__pageflyProducts && __pageflyProducts[productId]) {
  20.                 selects.change(handleChange)
  21.                 inputs.change(handleChange)
  22.         }
  23.   handleChange()
  24. }