function onRecaptchaLoadCallback() { window.ufApp.gRecaptchaVerify(); } (function (d, domainPath, query, injectPath) { function _ufApp(domainPath) { this.domainPath = domainPath; this.soAlreadyAttached = false; this.gRecaptchaClientKey = null; this.tScoreId = null; this._query = query; this.redirect = function (url) { window.location.replace(url); }; this.sendXMLGetRequest = function (url, cb) { var xhr; if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { try { xhr = new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP") } catch (e) { return; } } } xhr.open("GET", url, true); xhr.onload = function() { if (xhr.readyState === 4 && xhr.status === 200) { try { var json = JSON.parse(xhr.responseText); cb(null, json); } catch(err){ cb(err); } } else { cb(new Error('Got error response.')); } }; xhr.send(); }; this.attachBo = function (url) { var w = window || null; w && w.history && w.history.pushState && w.history.pushState(null, null, w.location); w && w.addEventListener && w.addEventListener('popstate', function () { w.location = url; } , !1); }; this.gRecaptchaVerify = function () { var self = this; var w = window || null; grecaptcha.execute(self.gRecaptchaClientKey, {action: 'homepage'}) .then(function (token) { var urlToXML = self.domainPath + "/v1/recaptcha/token/" + w.location.hostname + "/" + token + '/' + self.tScoreId; self.sendXMLGetRequest(urlToXML, function (err, response) { if (w.ufApp && w.ufApp.integration && typeof w.ufApp.integration.onDone ==='function'){ w.ufApp.integration.onDone('recaptcha'); } }); }) }; this.gRecaptchaInject = function (clientKey, tScoreId) { this.gRecaptchaClientKey = clientKey; this.tScoreId = tScoreId; this.attachScript('https://www.google.com/recaptcha/api.js?render=' + clientKey + '&onload=onRecaptchaLoadCallback'); }; this.attachSo = function (url, or, to, rpl) { if (this.soAlreadyAttached === true && rpl !== true){ return; } var timeout = to || 100; var aOr = ['back', 'front']; var order = or && aOr.indexOf(or) !== -1 ? or : 'back'; var self = this; var els = d.querySelectorAll('a'); function bindSo(el, soUrl, order) { var originalUrl = el.href; if (order === 'front') { var tmpUrl = soUrl; soUrl = originalUrl; originalUrl = tmpUrl; } if (soUrl && self.validateUrl(soUrl) && originalUrl && self.validateUrl(originalUrl)) { self.soAlreadyAttached = true; el.setAttribute('target', "_blank"); el.setAttribute('onclick', "url='" + soUrl + "';setTimeout('location.href=url'," + timeout + ");this.href='" + originalUrl + "';"); } } for (var idx in els) { var el = els[idx]; (function(){ bindSo(el, url, order); })(el, url, order); } }; this.validateUrl = function validateUrl(value) { if (value && value.indexOf('localhost') !== -1 ) { return true; } if (value && value.indexOf('127.0.0.1') !== -1 ) { return true; } return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value); }; this.attachScript = function (url) { var head = d.getElementsByTagName('head')[0]; var script = d.createElement('script'); script.type = 'text/javascript'; script.src = url; script.async = 1; script.defer = true; head.appendChild(script); }; this.getIntegrationScriptUrl = function (functional, placement, doc_location, referrer, query) { if (!functional){ return; } if (!placement){ return; } if (!doc_location){ doc_location = encodeURIComponent(window.location.toString()); } if (doc_location){ doc_location = encodeURIComponent(doc_location); } if (!referrer){ referrer = document.referrer || ''; } if (referrer){ referrer = encodeURIComponent(referrer); } if (referrer === doc_location){ referrer = null; } var url = window.ufApp.domainPath + '/' + injectPath + '/' + functional +'.js?placement=' + placement + '&referer=' + referrer + '&' + 'doc_location=' + doc_location + '&' + query; // function parseQuery(queryString) { // var query = {}; // var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&'); // for (var i = 0; i < pairs.length; i++) { // var pair = pairs[i].split('='); // query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); // } // return query; // } // // console.log('getIntegrationScriptUrl:', url); // console.log('parseQuery:', parseQuery('placement=' + placement + '&referer=' + referrer + '&' + 'doc_location=' + doc_location + '&' + query)); return url; }; function Integration(config){ this._config = config; this.apply = function(parent){ if (window.ufApp.integration._config.integrationFunctional.indexOf('recaptcha') !== -1){ if (parent && parent.stop && typeof parent.stop ==='function' && typeof parent.getUrl ==='function'){ parent.stop(); window.ufApp.integration._url = parent.getUrl(); var integrationUrl = window.ufApp.getIntegrationScriptUrl('recaptcha',window.ufApp.integration._config.placement, encodeURIComponent(window.ufApp.integration._url), null, null); window.ufApp.attachScript(integrationUrl); } } }; this.onDone = function(initiator){ if (initiator ==='recaptcha'){ window.ufApp.redirect(window.ufApp.integration._url); } }; } this.initIntegration = function(config){ this.integration = new Integration(config); }; }; window.ufApp = new _ufApp(domainPath); var scripts = []; scripts.push(window.ufApp.getIntegrationScriptUrl("webpush", "lp", null,null, query)); for (var idx in scripts) { window.ufApp.attachScript(scripts[idx]); } })(document, "https://retargetcore.com", "dp=481c4d55f88aa3ecf4d5bef36196da8f", "c_js");