(function(){ var loadScript = function(url, callback){ var script = document.createElement("script"); script.type = "text/javascript"; if (script.readyState){ script.onreadystatechange = function(){ if (script.readyState == "loaded" || script.readyState == "complete"){ script.onreadystatechange = null; callback(); } }; } else { script.onload = function(){ callback(); }; } script.src = url; document.getElementsByTagName("head")[0].appendChild(script); }; var fix = function($){var bots = ['Googlebot','Bingbot','Slurp','DuckDuckBot','Baiduspider','YandexBot','Sogou','Exabot','facebot','facebookexternalhit','ia_archiver']; $('m4u_country').replaceWith('United States'); $('m4u_country_code').replaceWith('US'); $('m4u_country_flag').replaceWith('' ); if(typeof m4u_exclude_ips != 'undefined') { var cur_ip = '54.235.48.106'; var ex_ips = m4u_exclude_ips.split(','); if(ex_ips.indexOf(cur_ip)>=0) return; } var css = ''; //var fa = ''; function performAction(act) { //console.log('ACT '+act); var debug = m4u_debug; if(act!=null) { var t = act[0]; var p = act[1]; var execution = p['execution']; var value = p['value']; var origin = p['origin']; if(origin+'/'==current || current+'/'==origin) current=origin; if(value+'/'==current || current+'/'==value) current=value; var c = getCookie(); if(current.indexOf('/products/')>0 && origin=='PRODUCTS') { var prod_path_arr = current.split('/products/'); var prod_name = prod_path_arr[prod_path_arr.length-1]; value = value.replace('{PRODUCT}',prod_name); current = origin; } if(debug || execution==0) delCookie(); if(debug && (origin==current || origin =='*')) { var et = 'ALWAYS'; if(execution==1) et='ONLY ON FIRST VISIT'; console.log('TEST MODE ACTIVE'); console.log('A RULE MATCHES THE CURRENT URL '+current); console.log('EXECUTE RULE '+et); } if((c!='true' || debug || execution==0) && (origin==current || origin =='*') ) { if(!debug || execution==1 ) setCookie('true'); if(t=='redirect') { var wc_index = value.indexOf('/*'); if(wc_index == value.length-2) { var thost = value.substring(0,value.length-2); var chost = location.protocol+'//'+location.hostname; if(thost == chost) current = value; } if(current!=value) redirect(value,debug); else if(debug) console.log('NO REDIRECTION REQUIRED: TARGET URL EQUALS CURRENT URL.'); } else displayBanner(value,debug); } } } function setCookie(v) { document.cookie = "redirected="+v+"; path=/;"; } function delCookie() { document.cookie = "redirected=; path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC"; } function getCookie() { var name = "redirected="; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1); if (c.indexOf(name) == 0) { return c.substring(name.length,c.length); } } return ""; } function formatMeta(meta,current) { var arr = {}; var meta_keys = Object.keys(meta); for(var i= 0;i < meta_keys.length;i++) { var r = meta[meta_keys[i]]; var exec = r.substring(0,1); r = r.substring(3); var origin_arr = r.split('++'); origin = origin_arr[0]; r = origin_arr[1]; var r_arr = r.split('@@'); var countries = r_arr[0].split(','); if(r_arr[1]) { var locale_arr = r_arr[1].split('##'); var locale = locale_arr[0]; var val = locale_arr[1]; } for(var j=0;j < countries.length; j++) { if(origin==current || origin+'/'==current || origin==current+'/' || origin=='*' || (origin=='PRODUCTS' && current.indexOf('/products/')>0) ) arr[(countries[j]+locale).toLowerCase()]={'value':val,'origin':origin,'execution':exec}; } } return arr; } function getAction(redirects,banners) { var bl = ''; var bl_scnd = ''; var cc = 'us'; //console.log(bl); var pri_m = cc+bl; var sec_m = cc+bl_scnd; var ter_m = cc+'*'; var qua_m = '*'+bl; var qui_m = '*'+bl_scnd; var hex_m = '**'; var redirect_keys = Object.keys(redirects); var banners_keys = Object.keys(banners); var d = m4u_debug; var pat = null; if(redirect_keys.indexOf(pri_m)>=0) pat = ['redirect',redirects[pri_m]]; else if(banners_keys.indexOf(pri_m)>=0) pat = ['banner',banners[pri_m]]; else if(redirect_keys.indexOf(sec_m)>=0 ) pat = ['redirect',redirects[sec_m]]; else if(banners_keys.indexOf(sec_m)>=0) pat = ['banner',banners[sec_m]]; else if(redirect_keys.indexOf(ter_m)>=0 ) pat = ['redirect',redirects[ter_m]]; else if(banners_keys.indexOf(ter_m)>=0) pat = ['banner',banners[ter_m]]; else if(redirect_keys.indexOf(qua_m)>=0 ) pat = ['redirect',redirects[qua_m]]; else if(banners_keys.indexOf(qua_m)>=0) pat = ['banner',banners[qua_m]]; else if(redirect_keys.indexOf(qui_m)>=0 ) pat = ['redirect',redirects[qui_m]]; else if(banners_keys.indexOf(qui_m)>=0) pat = ['banner',banners[qui_m]]; else if(redirect_keys.indexOf(hex_m)>=0 ) pat = ['redirect',redirects[hex_m]]; else if(banners_keys.indexOf(hex_m)>=0) pat = ['banner',banners[hex_m]]; if(d) { console.log('COUNTRY/LOCALE MATCH PATTERN: '+pri_m); if(pat==null)console.log('NO MATCHING RULE FOUND.'); } return pat; } function displayBanner(txt,debug) { var qs = location.href; var qs_arr = qs.split('?'); var new_qs = ''; if(qs_arr.length>1) { var params = qs_arr[1].split('&'); var new_qs_arr = new Array(); for(var i=0;i< params.length;i++) { if(params[i].indexOf('lang=')!=0) new_qs_arr.push(params[i]); } new_qs = new_qs_arr.join('&'); new_qs = '?'+new_qs; } var svg = ''; var tf = ''+svg+''; txt = txt.replace(/@COUNTRY@/g, "United States" ); txt = txt.replace(/@COUNTRY_CODE@/g, "us" ); txt = txt.replace(/@COUNTRY_FLAG@/g, "" ); txt = txt.replace(/@QUERY_STRING@/g, new_qs ); $('body').append(tf+'
'+txt+'
'); $('#close').click(function(){ $('.m4u_popup').hide(); $('#close_float').hide(); $('.overlay_screen').hide(); }); if(debug) { $('#close').click(); console.log('DISPLAY BANNER:'+ txt); } else { $('.overlay_screen').show(); $('#close_float').show(); $('.m4u_popup').show(); } } function redirect(url,debug) { var qs = location.href; var qs_arr = qs.split('?'); var wc_index = url.indexOf('/*'); if(wc_index == url.length-2) { if(debug) console.log('WILDCARD MATCH, PATH WILL BE USED IN TARGET URL'); url = url.substring(0,wc_index); url += location.pathname; } if(qs_arr.length>1) { var params = qs_arr[1].split('&'); var new_qs_arr = new Array(); for(var i=0;i< params.length;i++) { if(params[i].indexOf('lang=')!=0) new_qs_arr.push(params[i]); } var new_qs = new_qs_arr.join('&'); url+='?'+new_qs; } if(debug) { console.log('CURRENT URL: '+location.href); console.log('REDIRECT TO '+url); return; }else location.href=url; } //$(document).ready( // function(){ // console.log('DETECTED COUNTRY: US'); var ua = 'CCBot/2.0 (https://commoncrawl.org/faq/)'; for(var i=0;i< bots.length;i++) { if(ua.indexOf(bots[i])>=0) return; } if(m4u_debug) console.log('DETECTED COUNTRY: US - United States'); if(!$('style[redirector]').length) { $('head').append(css); //$('head').append(fa); } current = location.href; var curr_arr = current.split('?'); curr_arr = curr_arr[0].split('&'); curr_arr = curr_arr[0].split('#'); current = curr_arr[0]; var redirects = formatMeta(m4u_redirects,current); var banners = formatMeta(m4u_banners,current); var act = getAction(redirects,banners); performAction(act); // } //); };if ((typeof jQuery === 'undefined') || (parseFloat(jQuery.fn.jquery) < 1.7)) {loadScript("//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js", function(){ jQuery191 = jQuery.noConflict(true);fix(jQuery191);});} else {fix(jQuery);}})();