1(function () { 2 var MANUAL_REGION_KEY = "optyx-manual-region"; 3 var ROOT_PATHS = new Set(["/", "/index.html"]); 4 5 function normalizeRegion(value) { 6 if (value === "uk" || value === "us") { 7 return value; 8 } 9 10 return null; 11 } 12 13 function currentRegion() { 14 if (window.location.pathname.indexOf("/uk") === 0) { 15 return "uk"; 16 } 17 18 if (window.location.pathname.indexOf("/us") === 0) { 19 return "us"; 20 } 21 22 return null; 23 } 24 25 function regionPath(region) { 26 return region === "uk" ? "/uk/" : "/us/"; 27 } 28 29 function readManualRegion() { 30 try { 31 return normalizeRegion(window.localStorage.getItem(MANUAL_REGION_KEY)); 32 } catch (error) { 33 return null; 34 } 35 } 36 37 function setManualRegion(region) { 38 try { 39 window.localStorage.setItem(MANUAL_REGION_KEY, region); 40 } catch (error) { 41 } 42 } 43 44 function attachRegionSwitches() { 45 var pageRegion = currentRegion(); 46 var links = document.querySelectorAll('a[href]'); 47 48 links.forEach(function (link) { 49 var href = link.getAttribute("href"); 50 if (!href) { 51 return; 52 } 53 54 var url = new URL(href, window.location.origin); 55 var targetRegion = null; 56 57 if (url.pathname.indexOf("/uk") === 0) { 58 targetRegion = "uk"; 59 } else if (url.pathname.indexOf("/us") === 0) { 60 targetRegion = "us"; 61 } 62 63 if (!targetRegion) { 64 return; 65 } 66 67 if (pageRegion && pageRegion === targetRegion) { 68 link.setAttribute("aria-current", "page"); 69 } 70 71 link.addEventListener("click", function () { 72 setManualRegion(targetRegion); 73 }); 74 }); 75 } 76 77 function updateStatus(message) { 78 var note = document.querySelector("[data-region-status]"); 79 if (note) { 80 note.textContent = message; 81 } 82 } 83 84 function redirectToRegion(region, message) { 85 updateStatus(message); 86 window.location.replace(regionPath(region)); 87 } 88 89 function routeHomePage() { 90 if (!ROOT_PATHS.has(window.location.pathname)) { 91 return; 92 } 93 94 var manualRegion = readManualRegion(); 95 if (manualRegion) { 96 redirectToRegion(manualRegion, "Taking you to your saved regional site..."); 97 return; 98 } 99 100 updateStatus("Checking your location..."); 101 102 var controller = new AbortController(); 103 var timeoutId = window.setTimeout(function () { 104 controller.abort(); 105 }, 1500); 106 107 window 108 .fetch("https://api.country.is/", { 109 signal: controller.signal, 110 }) 111 .then(function (response) { 112 if (!response.ok) { 113 throw new Error("Location request failed"); 114 } 115 116 return response.json(); 117 }) 118 .then(function (data) { 119 var region = data && data.country === "GB" ? "uk" : "us"; 120 redirectToRegion(region, "Routing you to the right regional site..."); 121 }) 122 .catch(function () { 123 redirectToRegion("us", "Taking you to the US site..."); 124 }) 125 .finally(function () { 126 window.clearTimeout(timeoutId); 127 }); 128 } 129 130 routeHomePage(); 131 132 document.addEventListener("DOMContentLoaded", function () { 133 attachRegionSwitches(); 134 }); 135})();
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.