1(function () { 2 3 // Stop redirect if already on China page 4 if (window.location.pathname.startsWith('/zh/china')) { 5 return; 6 } 7 8 function getCookie(name) { 9 const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); 10 return match ? match[2] : null; 11 } 12 13 function setCookie(name, value) { 14 document.cookie = 15 name + "=" + value + 16 "; path=/; max-age=" + (60 * 60 * 24 * 30) + 17 "; SameSite=Lax"; 18 } 19 20 var isHomepage = window.location.pathname === '/' || window.location.pathname === ''; 21 var country = getCookie('visitor_country'); 22 23 // Returning visitor â country already known 24 if (country) { 25 26 // Condition 2: China user visits homepage for the first time 27 if (country === 'CN' && isHomepage && !getCookie('china_home_visited')) { 28 setCookie('china_home_visited', '1'); 29 window.location.href = "/zh/china/"; 30 } 31 32 return; 33 } 34 35 // Condition 1: First time visitor â detect country via API 36 37 38 fetch(geoApi.ajaxurl + '?action=kpit_get_visitor_country') 39 .then(function(response) { 40 return response.json(); 41 }) 42 .then(function(result) { 43 44 if (!result.success) return; 45 46 var detectedCountry = result.data.country_code; 47 48 setCookie('visitor_country', detectedCountry); 49 50 if (detectedCountry === 'CN') { 51 if (isHomepage) { 52 setCookie('china_home_visited', '1'); 53 } 54 55 window.location.replace('/zh/china/'); 56 } 57 58 }) 59 .catch(function(err) { 60 console.error(err); 61 }); 62 63})();
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.