PageSourceSearch

https://invisiblebeadextensions.com/cdn/shop/t/350/assets/cart-monitor.js?v=27401442639308168931787747214

js invisiblebeadextensions.com collected 2026-10-01 12:10:36 UTC 6,772 bytes, 2 lines download raw bytes

1let fetchInProgress=!1,fetchTimeout=null,isInitialized=!1,debounceTimeout=null;const DEBOUNCE_DELAY=150;function debouncedCartUpdate(){debounceTimeout&&clearTimeout(debounceTimeout),debounceTimeout=setTimeout(async()=>{try{const freshCart=await getCart();freshCart&&updateCartItemCount(freshCart)}catch{}debounceTimeout=null},DEBOUNCE_DELAY)}(function(){const handleCartUpdated=debouncedCartUpdate;typeof document<"u"&&(document.addEventListener("cart:updated",handleCartUpdated),document.addEventListener("cart:change",handleCartUpdated),document.addEventListener("cart:refresh",handleCartUpdated),document.addEventListener("ssp:cart:update",handleCartUpdated));let pubSubSetup=!1;const setupPubSub=()=>{if(pubSubSetup)return!0;if(typeof subscribe<"u"&&typeof PUB_SUB_EVENTS<"u"){const eventName=PUB_SUB_EVENTS.cartUpdate||"cart-update";return subscribe(eventName,event=>{event&&event.cartData?updateCartItemCount(event.cartData):handleCartUpdated()}),pubSubSetup=!0,!0}return!1};if(setupPubSub()||[100,500,1e3].forEach(delay=>{setTimeout(()=>{pubSubSetup||setupPubSub()},delay)}),typeof window<"u"&&window.fetch){const originalFetch=window.fetch;window.fetch=function(...args){const url=typeof args[0]=="string"?args[0]:args[0]?.url||"",result=originalFetch.apply(this,args);return(url.includes("/cart/add.js")||url.includes("/cart/update.js")||url.includes("/cart/change.js"))&&args[1]?.method==="POST"&&result.then(response=>{response.ok&&handleCartUpdated()}).catch(()=>{}),result}}})();async function getCart(retryCount=3,delay=1e3){if(fetchInProgress)return null;try{fetchInProgress=!0,clearTimeout(fetchTimeout);for(let i=0;i<retryCount;i++)try{const response=await fetch("/cart.js");if(!response.ok)throw new Error(`HTTP error! status: ${response.status}`);return await response.json()}catch(error){if(i===retryCount-1)throw error;await new Promise(resolve=>setTimeout(resolve,delay))}}catch(error){return console.error("Error fetching cart after all retries:",error),null}finally{fetchInProgress=!1,fetchTimeout=setTimeout(()=>{fetchInProgress=!1},1e3)}}function handleCartChanges(cart){try{cart&&typeof cart=="object"&&updateCartItemCount(cart)}catch(error){console.error("Error handling cart changes:",error)}}function isCartChanged(oldCart,newCart){try{return!oldCart&&!newCart?!1:!oldCart||!newCart?!0:JSON.stringify(oldCart)!==JSON.stringify(newCart)}catch(error){return console.error("Error comparing carts:",error),!0}}async function checkCart(previousCart){try{if(fetchInProgress)return previousCart;const currentCart=await getCart();return currentCart&&isCartChanged(previousCart,currentCart)?(handleCartChanges(currentCart),currentCart):previousCart}catch(error){return console.error("Error in checkCart:",error),previousCart}}async function setupCartChangeDetection(){try{let previousCart=await getCart();const observer=new MutationObserver(async mutations=>{try{mutations.some(mutation=>mutation.target&&mutation.target.closest&&(mutation.target.closest(".cart-drawer")||mutation.target.closest(".cart-count-bubble")||mutation.target.matches(".cart-drawer, .cart-count-bubble")))&&(previousCart=await checkCart(previousCart))}catch(error){console.error("Cart observer error:",error)}});try{document.body&&observer.observe(document.body,{subtree:!0,childList:!0,attributes:!0})}catch(error){console.error("Failed to start cart observer:",error)}try{previousCart=await checkCart(previousCart)}catch(error){console.error("Error during initial cart check:",error)}isInitialized=!0}catch(error){console.error("Error setting up cart change detection:",error)}}function updateCartItemCount(cart){try{if(!cart||typeof cart!="object"||!cart.items||!Array.isArray(cart.items))return;let itemCount;try{typeof cart.item_count=="number"?itemCount=cart.item_count:itemCount=cart.items.reduce((count,item)=>{const quantity=item&&typeof item.quantity=="number"?item.quantity:0;return count+quantity},0)}catch(error){console.error("Error calculating item count:",error);return}try{const headerCartIconLinks=document.querySelectorAll("header #cart-icon-bubble, header .header__icon--cart"),cartCountBubbles=document.querySelectorAll(".cart-count-bubble"),updateOrCreateBubble=(container,onlyCreateInHeader=!1)=>{let bubble=container.querySelector(".cart-count-bubble");const isInHeader=container.closest("header")!==null;if(!bubble&&itemCount>0&&(!onlyCreateInHeader||isInHeader)&&(bubble=document.createElement("div"),bubble.className="
1cart-count-bubble",container.appendChild(bubble)),bubble){const countSpan=bubble.querySelector('span[aria-hidden="true"]'),visuallyHidden=bubble.querySelector(".visually-hidden");if(itemCount>0){if(countSpan)countSpan.textContent=itemCount;else{const newSpan=document.createElement("span");newSpan.setAttribute("aria-hidden","true"),newSpan.textContent=itemCount,bubble.appendChild(newSpan)}if(visuallyHidden)visuallyHidden.textContent=`Cart count: ${itemCount}`;else{const newVisuallyHidden=document.createElement("span");newVisuallyHidden.className="visually-hidden",newVisuallyHidden.textContent=`Cart count: ${itemCount}`,bubble.appendChild(newVisuallyHidden)}bubble.classList.remove("hidden")}else bubble.classList.add("hidden")}};cartCountBubbles.forEach(bubble=>{try{const container=bubble.closest("a")||bubble.parentElement;container&&updateOrCreateBubble(container,!1)}catch{}}),headerCartIconLinks.forEach(link=>{try{updateOrCreateBubble(link,!0)}catch{}}),cartCountBubbles.length===0&&headerCartIconLinks.length===0&&[100,300,500,1e3,2e3].forEach(delay=>{setTimeout(()=>{try{document.querySelectorAll("header #cart-icon-bubble, header .header__icon--cart").forEach(link=>{updateOrCreateBubble(link,!0)})}catch{}},delay)})}catch(domError){console.error("Error updating cart count DOM:",domError)}}catch(error){console.error("Error updating cart item count:",error)}}async function initializeCartMonitor(){try{await setupCartChangeDetection();try{let initialCart=null,retries=5;for(;retries>0&&!initialCart;){try{initialCart=await getCart(1,500)}catch(fetchError){console.error("Error fetching initial cart:",fetchError)}retries--,initialCart||await new Promise(resolve=>setTimeout(resolve,200))}initialCart?updateCartItemCount(initialCart):setTimeout(async()=>{try{const fallbackCart=await getCart();fallbackCart&&updateCartItemCount(fallbackCart)}catch(fallbackError){console.error("Error in fallback cart fetch:",fallbackError)}},2e3)}catch(initError){console.error("Error during cart initialization:",initError)}}catch(error){console.error("Critical error in cart monitor initialization:",error)}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",initializeCartMonitor):initializeCartMonitor();
2//# sourceMappingURL=/cdn/shop/t/350/assets/cart-monitor.js.map?v=27401442639308168931787747214

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.