window.SizebayPrescript = () => ({ getPermalink() { return `https://${window.location.host}/${LS.product.id}` }, getAnchor() { return { web: 'form#product_form > div.js-product-variants', mobile: 'form#product_form > div.js-product-variants' } }, getTenantId() { return 5351 }, getLanguage() { return 'pt' }, getButtons() { return { order: [ { name: 'vfr', text: null }, { name: 'chart', text: null }, ], position: 'after', class: 'vfr__button--clean', } }, getPageProductImg() { const imagesTag = document.querySelector('.swiper-wrapper div.swiper-slide a img') if (!imagesTag) return undefined const images = imagesTag.dataset.srcset?.split(',').map(srcset => { const [rawSrc, width] = srcset.split(' ') return { width: +width.replace('w', ''), src: `https:${rawSrc}` } }) || [] const maxImage = images.reduce((max, img) => img.width > (max?.width || 0) ? img : max, images[0]) return maxImage?.src }, getEnableRedesignedShoe() { return { enabled: true, } } }) const insertSizebayScript = (src, base) => { const script = document.createElement('script') script.id = base ? 'szb-vfr__base' : 'szb-vfr__module' script.setAttribute('src', src) document.querySelector('head').appendChild(script) } const sizebayStyles = () => { const link = document.createElement('link') link.setAttribute('rel', 'stylesheet') link.setAttribute('type', 'text/css') link.setAttribute('href', 'https://static.sizebay.technology/5351/publish/styles_v4.css') document.querySelector('body').appendChild(link) } const sizebayImplantation = () => { insertSizebayScript('https://vfr-v3-production.sizebay.technology/V4/implantation/index.js', true) sizebayStyles() } const addToCart = () => { const payload = { products: [] } payload.products.push({ permalink: window?.SizebayPrescript().getPermalink() }) window.Sizebay.events.addToCart(payload, 5351) } function SizebayInit() { if (!document.querySelectorAll('#szb-vfr__base').length) sizebayImplantation() document.querySelector('[data-store="product-buy-button"]')?.addEventListener('click', addToCart) const payload = { permalink: SizebayPrescript().getPermalink(), tenantId: SizebayPrescript().getTenantId(), buttons: SizebayPrescript().getButtons(), anchor: SizebayPrescript().getAnchor(), lang: SizebayPrescript().getLanguage(), } const sizebayRender = () => { console.log(`Sizebay -> product: ${payload.permalink}`) window?.Sizebay?.Implantation(payload) } window.addEventListener('sizebay:loaded', () => { sizebayRender() }) typeof window?.Sizebay?.Implantation === 'function' && sizebayRender() } if (window.location.href.includes('/produtos/') || window.location.href.includes('/productos/')) { SizebayInit() }