!function() { "use strict"; var _W = window, _D = document, _C = _W.console; if( !_C ) _C = { log: function() {}, error: function() {} } _W.KRLC = { proto: function() { var e = _W.location && _W.location.protocol; return -1 === ["http", "https"].indexOf(e || "") && (e = "https:"), e }, ajaxGET: function( data, cb, cberr ){ var xhr = new XMLHttpRequest; xhr.onreadystatechange = function() { if( 4 === xhr.readyState ){ if( 200 === xhr.status ) { var res = xhr.responseType && "text" !== xhr.responseType ? "document" === xhr.responseType ? xhr.responseXML : xhr.response : xhr.responseText; try { res = _W.MooTools && void 0 === JSON.parse ? JSON.decode( res ) : JSON.parse( res ); } catch (e) { "function" == typeof cberr && cberr( 2, e.message ); return; } if( res ){ if( "undefined" != typeof res.d ) "function" == typeof cb && cb( res.d ); else if( "undefined" != typeof res.err ) "function" == typeof cberr && cberr( 4, res.err ); else "function" == typeof cberr && cberr( 5 ); }else "function" == typeof cberr && cberr( 3 ); }else "function" == typeof cberr && cberr( 1, xhr.status ); } } xhr.open( "GET", this.ajaxURL + data, !0 ); xhr.send( null ); } } var _LC = _W.KRLC; _LC._LS = !1; try{ if( _W.localStorage && "function" == typeof _W.localStorage.getItem ){ _W.localStorage.setItem( 'krlc_temp', 'test' ); _W.localStorage.removeItem( 'krlc_temp' ); _LC._LS = !0; }else _C.log( 'Local storage not set' ); } catch (e) { _C.log( 'Local storage access exception ' + e.name + ': ' + e.message ); } _LC._CK = !1; try{ document.cookie = "krlc_temp=test"; if( document.cookie.indexOf( "krlc_temp=test" ) !== -1 ){ _LC._CK = !0; document.cookie = "krlc_temp=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; }else _C.log( 'Cookie not set' ); } catch (e) { _C.log( 'Cookie access exception ' + e.name + ': ' + e.message ); } _LC.getItem = function( name ){ if( _LC._LS ){ return _W.localStorage.getItem( name ); }else if( _LC._CK ){ var cookies = _D.cookie ? _D.cookie.split('; ') : []; for( var i = 0; i < cookies.length; i++ ) { var parts = cookies[ i ].split( '=' ); var nm = parts.length && parts.length > 0 ? parts[ 0 ] : ''; if( nm == name ){ var val = parts.length && parts.length > 1 ? parts[ 1 ] : ''; return val ? val : ''; } } return undefined; }else return undefined; } _LC.setItem = function( name, value ){ if( _LC._LS ){ return _W.localStorage.setItem( name, value ); }else if( _LC._CK ){ _D.cookie = name + "=" + encodeURIComponent( value ) + "; expires=Tue, 31 Dec 2030 23:59:59 UTC; path=/"; }; } _LC.delItem = function( name ){ if( _LC._LS ){ return _W.localStorage.removeItem( name ); }else if( _LC._CK ){ _D.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; }; } _LC.clientID_itemName = 'krlc_' + _LC._ID + '_cid'; _LC.chatVisible_itemName = 'krlc_' + _LC._ID + '_chv'; if( !( _LC.clientID = _LC.getItem( _LC.clientID_itemName ) ) ) _LC.clientID = 0; _LC.head = _D.head || _D.getElementsByTagName("head")[0]; if( !_LC.head ) throw new Error("Cannot get document head element"); _LC._JS = _D.currentScript ? _D.currentScript : _D.querySelector( "script[krl]" ) || _D.querySelector( "script[data-krl]" ); var src = null, m; if( _LC._JS ){ src = _LC._JS.src; _LC._nonce = _LC._JS.nonce || _LC._JS.getAttribute( "nonce" ); }else{ try { throw new Error( "Get script URL" ) }catch( e ){ var r = e.stack; if( r ){ var i = r.match(/https?:\/\/\S+\/livechat\/\?c=([A-Za-z0-9]+)/); src = i ? i[ 0 ] : null; } } } if( src && ( m = src.match(/https?:\/\/(\S+)\/livechat\/\?c=([A-Za-z0-9]+)/) ) ){ _LC._URL = _LC.proto() + '//' + m[ 1 ] + '/livechat/'; _LC.ajaxURL = _LC._URL + '?w='; _C.log( 'nonce: ' + _LC._nonce ); _C.log( 'URL: ' + src ); _C.log( 'HOST: ' + m[ 1 ] ); _C.log( 'ID: ' + m[ 2 ] ); _C.log( 'URL: ' + _LC._URL ); _C.log( 'ajaxURL: ' + _LC.ajaxURL ); _LC.cfgHandler = function( res ){ _LC._ID = m[ 2 ]; _LC._CFG = res.cfg; _LC.sid = res.sid; _LC.clientID = res.cid; _LC.setItem( _LC.clientID_itemName, _LC.clientID ); _LC.psrc = res.psrc; _C.log( 'style: ' + res.style ); _C.log( 'bsrc: ' + res.bsrc ); _C.log( 'psrc: ' + res.psrc ); var el = _D.createElement( 'link' ); el.rel = 'stylesheet'; el.href = _LC.proto() + res.style; _LC.head.appendChild( el ); el = _D.createElement( 'script' ); el.src = res.bsrc; el.type = "text/javascript"; el.async = !0; el.charset = "UTF-8"; if( _LC._nonce ) el.setAttribute( "nonce", _LC._nonce ); _LC.head.appendChild( el ); _LC.cfgHandler = null; _LC.cfgGet = null; }; _LC.cfgGet = function(){ _LC.ajaxGET( 'init&c=' + m[ 2 ] + '&cid=' + _LC.clientID, _LC.cfgHandler, function( code, data = '' ){ _C.error( 'AJAX GET(1) config: [' + code + '] ' + data ); code != 4 && _LC.ajaxGET( 'init&c=' + m[ 2 ] + '&cid=' + _LC.clientID, _LC.cfgHandler, function( code, data = '' ){ _C.error( 'AJAX GET(2) config: [' + code + '] ' + data ); setTimeout( _LC.cfgGet, 2000 ); }); }); } _LC.cfgGet(); }else _C.error( 'Get script URL' ); }();