var dbObjCollection = [{appNameId:'1',country:'au',url:'https://pitviper.au',append_url:'YES',original_url:'',redirect_url:''},{appNameId:'2',country:'ca',url:'',append_url:'YES',original_url:'https://pitviper.com/',redirect_url:'https://ca.pitviper.com/'},{appNameId:'2',country:'au',url:'',append_url:'YES',original_url:'https://pitviper.com',redirect_url:'https://pitviper.au'},]; /* 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="1514054123"; /*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: "U2FsdGVkX19vi6fyTGaTQaCYQ/zkWstc2q8RFLzo7sY="} }).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; }