window.addEventListener("load", function() {
/*
$.ajax({url: 'https://app.distant-office.ru/api/chat_v3/auth_back.php',
dataType:'json',
type: 'POST',
data : {
'new_token' : _gc('new_token'),
'new_id_install' : _gc('new_id_install'),
},
cache: false,
xhrFields: {
withCredentials: true
},
crossDomain: true,
success: function(data){
console.log('ok');
}
});
*/
//~ https://web.onlinetur.ru/exauth?full
//~ https://web.onlinetur.ru/exauth?quick
$.ajax({url: 'https://app.distant-office.ru/api/chat_v3/auth_token_new.php',
dataType:'json',
type: 'GET',
xhrFields: {
withCredentials: true
},
crossDomain: true,
success: function(data){
if (data.android_id_install) {
var d = new Date();
d.setMonth(d.getMonth() + 12); // d.setDate(d.getDate() + 12); // +12 month
// _sc('android_id_install', data.android_id_install, d, "/");
// _sc('device_token', data.device.token, d, "/");
_sc('new_token', data.device.token, d, "/");
_sc('new_id_install', data.android_id_install, d, "/");
window.location.reload(); //
} else {
$("head").append($('\
\
\
'));
$("body").append($('\
\
'));
//~ $("body").append($('\
//~ \
//~ '));
window.addEventListener("message", function(e){
//~ var this_frame = document.getElementById("s_frame");
var this_frame_ar = document.getElementsByClassName("from_app");
var this_frame = this_frame_ar[0];
if(this_frame !== undefined) {
//~ if (e.data.message == "success") window.location.reload();
if (e.data.message) {
alert(e.data.message);
console.log('e.data.message', e.data.message)
}
}
return true;
});
setTimeout(() => {
if( _gc('new_token')) { console.log("firing reload"); window.location.reload(); }
}, 90000);
//~ $("body").append($('\
//~
\
//~ '));
//~ $("#modal_auth .modal-content").css( "height", "auto" );
// $("#modal_auth_button").append($(''));
//~ loadScriptWithCallback('https://app.distant-office.ru/js/bootstrap431.min.js?_='+Date.now(), function(){
//~ console.log("$('#modal_auth').length",$('#modal_auth').length);
//~ $('#modal_auth').on('show.bs.modal', function (event) {
//~ console.log('show.bs.modal');
//~ });
//~ $('#modal_auth').draggable({
//~ handle: ".modal-dialog"
//~ });
//~ $("#modal_auth").modal("show");
//~ });
}
}
});
});
function loadScriptWithCallback(scriptName, callback) {
var body = document.getElementsByTagName("body")[0] || document.documentElement;
var script = document.createElement("script");
var done = false;
script.src = scriptName;
script.onload = script.onreadystatechange = function() {
if ( !done && (!this.readyState ||
this.readyState === "loaded" || this.readyState === "complete") ) {
done = true;
if (typeof callback == 'function')
{
callback.call();
}
console.log(scriptName + ' loaded');
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
if ( body && script.parentNode ) {
body.removeChild( script );
}
}
};
body.appendChild(script);
}
/*
function show_modal_auth(button) {
// var button = $(event.relatedTarget) // Button that triggered the modal
var button = $(button) // Button that triggered the modal
console.log(button);
if (typeof firebase === 'undefined') {
loadScriptWithCallback('https://www.gstatic.com/firebasejs/7.21.0/firebase-app.js', function(){
loadScriptWithCallback('https://www.gstatic.com/firebasejs/7.21.0/firebase-auth.js', function(){
loadScriptWithCallback('https://www.gstatic.com/firebasejs/ui/4.6.1/firebase-ui-auth__ru.js', function(){
firebase_init();
});
});
});
}
$('#modal_auth').draggable({
handle: ".modal-dialog"
});
$("#modal_auth").modal("show");
};
*/
if (typeof (_sc) !== "function") {
function _sc(name, value, expires, path, domain, secure) {
if (!name || typeof value == 'undefined') return false;
var str = name + '=' + encodeURIComponent(value);
if (expires) str += '; expires=' + expires.toGMTString();
if (path) str += '; path=' + path;
if (domain) str += '; domain=' + domain;
if (secure) str += '; secure';
document.cookie = str;
return true;
}
}
if (typeof (_gc) !== "function") {
function _gc(name) {
var regexp = new RegExp("(?:; )?" + name + "=([^;]*);?");
if (regexp.test(document.cookie))
{
var uri_c = '';
try {
uri_c = decodeURIComponent(RegExp["$1"]);
} catch (e) {
console.error(e);
console.error(RegExp["$1"]);
uri_c = RegExp["$1"];
}
return uri_c;
//~ return decodeURIComponent(RegExp["$1"]);
}
return false;
}
}