1(function () { 2 3 // Add the country domain mapping here 4 const countryDomainMapping = { 5 com : "us", 6 ca : "ca", 7 mx : "mx", 8 uk : "gb", 9 pl : "pl", 10 dk : "dk", 11 fr: "fr", 12 it: "it", 13 es: "es", 14 se: "se", 15 be: "be", 16 de: "de", 17 nl: "nl", 18 no: "no" 19 }; 20 21 22 let retryFlag = true; 23 const hostname = window.location.hostname; // e.g. support.sharkninja.ca 24 const parts = hostname.split('.'); 25 const tld = parts[parts.length - 1]; 26 function onUrlChange() { 27 if (document.querySelector("link[hreflang]") != null) { 28 document.querySelectorAll("link[hreflang]").forEach((item) => { 29 30 const langCode = item.hreflang.split('-')[1]; 31 letIsRemoved = false; 32 if (tld == 'com' && (langCode != 'us' && langCode != 'default')) { 33 item.remove(); 34 retryFlag = false; 35 letIsRemoved = true; 36 } 37 else if (tld != 'com' && countryDomainMapping[tld] && countryDomainMapping[tld] != langCode) { 38 item.remove(); 39 retryFlag = false; 40 letIsRemoved = true; 41 } 42 43 if(!letIsRemoved && tld != getCanonicalDomain(item.href)){ 44 let domainName = getCanonicalDomain(item.href); 45 item.href = item.href.replace(`.${domainName}/`, `.${tld}/`); 46 } 47 }) 48 } 49 if (document.querySelector("link[rel='canonical']") != null) { 50 document.querySelectorAll("link[rel='canonical']").forEach((item) => { 51 let domainName = getCanonicalDomain(item.href); 52 if(tld != domainName){ 53 item.href = item.href.replace(`.${domainName}/`, `.${tld}/`); 54 } 55 }) 56 } 57 if (retryFlag) { 58 retryFlag = false; 59 setTimeout(() => onUrlChange(), 100); 60 } 61 62 } 63 64 function getCanonicalDomain(url){ 65 const u = new URL(url); 66 const hostname = u.hostname; // e.g. "support.sharkninja.ca" 67 const parts = hostname.split('.'); 68 return parts.length ? parts.slice(-1)[0] : ''; 69 } 70 // Listen for back/forward navigation 71 window.addEventListener('popstate', function () { 72 retryFlag = true; 73 onUrlChange(); 74 }); 75 76 // Monkey patch pushState & replaceState 77 const pushState = history.pushState; 78 const replaceState = history.replaceState; 79 80 history.pushState = function () { 81 pushState.apply(history, arguments); 82 retryFlag = true; 83 onUrlChange(); 84 }; 85 86 history.replaceState = function () { 87 replaceState.apply(history, arguments); 88 retryFlag = true; 89 onUrlChange(); 90 }; 91 window.addEventListener("load", onUrlChange); 92})();
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.