1(function(){const p={rebuyUpsellsAtc:".rebuy-cart [data-rebuy-upsells-atc]"};class f{constructor(){this.initBoosterSwapping()}initBoosterSwapping(){const n=document.querySelectorAll(p.rebuyUpsellsAtc);n?.length&&n.forEach(s=>{s.addEventListener("click",e=>{e.preventDefault();const i=s.dataset.rebuyUpsellsAtc||"";i&&this.swapToBooster(i)})})}find4WeekPlanByVariant(n,s){return n.flatMap(e=>e.selling_plans??[]).find(e=>e.shopify_variant_id===String(s)&&e.order_interval_unit_type==="week"&&e.order_interval_frequency==="4")}async swapToBooster(n){if(!n||typeof n!="string")return;const s=window.Rebuy?.SmartCart?.items();if(!s?.length)return;const e=s.filter(t=>t.product?.metafields?.product?.has_boosters&&!(t.variant_title||"").toLowerCase().includes(n)&&!!(t.product?.variants||[]).find(o=>(o.title||"").toLowerCase().split(" / ").includes(n)&&(t.variant_title||"").split(" / ").filter(l=>l!=="Blend").every(l=>(o.title||"").split(" / ").includes(l))));if(!e?.length)return;const i=e.map(t=>{const o=(t.product.variants||[]).find(u=>!!((u.title||"").toLowerCase().split(" / ").includes(n)&&(t.variant_title||"").split(" / ").filter(d=>d!=="Blend").every(d=>(u.title||"").split(" / ").includes(d))));if(!o)return null;const l=t.selling_plan_allocation&&t.product?.selling_plan_groups?.length?t.product?.selling_plan_groups:[],r=this.find4WeekPlanByVariant(l,o.id);return{id:o.id,quantity:t.quantity,selling_plan:r?.id||null}}).filter(t=>t),a=e.reduce((t,o)=>(t[o.key]=0,t),{});if(!(!Object.keys(a)?.length||i.length!==Object.keys(a).length))try{await fetch(window.Shopify.routes.root+"cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:i})}),await fetch(window.Shopify.routes.root+"cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:a})})}catch(t){console.error("Error swapping to booster:",t)}}}window.switchToSubscription=async(c,n,s)=>{if(!(!c||!n||!s))try{const[e,i]=await Promise.all([fetch(`/products/${c}.js`).then(r=>r.json()),fetch("/cart.js").then(r=>r.json())]);if(!e)return;if((i?.items||[]).find(r=>!!r.selling_plan_allocation)){await fetch("/cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:{}})});return}const a=(e.variants||[]).find(r=>r.sku===n);if(!a)return;const t=document.querySelectorAll("[data-rebuy-switch-to-subscription-button]");t?.length&&t.forEach(r=>r.disabled=!0);const o={items:[{id:a.id,quantity:1,selling_plan:a.selling_plan_allocations[0]?.selling_plan_id||null}]};await fetch(window.Shopify.routes.root+"cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});const l={[s]:0};await fetch(window.Shopify.routes.root+"cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:l})}),t?.length&&t.forEach(r=>r.disabled=!1)}catch(e){console.error("Error switching to subscription:",e);const i=document.querySelectorAll("[data-rebuy-switch-to-subscription-button]");i?.length&&i.forEach(a=>a.disabled=!1)}};document.addEventListener("rebuy:smartcart.ready",()=>{new f,document.querySelectorAll('a[href="/cart"]').forEach(n=>n.classList.add("loaded"))});})();
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.