PageSourceSearch

https://mascolori.eu/cdn/shop/t/62/assets/product-cart-properties.js?v=82886994574002096511791557767

js mascolori.eu collected 2026-10-09 22:40:35 UTC 5,907 bytes, 2 lines download raw bytes

1(function(){"use strict";function waitForDOM(callback){document.readyState==="loading"?document.addEventListener("DOMContentLoaded",callback):callback()}const domCache={};function getCachedElement(selector,context=document){return domCache[selector]||(domCache[selector]=context.querySelector(selector)),domCache[selector]}function getCachedElements(selector,context=document){const cacheKey=`all_${selector}`;return domCache[cacheKey]||(domCache[cacheKey]=context.querySelectorAll(selector)),domCache[cacheKey]}function clearDOMCache(){Object.keys(domCache).forEach(key=>delete domCache[key])}function initCartProperties(){const productForm=getCachedElement("#product-form")||getCachedElement('form[action*="cart/add"]');productForm&&(createHiddenPropertyInputs(productForm),setupVariantMonitoring(productForm))}function createHiddenPropertyInputs(productForm){productForm.querySelectorAll('input[name*="properties"]').forEach(input=>input.remove());const oldPriceInput=document.createElement("input");oldPriceInput.type="hidden",oldPriceInput.name="properties[Old Price]",oldPriceInput.id="cart-property-old-price",productForm.appendChild(oldPriceInput);const discountInput=document.createElement("input");discountInput.type="hidden",discountInput.name="properties[Discount]",discountInput.id="cart-property-discount",productForm.appendChild(discountInput)}function setupVariantMonitoring(productForm){(getCachedElement(".product-variants")||productForm).addEventListener("click",handleVariantClick);const variantSelect=getCachedElement("#product_select");variantSelect&&variantSelect.addEventListener("change",handleSelectChange);const initialVariant=getCachedElement("[data-pm-variant-id].available");initialVariant&&updateCartProperties(initialVariant),setupAddToCartInterception(productForm)}function handleVariantClick(event){const variantOption=event.target.closest("[data-pm-variant-id]");variantOption&&variantOption.classList.contains("available")&&updateCartProperties(variantOption)}function handleSelectChange(event){const selectedOption=event.target.options[event.target.selectedIndex];if(selectedOption&&selectedOption.dataset.pmVariantId){const variantElement=getCachedElement(`[data-pm-variant-id="${selectedOption.dataset.pmVariantId}"]`);variantElement&&updateCartProperties(variantElement)}}function setupAddToCartInterception(productForm){productForm.addEventListener("submit",function(e){const currentVariant=getCachedElement("[data-pm-variant-id].active")||getCachedElement("[data-pm-variant-id].available");currentVariant&&updateCartProperties(currentVariant),interceptCartAddRequest()},!0),getCachedElements("[add-to-cart-button]").forEach(button=>{button.addEventListener("click",function(e){const currentVariant=getCachedElement("[data-pm-variant-id].active")||getCachedElement("[data-pm-variant-id].available");currentVariant&&updateCartProperties(currentVariant),interceptCartAddRequest()},!0)})}function updateCartProperties(variantElement){const variantId=variantElement.getAttribute("data-pm-variant-id"),comparePrice=variantElement.getAttribute("data-pm-variant-compare-price"),currentPrice=variantElement.getAttribute("data-pm-variant-price"),variantInput=getCachedElement("#productID");if(variantInput&&variantId&&(variantInput.value=variantId),clearCartProperties(),comparePrice&&currentPrice&&comparePrice.trim()&&currentPrice.trim()){const comparePriceNum=parseFloat(comparePrice.replace(/[^\d,.-]/g,"").replace(",",".")),currentPriceNum=parseFloat(currentPrice.replace(/[^\d,.-]/g,"").replace(",","."));if(!isNaN(comparePriceNum)&&!isNaN(currentPriceNum)&&comparePriceNum>currentPriceNum){const discount=Math.round((comparePriceNum-currentPriceNum)/comparePriceNum*100);setCartProperties(comparePrice,`${discount}% OFF`)}}}function setCartProperties(oldPrice,discountText){const oldPriceInput=getCachedElement("#cart-property-old-price"),discountInput=getCachedElement("#cart-property-discount");if(oldPriceInput&&discountInput){const strikethroughPrice=oldPrice.split("").map(char=>char+"\u0336").join("");oldPriceInput.value=strikethroughPrice,discountInput.value=discountText}}function clearCartProperties(){const oldPriceInput=getCachedElement("#cart-property-old-price"),discountInput=getCachedElement("#cart-property-discount");oldPriceInput&&(oldPriceInput.value=""),discountInput&&(discountInput.value="")}function interceptCartAddRequest(){if(window.cartPropertiesInterceptActive)return;window.cartPropertiesInterceptActive=!0;const originalFetch=window.fetch;window.fetch=function(url,options){if(url.includes("cart/add.js")&&options&&options.body)try{const requestData=JSON.parse(options.body);if(requestData.items&&requestData.items.length>0){const oldPriceInput=getCachedElement("#cart-property-old-price"),discountInput=getCachedElement("#cart-property-discount");oldPriceInput&&oldPriceInput.value&&discountInput&&discountInput.value&&(requestData.items[0].properties||(requestData.items[0].properties={}),requestData.items[0].properties["Old Price"]=oldPriceInput.value,requestData.items[0].properties.Discount=discountInput.value)}options.body=JSON.stringify(requestData)}catch(error){console.error("Error intercepting cart/add request:",error)}return originalFetch.call(this,url,options)},setTimeout(()=>{window.fetch=originalFetch,window.cartPropertiesInterceptActive=!1},2e3)}waitForDOM(function(){initCartProperties()}),window.MutationObserver&&new MutationObserver(function(mutations){let shouldReinit=!1;mutations.forEach(mutation=>{mutation.type==="childList"&&Array.from(mutation.addedNodes).some(node=>node.nodeType===1&&(node.matches("[data-pm-variant-id]")||node.querySelector("[data-pm-variant-id]")))&&(shouldReinit=!0)}),shouldReinit&&(clearDOMCache(),initCartProperties())}).observe(document.body,{childList:!0,subtree:!0})})();
2//# sourceMappingURL=/cdn/shop/t/62/assets/product-cart-properties.js.map?v=82886994574002096511791557767

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.