PageSourceSearch

https://www.tjc.co.uk/cdn/shop/t/2/assets/live-tv-cart-on-air.js?v=51822410072190960321786084882

js tjc.co.uk collected 2026-10-04 09:11:05 UTC 5,672 bytes, 2 lines download raw bytes

1(function(){"use strict";if(window.__tjcLiveTvCartOnAir)return;window.__tjcLiveTvCartOnAir=!0;var ENDPOINT="/apps/live-tv/currently-on-air",LINE_SELECTOR="[data-ltv-auction-code]",SEED_SELECTOR="#ltv-on-air-seed",CACHE_TTL_MS=6e4,SEED_MAX_AGE_MS=12e4,RERENDER_DEBOUNCE_MS=50,CART_URL="/cart.js",CART_CHANGE_URL="/cart/change.js",cache=null,pendingRefresh=null,flipInFlight=!1;function normalizeCode(value){return value==null?"":String(value).trim().toLowerCase()}function addCode(codes,value){var code=normalizeCode(value);code&&codes.add(code)}function addAuctionCodes(codes,auctions){if(Array.isArray(auctions))for(var i=0;i<auctions.length;i++)auctions[i]&&addCode(codes,auctions[i].auctionCode)}function collectOnAirCodes(payload){var codes=new Set;if(!payload||payload.isLive!==!0)return codes;var data=payload.data;return!data||typeof data!="object"||(addCode(codes,data.auctionCode),addCode(codes,data.packageCode),addAuctionCodes(codes,data.groupAuctions),addAuctionCodes(codes,data.mlaAuctions)),codes}function readSeed(){var seed=document.querySelector(SEED_SELECTOR);if(!seed)return null;var renderedAt=Number(seed.getAttribute("data-ltv-rendered-at"))*1e3;if(!Number.isFinite(renderedAt)||Date.now()-renderedAt>SEED_MAX_AGE_MS)return null;for(var codes=new Set,raw=seed.getAttribute("data-ltv-codes")||"",parts=raw.split("|"),i=0;i<parts.length;i++)addCode(codes,parts[i]);return codes}function fetchOnAirCodes(){return fetch(ENDPOINT,{method:"GET",headers:{Accept:"application/json"},credentials:"same-origin"}).then(function(response){if(!response.ok)throw new Error("currently-on-air responded "+response.status);return response.json()}).then(function(payload){return!payload||payload.success!==!0?(console.warn("[live-tv-cart] on-air endpoint returned an error payload",payload),{answered:!0,authoritative:!1,codes:new Set}):{answered:!0,authoritative:!0,codes:collectOnAirCodes(payload)}}).catch(function(error){return console.warn("[live-tv-cart] on-air lookup failed; falling back to server-rendered seed",error),{answered:!1,authoritative:!1,codes:new Set}})}function getOnAirCodes(){var now=Date.now();return(!cache||now-cache.at>CACHE_TTL_MS)&&(cache={at:now,promise:fetchOnAirCodes()}),cache.promise}function applyCodes(codes){for(var lines=document.querySelectorAll(LINE_SELECTOR),i=0;i<lines.length;i++){var line=lines[i],code=normalizeCode(line.getAttribute("data-ltv-auction-code"));code&&codes.has(code)?line.removeAttribute("hidden"):line.setAttribute("hidden","")}}function itemSourceOf(properties){return properties&&typeof properties._itemSource=="string"?properties._itemSource.trim():""}function findEndedLine(cart,onAirCodes){for(var items=cart&&Array.isArray(cart.items)?cart.items:[],i=0;i<items.length;i++){var item=items[i];if(itemSourceOf(item&&item.properties)==="TV"){var code=normalizeCode(item.properties._auctionCode);if(!(!code||onAirCodes.has(code)))return item}}return null}function flipLineToMissedAuction(item){var properties={};for(var name in item.properties)Object.prototype.hasOwnProperty.call(item.properties,name)&&(properties[name]=item.properties[name]);return properties._itemSource="MA",fetch(CART_CHANGE_URL,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},credentials:"same-origin",body:JSON.stringify({id:item.key,properties:properties})}).then(function(response){if(!response.ok)throw new Error("cart/change.js responded "+response.status);return response.json()})}function flipEndedLines(onAirCodes){flipInFlight||(flipInFlight=!0,fetch(CART_URL,{headers:{Accept:"application/json"},credentials:"same-origin"}).then(function(response){if(!response.ok)throw new Error("cart.js responded "+response.status);return response.json()}).then(function(cart){var budget=cart&&Array.isArray(cart.items)?cart.items.length:0;function step(currentCart,remaining){if(remaining<=0)return Promise.resolve();var target=findEndedLine(currentCart,onAirCodes);return target?flipLineToMissedAuction(target).then(function(updatedCart){return step(updatedCart,remaining-1)}):Promise.resolve()}return step(cart,budget)}).catch(function(error){console.warn("[live-tv-cart] could not rewrite ended Live TV lines to MA",error)}).then(function(){flipInFlight=!1}))}function hasEndedLines(){for(var lines=document.querySelectorAll(LINE_SELECTOR),i=0;i<lines.length;i++)if(lines[i].hasAttribute("hidden"))return!0;return!1}function refresh(){if(document.querySelector(LINE_SELECTOR)){var seed=readSeed();seed&&applyCodes(seed),getOnAirCodes().then(function(result){if(!result.answered){seed||applyCodes(new Set);return}applyCodes(result.codes),result.authoritative&&hasEndedLines()&&flipEndedLines(result.codes)})}}function scheduleRefresh(){pendingRefresh||(pendingRefresh=window.setTimeout(function(){pendingRefresh=null,refresh()},RERENDER_DEBOUNCE_MS))}function observeCartRerenders(){typeof MutationObserver!="function"||!document.body||new MutationObserver(function(mutations){for(var i=0;i<mutations.length;i++)for(var added=mutations[i].addedNodes,j=0;j<added.length;j++){var node=added[j];if(node.nodeType===1&&(node.matches(LINE_SELECTOR)||node.querySelector(LINE_SELECTOR))){scheduleRefresh();return}}}).observe(document.body,{childList:!0,subtree:!0})}
1function init(){refresh(),observeCartRerenders(),document.addEventListener("cart:update",scheduleRefresh),document.addEventListener("cart-page:morphed",scheduleRefresh),document.addEventListener("cart-drawer:open",scheduleRefresh)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",init,{once:!0}):init()})();
2//# sourceMappingURL=/cdn/shop/t/2/assets/live-tv-cart-on-air.js.map?v=51822410072190960321786084882

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.