var dbObjCollection = [{appNameId:'1',country:'gb,ie,is,mc,nl,no,pl,ro,ru,za,se,tr,ua,ch,pt,lu,it,im,hu,gr,de,fr,fi,dk,bg,vg,be,at,am,al',url:'https://www.grahamsnatural.co.uk/',append_url:'YES',original_url:'',redirect_url:''},{appNameId:'2',country:'us,ca,tw,ph,sg',url:'',append_url:'YES',original_url:'https://www.grahamsnatural.com.au',redirect_url:'https://www.grahamsnatural.com/'},{appNameId:'2',country:'nl',url:'',append_url:'YES',original_url:'https://www.grahamsnatural.com.au/',redirect_url:'https://www.grahams.nl/'},{appNameId:'2',country:'qa',url:'',append_url:'YES',original_url:'https://www.grahamsnatural.com.au',redirect_url:'https://www.grahamsnatural.co.uk'},{appNameId:'2',country:'at,be,hr,cz,dk,fi,fr,de,gr,hu,is,it,lu,mc,no,pl,pt,ro,ru,sk,si,es,se,ch,tr,ua,il',url:'',append_url:'YES',original_url:'https://www.grahamsnatural.com.au/',redirect_url:'https://www.grahamsnatural.eu/'},{appNameId:'2',country:'gb,ie,im,sa,za,ae,qa,kw',url:'',append_url:'YES',original_url:'https://www.grahamsnatural.com.au',redirect_url:'https://www.grahamsnatural.co.uk'},{appNameId:'2',country:'ca,us',url:'',append_url:'YES',original_url:'https://www.grahamsnatural.com.au/collections/eczema-care-products',redirect_url:'https://www.grahamsnatural.com/collections/eczema-creams-treatments'},]; /* console.log(temp8Check); */ function RemoveLastCharFrmStringWC(dString, rchar){ if(dString != null && rchar != null){ if(dString.length > 0 && rchar.length > 0) { var lastChar = dString.substr(dString.length - 1); if(lastChar == rchar) { dString = dString.slice(0,-1); } } } return dString; } function GetLocation(href) { var l = document.createElement("a"); l.href = href; return l; } var urlString = window.top.location.href; urlParams = parseURLParams(urlString); if(urlParams){ if(urlParams['geo']=="false"){ Cookies.set('geo',"false",{ path: '/' }); } } var actual_url= window.location.href; if(actual_url != Cookies.get("same_domain")){ if(!Cookies.get('geo')){ var rand="190698870"; /*if(Cookies.get("data"+rand)){ window.top.location.href =Cookies.get("data"+rand); } */ if(!Cookies.get("mod_cc")){ modBarjquery.ajax({ url: '//pro.ip-api.com/json/?key=MQXSLbxUAhwAwzB', type: 'POST', dataType: 'jsonp' }).success (function (data1) { console.log ("IP API"); Cookies.set("mod_cc"+rand,data1['countryCode']); Cookies.set("mod_cn"+rand,data1['country']); auto_url_bar(); auto_bar(); }); } setTimeout(function(){ if(!Cookies.get("mod_cc"+rand)){ modBarjquery.ajax({ url: "http://api.ipapi.com/api/check?access_key=3b026537ce9f3956700c31bee96daa53", dataType: "jsonp", type: "POST", }).success(function(data4){ var data5 = data4['country_code']; console.log ("Geo IP Nekudo") Cookies.set("mod_cc"+rand,data5['country_code']); Cookies.set("mod_cn"+rand,data5['country_name']); auto_url_bar(); auto_bar(); }); } }, 2000); /*Backed up on 3 sep 2019 due to shutdown of geoip api. setTimeout(function(){ if(!Cookies.get("mod_cc"+rand)){ modBarjquery.ajax({ url: "//geoip.nekudo.com/api", dataType: "jsonp", type: "POST", }).success(function(data4){ var data5 = data4['country']; console.log ("Geo IP Nekudo") Cookies.set("mod_cc"+rand,data5['code']); Cookies.set("mod_cn"+rand,data5['name']); auto_url_bar(); auto_bar(); }); } }, 2000); */ setTimeout(function(){ if(!Cookies.get("mod_cc"+rand)){ modBarjquery.ajax({ url: "//modapps.com.au/geolocationredirect/index.php/redirect/geo/", dataType: "json", type: "POST", data: { data: "U2FsdGVkX1+ng5VyfW609rVGn7L1q43W20rxjT+sRGM="} }).success(function(data2){ Cookies.set("mod_cc"+rand,data2['country_code']); Cookies.set("mod_cn"+rand,data2['country_name']); auto_url_bar(); auto_bar(); }); } }, 2000); } function auto_url_bar(){ if(Cookies.get("mod_cc"+rand)){ var searchAppId = "2"; var searchCountry = Cookies.get("mod_cc"+rand); console.log(searchCountry); if(searchCountry != null){ searchCountry = searchCountry.replace(/\"/g, ""); } var searchUrl = RemoveLastCharFrmStringWC(window.top.location.href,'/').replace('www.',''); console.log(searchUrl); var resultObj = ''; resultObj = modBarjquery.grep(dbObjCollection, function(e){ return (e.appNameId == searchAppId && (e.country.toUpperCase().indexOf(searchCountry) >= 0)) && RemoveLastCharFrmStringWC(e.original_url,'/').replace('www.','') == searchUrl}); console.log(resultObj); if(resultObj != null){ if (resultObj.length == 0) { // not found console.log("Not found - auto_url_bar - searchId 2"); } else { // access the foo property using result[0].foo window.top.location.href=resultObj[0].redirect_url; } } } } function auto_bar(){ if(Cookies.get("mod_cc"+rand)){ var checkUrlPath = ''; var searchAppId = "1"; var searchCountry = Cookies.get("mod_cc"+rand); if(searchCountry != null){ searchCountry = searchCountry.replace(/\"/g, ""); } var searchUrl = window.top.location.href; var resultObj = ''; resultObj = modBarjquery.grep(dbObjCollection, function(e){ return (e.appNameId == searchAppId && (e.country.toUpperCase().indexOf(searchCountry) >= 0)); }); if(resultObj != null){ if (resultObj.length == 0) { // not found console.log("Not found - auto bar function - searchAppId 1"); } else { // access the foo property using result[0].foo var rdpURL = GetLocation(resultObj[0].url); if(resultObj[0].append_url.toUpperCase() == "YES") { checkUrlPath = RemoveLastCharFrmStringWC(rdpURL.href,'/') + window.location.pathname + window.location.search ; } else { checkUrlPath = rdpURL.href; } if(checkUrlPath.length > 0){ Cookies.set("data"+rand,checkUrlPath); Cookies.set("same_domain",resultObj[0].url); window.top.location.href = Cookies.get("data"+rand); } } } } } } function parseURLParams(url) { var queryStart = url.indexOf("?") + 1, queryEnd = url.indexOf("#") + 1 || url.length + 1, query = url.slice(queryStart, queryEnd - 1), pairs = query.replace(/\+/g, " ").split("&"), parms = {}, i, n, v, nv; if (query === url || query === "") { return; } for (i = 0; i < pairs.length; i++) { nv = pairs[i].split("="); n = decodeURIComponent(nv[0]); v = decodeURIComponent(nv[1]); if (!parms.hasOwnProperty(n)) { parms[n] = []; } parms[n].push(nv.length === 2 ? v : null); } return parms; }