PageSourceSearch

https://blackbasin.com/cdn/shop/t/5/assets/custom-shipping-insurance.js?v=124342533089970119091784309623

js blackbasin.com collected 2026-10-09 04:56:51 UTC 3,644 bytes, 2 lines download raw bytes

1(function(){const configEl=document.getElementById("ShippingInsuranceConfig");if(!configEl)return;let config;try{config=JSON.parse(configEl.textContent)}catch(e){console.warn("[shipping-insurance] failed to parse config blob",e);return}const productId=config.productId,variantId=config.variantId,initialOptedOut=config.optedOut===!0,initialHasInsuranceLine=config.hasInsuranceLine===!0,initialHasRealItems=config.hasRealItems===!0;if(!productId||!variantId)return;let inFlight=!1;function fetchCart(){return fetch(`${window.routes?.cart_url||"/cart"}.js`,{headers:{Accept:"application/json"}}).then(r=>r.json())}function hasRealItems(cart){return cart.items.some(item=>item.product_id!==productId)}function findInsuranceLine(cart){for(let i=0;i<cart.items.length;i++)if(cart.items[i].product_id===productId)return i+1;return 0}function isOnlyInsurance(cart){return cart.items.length>0&&!hasRealItems(cart)}function refreshCartUI(){try{window.miniCart?.updateSectionContents?.()}catch{}try{document.querySelector("cart-items")?.updateSectionContents?.()}catch{}}function addInsurance(){return inFlight?Promise.resolve():(inFlight=!0,fetch(`${window.routes?.cart_add_url||"/cart/add"}.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({items:[{id:variantId,quantity:1}]})}).then(r=>r.json()).catch(e=>{console.warn("[shipping-insurance] add failed",e)}).finally(()=>{inFlight=!1}))}function removeInsurance(lineIndex){return inFlight?Promise.resolve():(inFlight=!0,fetch(`${window.routes?.cart_change_url||"/cart/change"}.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({line:lineIndex,quantity:0})}).then(r=>r.json()).catch(e=>{console.warn("[shipping-insurance] remove failed",e)}).finally(()=>{inFlight=!1}))}function clearOptOut(){return fetch(`${window.routes?.cart_update_url||"/cart/update"}.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({attributes:{_shipping_insurance_opted_out:""}})}).catch(e=>console.warn("[shipping-insurance] clearOptOut failed",e))}function ensurePresence(){return fetchCart().then(cart=>{const insuranceLine=findInsuranceLine(cart),realItems=hasRealItems(cart),optedOut=cart.attributes?._shipping_insurance_opted_out==="true";return insuranceLine&&!realItems?removeInsurance(insuranceLine).then(refreshCartUI):!insuranceLine&&realItems?optedOut?null:addInsurance().then(refreshCartUI):null})}function init(){initialHasInsuranceLine&&!initialHasRealItems?fetchCart().then(cart=>{const lineIndex=findInsuranceLine(cart);lineIndex&&removeInsurance(lineIndex).then(refreshCartUI)}):!initialHasInsuranceLine&&initialHasRealItems&&!initialOptedOut&&addInsurance().then(refreshCartUI),typeof subscribe=="function"&&typeof PUB_SUB_EVENTS<"u"&&(subscribe(PUB_SUB_EVENTS.cartItemAdd,event=>{if(event&&event.source==="shipping-insurance")return;const items=event?.items||[];items.length>0&&items.every(it=>it&&(it.product_id===productId||it.id===variantId))||ensurePresence()}),subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{if(event&&event.source==="shipping-insurance")return;const cart=event?.cartData;if(cart){if(isOnlyInsurance(cart)){const lineIndex=findInsuranceLine(cart);lineIndex&&removeInsurance(lineIndex).then(refreshCartUI);return}cart.item_count===0&&cart.attributes?._shipping_insurance_opted_out==="true"&&clearOptOut()}}))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",init):init()})();
2//# sourceMappingURL=/cdn/shop/t/5/assets/custom-shipping-insurance.js.map?v=124342533089970119091784309623

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.