window.SizebayPrescript = () => ({ getPermalink() { const product = document.querySelector("link[rel='canonical']")?.href || window.location.href; console.log("Link produto: " + product) return product }, getAnchor() { return { web: 'form#product_form > div.js-product-variants', mobile: 'form#product_form > div.js-product-variants' } }, getPageProductImg() { let link = ''; const imagesTag = document.querySelector('.swiper-wrapper div.swiper-slide a img') if(!imagesTag){ return false } const images = imagesTag .dataset.srcset.split(',').map(srcset => { const [rawSrc, width] = srcset.split(' ') const src = `https:${rawSrc}` return { width: +width.replace('w', ''), src } }) if(images.length > 1) { const maxWidthAvailable = Math.max(...images.map(src => src.width ? src.width : 0)); link = images.find(el => el.width === maxWidthAvailable).src; } else { link = images[0].src; } return link; }, getTenantId() { return 3558 }, getButtons() { return { order: [ { name: 'vfr', text: null }, { name: 'chart', text: null } ], position: 'after', class: 'vfr__button--clean' } }, getLanguage() { return 'br' }, getIntegration() { const appUrl = 'https://vfr-v3-production.sizebay.technology/V4/implantation/index.js' const app = document.createElement('script') app.id = 'szb-vfr__base' app.setAttribute('src', appUrl) document.querySelector('head').appendChild(app) } }) function insertStyle(ref) { const linkElem = document.createElement('link') linkElem.setAttribute('rel', 'stylesheet') linkElem.setAttribute('type', 'text/css') linkElem.setAttribute('href', ref) document.querySelector('body').appendChild(linkElem) } function insertScript(ref) { let app = document.createElement('script') app.id = 'szb-vfr__base' app.setAttribute('src', ref) document.querySelector('head').appendChild(app) } function init() { const implantation = 'https://vfr-v3-production.sizebay.technology/V4/implantation/index.js' insertScript(implantation) } function customStyle() { const style = 'https://static.sizebay.technology/3558/publish/styles_v4.css' insertStyle(style) } function SizebayInit() { init() if ( window.location.href.includes('/produtos') || window.location.href.includes('/productos') ) { customStyle() let payload = { permalink: SizebayPrescript().getPermalink(), tenantId: SizebayPrescript().getTenantId(), buttons: SizebayPrescript().getButtons(), anchor: SizebayPrescript().getAnchor(), lang: SizebayPrescript().getLanguage() } let loaded = setInterval(() => { if (document.querySelectorAll('form#product_form > div.js-product-variants').length || document.querySelectorAll('form#product_form > div.js-product-variants').length) { console.log('Prescript V1.0') window.Sizebay.Implantation(payload) clearInterval(loaded) } }, 1000) } } SizebayInit()