PageSourceSearch

https://www.lovisa.co.uk/cdn/shop/t/811/assets/xgen-common.js?v=82960252284911091011789977862

js lovisa.co.uk collected 2026-09-26 13:25:10 UTC 15,816 bytes, 2 lines download raw bytes

1window.xgenQueryId=window.xgenQueryId||{};function hashCode(str){str.length%32>0&&(str+=Array(33-str.length%32).join("z"));var hash="",bytes=[],i=0,j=0,k=0,a=0,dict=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","1","2","3","4","5","6","7","8","9"];for(i=0;i<str.length;i++)ch=str.charCodeAt(i),bytes[j++]=ch<127?ch&255:127;var chunk_len=Math.ceil(bytes.length/32);for(i=0;i<bytes.length;i++)j+=bytes[i],k++,(k==chunk_len||i==bytes.length-1)&&(a=Math.floor(j/k),a<32?hash+="0":a>126?hash+="z":hash+=dict[Math.floor((a-32)/2.76)],j=k=0);return hash}const minute=60*1e3;class CustomXGen{constructor(){this.key=window.xgen_vars.xgen_api_key,this.secret=window.xgen_vars.xgen_api_secret,this.clientId=window.xgen_vars.xgen_client_id,this.trackerId=window.xgen_vars.xgen_tracker_id,this.collectionDeploymentId=window.xgen_vars.xgen_collection_deployment_id,this.searchDeploymentId=window.xgen_vars.xgen_search_deployment_id,this.locale=window.theme.locale,this.xgenEvents=[],this.isV3=!1,this.trackingInitialized=!1,this.authStore=null;const xgen_vars=window.xgen_vars||{},marketLocale="en-"+xgen_vars.locale;this.xgenCollection=xgen_vars.locales&&xgen_vars.locales.includes(marketLocale)?marketLocale:"default",this.isSearchOrCollection=window.location.pathname.includes("search")||window.location.pathname.includes("collections/"),this.recommendQueue=[];const recommendQueueTime=this.isSearchOrCollection?1500:500,scheduleRecommendQueue=()=>{this.hasMarketingConsent()&&setTimeout(this.processRecommendQueue.bind(this),recommendQueueTime)};this.hasMarketingConsent()?scheduleRecommendQueue():window.theme?.consentGating&&window.lovisaConsent?(window.lovisaConsent.onConsentReady(scheduleRecommendQueue),window.addEventListener("lovisa:consent-updated",scheduleRecommendQueue)):scheduleRecommendQueue(),this.whenConsentReady(()=>this.loadSdk()),window.theme?.consentGating&&window.addEventListener("lovisa:consent-updated",()=>{this.getStatisticsConsent()&&this.xgen&&!this.trackingInitialized&&this.initXgenTracking()})}whenConsentReady(fn){window.theme?.consentGating&&window.lovisaConsent?window.lovisaConsent.onConsentReady(fn):fn()}getStatisticsConsent(){if(window.theme?.consentGating&&window.lovisaConsent?.ready)return window.lovisaConsent.hasStatistics();try{return window.Shopify.customerPrivacy.userCanBeTracked()}catch{return!1}}hasMarketingConsent(){return window.theme?.consentGating?window.lovisaConsent?.ready&&window.lovisaConsent.hasMarketing():!0}processRecommendQueue(){if(!this.hasMarketingConsent())return;const ids=JSON.parse(JSON.stringify(this.recommendQueue));this.recommendQueue=!1,ids.length&&this.recommend({ids,queue:!0}).then(results=>{window.dispatchEvent(new CustomEvent("xgen:recommendations:processed",{detail:results}))})}loadSdk(){const xgenInstance=this;window.Shopify.loadFeatures([{name:"consent-tracking-api",version:"0.1"}],error=>{class CustomAuthStore extends XGenSdkCore.LocalCookieAuthStore{_originalGenerateUserId;constructor(...args){super(...args),this.tokenKey="custom_xgen_token",this.userKey="custom_xgen_user",this.sessionKey="custom_xgen_session",this._originalGenerateUserId=this.generateUserId,this.generateUserId=()=>xgenInstance.getStatisticsConsent()?this._originalGenerateUserId():`cookieless${new Date().toISOString().substring(0,13)?.replace(/-/g,"")}`}_storageGet(key){if(xgenInstance.getStatisticsConsent())return super._storageGet(key);let val=localStorage.getItem(key);if(val||(val=sessionStorage.getItem(key)),!val)return this.storageFallback?this.storageFallback[key]:void 0;try{return JSON.parse(val)}catch{return val}}_storageSet(key,val){if(xgenInstance.getStatisticsConsent()){super._storageSet(key,val);return}key===this.sessionKey?sessionStorage.setItem(key,JSON.stringify(val)):localStorage.setItem(key,JSON.stringify(val)),this.storageFallback&&(this.storageFallback[key]=val)}_storageRemove(key){if(xgenInstance.getStatisticsConsent()){super._storageRemove(key);return}localStorage.removeItem(key),sessionStorage.removeItem(key),this.storageFallback&&delete this.storageFallback[key]}get user(){const existingUser=super.user;if(!existingUser)return null;const isCookieless=existingUser.userId.startsWith("cookieless"),
1cookiesAccepted=xgenInstance.getStatisticsConsent();return isCookieless&&cookiesAccepted?(this.clear(),null):!isCookieless&&!cookiesAccepted?(this.clear(),null):existingUser}}xgenInstance.getStatisticsConsent()||xgenInstance.removeSdkDefaultCookies();const authStore=new CustomAuthStore({cookieOptions:{domain:"."+window.location.hostname.replace("www.","")}});xgenInstance.authStore=authStore;const xgenOptions={key:xgenInstance.key,secret:xgenInstance.secret,clientId:xgenInstance.clientId,trackerId:xgenInstance.trackerId,locale:xgenInstance.locale,authStore};xgenInstance.xgen=new XGenSdkCore.XGenClient(xgenOptions),document.dispatchEvent(new CustomEvent("xgen-sdk-loaded")),xgenInstance.getStatisticsConsent()&&xgenInstance.initXgenTracking()})}mapGTMEvent(event){switch(event.event){case"pageView":return{action:"pageView",data:event.data||{}};case"view_promotion":return!1;case"productView":case"itemView":return console.log("ItemView event"),{action:"itemView",data:event.data||{item:{id:"",name:"",price:"",currency:""}}};case"categoryView":return{action:"categoryView",data:event.data||{category:"",items:["id","id"]}};case"addToCart":return{action:"addToCart",data:event.data||{item:{id:"",name:"",price:"",currency:"",quantity:""}}};default:return{action:event.event,data:event.data||{}}}}pushEvent(event){if(this.getStatisticsConsent()){if(this.trackingInitialized&&this.xgen){const mappedEvent=this.mapGTMEvent(event);mappedEvent&&this.xgen.track[mappedEvent.action]&&this.xgen.track[mappedEvent.action](mappedEvent.data);return}this.xgenEvents.push(event)}}initXgenTracking(){if(!this.getStatisticsConsent()||!this.xgen||this.trackingInitialized)return;this.trackingInitialized=!0;const xgBatchEvents=this.xgen.track.createBatch();xgBatchEvents.pageView(),this.xgenEvents.forEach(event=>{const mappedEvent=this.mapGTMEvent(event);console.log("XGen Track (Batch) ",mappedEvent),mappedEvent&&xgBatchEvents[mappedEvent.action]&&(console.log("SENDING: XGen Track (Batch) ",JSON.stringify(mappedEvent)),xgBatchEvents[mappedEvent.action](mappedEvent.data))}),xgBatchEvents.send(),this.pushEvent=event=>{if(!this.getStatisticsConsent())return;const mappedEvent=this.mapGTMEvent(event);return console.log("XGen Track ",mappedEvent),mappedEvent&&this.xgen.track[mappedEvent.action]?(console.log("SENDING: XGen Track ",JSON.stringify(mappedEvent)),Promise.resolve(this.xgen.track[mappedEvent.action](mappedEvent.data))):(console.log("XGen Track - No event found",mappedEvent),Promise.resolve())}}removeSdkDefaultCookies(){["xgen_session","xgen_token","xgen_user"].forEach(name=>{window.theme.removeCookie(name),window.theme.removeCookie(name,window.location.host),window.theme.removeCookie(name,"."+window.location.host);const hostSplit=window.location.host.split(".").slice(1).join(".");hostSplit&&(window.theme.removeCookie(name,hostSplit),window.theme.removeCookie(name,"."+hostSplit))})}removeXgenCookies(){this.removeSdkDefaultCookies(),window.theme.removeCookie("custom_xgen_session"),window.theme.removeCookie("custom_xgen_token"),window.theme.removeCookie("custom_xgen_user"),window.theme.removeCookie("custom_xgen_session",window.location.host),window.theme.removeCookie("custom_xgen_token",window.location.host),window.theme.removeCookie("custom_xgen_user",window.location.host),window.theme.removeCookie("custom_xgen_session","."+window.location.host),window.theme.removeCookie("custom_xgen_token","."+window.location.host),window.theme.removeCookie("custom_xgen_user","."+window.location.host);const hostSplit=window.location.host.split(".").slice(1).join(".");hostSplit&&(window.theme.removeCookie("custom_xgen_session",hostSplit),window.theme.removeCookie("custom_xgen_token",hostSplit),window.theme.removeCookie("custom_xgen_user",hostSplit),window.theme.removeCookie("custom_xgen_session","."+hostSplit),window.theme.removeCookie("custom_xgen_token","."+hostSplit),window.theme.removeCookie("custom_xgen_user","."+hostSplit))}xgenLoaded(){return new Promise((resolve,reject)=>{this.xgen?resolve(this.xgen):document.addEventListener("xgen-sdk-loaded",()=>{resolve(this.xgen)})})}prepareSearchInput(input){if(!input.options.deploymentId)if(this.collectionDeploymentId)input.options.deploymentId=this.collectionDeploymentId;else if(this.searchDeploymentId)input.options.deploymentId=this.searchDeploymentId;else throw new Error("No deployment id provided");
1input.query||(input.query="");const queryId=input.queryId&&input.queryId.length>0?input.queryId:!1,options={...input.options};return options.collection||(options.collection=this.xgenCollection),options.facets=!0,queryId?{query:input.query,queryId,options:{...options,queryId}}:{query:input.query,options}}getTrendingSearches(input){return input||(input={}),input.collection||(input.collection=this.xgenCollection),new Promise((resolve,reject)=>{this.xgenLoaded().then(xgen=>{xgen.search.getTrendingSearches(input).then(resolve).catch(error=>{this.removeXgenCookies(),setTimeout(()=>{xgen.search.getTrendingSearches(input).then(resolve)},0)})})})}getSearchSuggestions(input,devMode){const query=typeof input>"u"?!1:typeof input=="string"?input:typeof input=="object"?input.query:!1;return query?(input=typeof input=="string"?{query}:input,input.collection||(input.collection=this.xgenCollection),devMode&&(input.options||(input.options={}),input.options.devMode=!0),new Promise((resolve,reject)=>{this.xgenLoaded().then(xgen=>{xgen.search.getSearchSuggestions(input).then(resolve).catch(error=>{this.removeXgenCookies(),setTimeout(()=>{xgen.search.getSearchSuggestions(input).then(resolve)},0)})})})):Promise.resolve(!1)}search(input){const timeNow=Date.now(),maxCacheTime=5*minute,queryObject=this.prepareSearchInput(input);if(!queryObject)return Promise.resolve(!1);queryObject.queryId&&this.xgen&&typeof this.xgen.cancel=="function"&&this.xgen.cancel(queryObject.queryId);const hash="xg_last_search";return new Promise((resolve,reject)=>{const lastSearch=sessionStorage.getItem(hash)?JSON.parse(sessionStorage.getItem(hash)):{};Object.keys(lastSearch).forEach(lsKey=>{lastSearch[lsKey].timestamp+maxCacheTime<=timeNow&&delete lastSearch[lsKey]});let thisMaxCacheTime=maxCacheTime;for(;Object.keys(lastSearch).length>10||JSON.stringify(lastSearch).length>1e4;)thisMaxCacheTime=thisMaxCacheTime-minute,Object.keys(lastSearch).forEach(lsKey=>{lastSearch[lsKey].timestamp+thisMaxCacheTime<=timeNow&&delete lastSearch[lsKey]});const queryHash=hashCode(JSON.stringify(queryObject));lastSearch&&lastSearch[queryHash]&&lastSearch[queryHash].timestamp&&lastSearch[queryHash].timestamp+maxCacheTime>timeNow?(lastSearch[queryHash].isFromCache=!0,resolve(lastSearch[queryHash])):this.xgenLoaded().then(xgen=>{xgen.search.getResults(queryObject).then(results=>{results&&(results.total_result!==void 0&&results.totalResults===void 0&&(results.totalResults=results.total_result),results.products_list!==void 0&&results.items===void 0&&(results.items=results.products_list),results.url_redirect&&!results.urlRedirect&&(results.urlRedirect=results.url_redirect)),results.timestamp=Date.now(),lastSearch[queryHash]=results;try{sessionStorage.setItem(hash,JSON.stringify(lastSearch))}catch{}resolve(results)}).catch(error=>{this.removeXgenCookies(),setTimeout(()=>{xgen.search.getResults(queryObject).then(results=>{results&&(results.total_result!==void 0&&results.totalResults===void 0&&(results.totalResults=results.total_result),results.products_list!==void 0&&results.items===void 0&&(results.items=results.products_list),results.url_redirect&&!results.urlRedirect&&(results.urlRedirect=results.url_redirect)),results.timestamp=Date.now(),lastSearch[queryHash]=results;try{sessionStorage.setItem(hash,JSON.stringify(lastSearch))}catch{}resolve(results)})},0)})})})}recommend(input){return this.hasMarketingConsent()?!input.ids||input.ids.length===0?Promise.resolve({}):(input.ids=[...new Set(input.ids)],new Promise((resolve,reject)=>{if(Object.keys(input).length===1&&input.ids&&this.recommendQueue)this.recommendQueue.push(...input.ids),window.addEventListener("xgen:recommendations:processed",event=>{resolve(event.detail)},{once:!0});else{if(input.queue&&(this.recommendQueue=!1),!input.ids)throw new Error("No ids provided");const xgenObject={options:{}};Array.from(["pathname","queryString","exclude","recentlyViewed","productCode","targetProductCode"]).forEach(key=>{typeof input[key]<"u"&&(xgenObject.options[key]=input[key])}),this.isV3?(xgenObject.containerIds=input.ids,xgenObject.options={version:"v3"}
1):xgenObject.elementIds=input.ids,xgenObject.options.locale="/"+this.xgenCollection+"/",this.xgenLoaded().then(xgen=>{xgen.recommend.getResults(xgenObject).then(results=>{resolve(results)}).catch(error=>{this.removeXgenCookies(),setTimeout(()=>{xgen.recommend.getResults(xgenObject).then(results=>{resolve(results)})},0)})})}})):(input&&input.ids&&this.recommendQueue&&this.recommendQueue.push(...input.ids),Promise.resolve({}))}getRecentlyViewed(productId){var recentlyViewed=localStorage.getItem("xgen_recentProducts")||"";if(productId&&recentlyViewed){var recentlyViewedArray=recentlyViewed.split("|").filter(id=>id.trim()!=productId);recentlyViewed=recentlyViewedArray.join("|")}return recentlyViewed}unifyProduct(product){const tags=[];product.tags&&typeof product.tags=="string"&&tags.push(...product.tags.split(",")),product.tags&&Array.isArray(product.tags)&&tags.push(...product.tags),product.types&&Array.isArray(product.types)&&tags.push(...product.types),product.type&&typeof product.type=="string"&&tags.push(product.type),product.product_types&&typeof product.product_types=="string"&&tags.push(...product.product_types.split(",")),product.product_types&&Array.isArray(product.product_types)&&tags.push(...product.product_types);const productUrl=product.product_url||product.link,handle=product.handle||productUrl.split("/").pop().replace(/\?.*$/g,"");return{available:typeof product.available<"u"?product.available:typeof product.is_in_stock<"u"?product.is_in_stock==="1":product.variants.some(variant=>variant.available),id:product.prod_code||product.code,title:product.prod_name,description:product.description,price:product.sale_price&&product.sale_price!=="None"?product.sale_price*100:product.price*100,compareAtPrice:product.price*100,compare_at_price:product.price*100,vendor:product.brand,handle,url:productUrl,tags,image:product.image,featured_image:product.image,images:product.images?product.images:[product.image],_type:"",currency:{symbol:product.currency_symbol||product.price_currency_symbol,code:product.currency_code||product.price_currency},collections:product.collections?product.collections.map(collection=>typeof collection=="object"&&collection!==null?{id:collection.id||collection.collection_id,handle:collection.handle,title:collection.title}:{handle:collection}):[],options:product.options,has_only_default_variant:!product.variants||product.variants.length===1,variants:product.variants?product.variants.map(variant=>({id:variant.id||variant.variant_id,title:variant.title,url:variant.url,sku:variant.sku,available:variant.available,inStock:variant.is_in_stock==="1",onSale:variant.is_on_sale==="1",price:variant.sale_price&&variant.sale_price!=="None"?variant.sale_price*100:variant.price*100,compareAtPrice:variant.price*100,compare_at_price:variant.price*100,options:variant.options||[],option1:variant.options?.[0]?.value||null,option2:variant.options?.[1]?.value||null,option3:variant.options?.[2]?.value||null})):[]}}}window.xgenCommon=new CustomXGen;
2//# sourceMappingURL=/cdn/shop/t/811/assets/xgen-common.js.map?v=82960252284911091011789977862

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.