var LORurl='https://api.lortechnologies.com' var lor_companyid='922' // Chat //////////////////////////////////////////////////// var monitor_xmlcaller var msgqueue = {} var msgseq = 0; var msgid = 0; var typinginterval; var currchatid = 0 var lor_activityid var websocketconnected=false var screeninterval var screenimg var screencan //window.onfocus = function () { if (lor_activityid) chatstatus();log('refreshing chat status') } var chatbar var monitor_sessionid var perm_sessionid var inlinecss = 1 var lor_cansendscreen=false var lor_havesentscreen =false var lor_loaded = false var lor_waiting = false if (window.CSS && CSS.supports('color', 'var(--fake-var)')) { inlinecss = 1 } else { inlinecss = 0 } var lor_mutationObserver = new MutationObserver(function (mutations) { lor_mutationObserver.disconnect(); lor_havesentscreen=false // mutations.forEach(function (mutation) { // console.log(mutation); // }); }); window.addEventListener("DOMContentLoaded", lor_init) if (document.readyState === 'interactive' || document.readyState === 'complete') lor_init() var lor_scrollTimeout function lor_init() { if (lor_loaded) return lor_loaded = true chatbar = document.createElement('div') chatbar.id="lor_chatbar" document.body.appendChild(chatbar) var sessionid = lor_getCookie("lor_sessionid") if (!sessionid) { sessionid = (parseInt(Math.random()*1000000)).toString() + '-' + Date.now() lor_setCookie("lor_sessionid",sessionid,1) } monitor_sessionid = sessionid; sessionid = lor_getCookie("lor_p_sessionid") if (!sessionid) { sessionid = (parseInt(Math.random() * 1000000)).toString() + '-' + Date.now() lor_setCookie("lor_p_sessionid", sessionid, 365) } perm_sessionid = sessionid; connectWebsock() window.addEventListener('scroll', function () { window.clearTimeout(lor_scrollTimeout); lor_scrollTimeout=window.setTimeout(lor_sendscreenpos,100) }) } var retryinterval = 500 var hasregistered = false; var ws_lor function connectWebsock() { try { ws_lor = new WebSocket(LORurl.replace('https', 'wss').replace('http', 'ws') + "/ws/?from=user&sessionguid=" + monitor_sessionid); ws_lor.onopen = function () { log('websock connected') retryinterval = 500 websocketconnected = true if (!hasregistered) startActivity(window.lor_activity) if (lor_activityid) chatstatus() }; ws_lor.onmessage = function (m) { pollResponse(m.data) } ws_lor.onerror = function (errorEvent) { log('WebSocket Status:: Error was reported: ' + LORurl.replace('https', 'wss').replace('http', 'ws') + "/ws/?from=user&sessionguid=" + monitor_sessionid); }; ws_lor.onclose = function (closeEvent) { log('WebSocket Status:: Socket Closed'); websocketconnected = false retryinterval *= 2 //progressive backoff if (retryinterval < 40000) window.setTimeout(function () { connectWebsock() }, retryinterval) }; } catch (wse) { log('There was a problem connecting to the server. LOR cannot function.') //if (thenrun) thenrun() } } function startActivity(msg) { hasregistered = true lor_havesentscreen = false; if (!msg) { var img = { src: '' } msg = { dealercode: '0', title: document.title, description: window.location.host + window.location.pathname, thumbnail: img.src } } msg["type"] = 'activity' msg["companyid"] = lor_companyid msg["dealerid"] = msg["dealerid"] || msg["dealercode"] msg["carid"] = msg["productid"]; msg["page"] = msg["source"]; var url = LORurl + '/poll.aspx?sessionGUID=' + monitor_sessionid + '&url=' + encodeURIComponent(window.location.href) + '&tm=' + new Date().getTime(); var xhr = createCORSRequest('POST', url); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); if (!xhr) return; xhr.onload = function () { if (lor_waiting) { var xresp = xhr.responseText if (xresp == '') return; if (xresp == 'NO_LOR') return; lor_cansendscreen=true lor_activityid = JSON.parse(xhr.responseText)["activityid"]; if (!doc('lor_css')) { var link = document.createElement("link"); link.href = LORurl + '/config/style_frontend.css?inlinecss=' + inlinecss + '&cid=' + lor_companyid + '&tmp=' + Date.now(); link.type = "text/css"; link.rel = "stylesheet"; link.media = "screen,print"; link.id = "lor_css" document.getElementsByTagName("head")[0].appendChild(link); } if (currchatid == 0 && window.lor_activityid) { // lor_http(LORurl + '/chat_user.xsl?fx_raw=yes&fx_action=status&activityid=' + lor_activityid + '&permguid=' + perm_sessionid, function (xmlcaller) { // doc('lor_chatbar').innerHTML = xmlcaller.responseText // doc('lor_chaticon').style.transform='scale(2)' // }) chatstatus() } } } lor_waiting = true; xhr.send('msg=' + escape(JSON.stringify(msg))) //window.setTimeout(lor_sendscreen, 300) } function registerActivity(action, thumbnail) { if (action=='photo') return if (!websocketconnected || !lor_activityid) return; var msg = {} msg["type"] = 'action' msg["activityid"] = lor_activityid msg["action"] = action msg["thumbnail"] = thumbnail var url = LORurl + '/poll.aspx?sessionGUID=' + monitor_sessionid + '&tm=' + new Date().getTime(); var xhr = createCORSRequest('POST', url); try { xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); } catch (e) { } if (!xhr) return; xhr.onload = function () { }//callback((xhr.status==200)); xhr.send('msg=' + escape(JSON.stringify(msg))) log(JSON.stringify(msg)) } function endActivity() { lor_havesentscreen = true; lor_activityid = "0"; lor_waiting = false; lor_mutationObserver.disconnect(); if (!websocketconnected || !lor_activityid) return; sendmsg({ type: 'endactivity', activityid: lor_activityid }) if (currchatid == 0) chatbar.innerHTML = "" } function lor_closechat() { //document.body.removeChild(chatbar) } function pollResponse(messagetext) { log('RECEIVED: ' + messagetext) var msg = JSON.parse(messagetext) if (chatbar) {// && doc('chatbox').getAttribute('data-carid') == msg.carid if (msg.type == 'activityreceived') { if (!doc('lor_canvas')) { var h2c = document.createElement("script"); h2c.src = LORurl + '/html2canvas.min.js?' + Date.now(); h2c.defer = "true" h2c.async = "true" h2c.id = "lor_canvas" document.getElementsByTagName("head")[0].appendChild(h2c); } window.setTimeout(lor_sendscreen, 1000) } if (msg.type == 'chataccept') chatload(msg) if (msg.type == 'chatdecline') chatload(msg) if (msg.type == 'chatload') chatload(msg) if (msg.type == 'chatcallback') chatload(msg) if (msg.type == 'adhocchatcallback') chatload(msg) if (msg.type == 'chatended') chatload(msg) if (msg.type == 'chatrequest') { lor_activityid = msg.activityid; currchatid = msg.chatid; chatload(msg) } if (msg.type == 'chatmsg') chatmsg(msg) if (msg.type == 'sendcontact') lor_sendcontact(msg) if (msg.type == 'sendform') lor_sendform(msg) if (msg.type == 'updatecontact') lor_updatecontact_received(msg) if (msg.type == 'updateform') lor_updateform_received(msg) if (msg.type == 'reachout') chatload(msg) if (msg.type == 'typing') if (doc('typingdiv')) doc('typingdiv').innerHTML = (msg.istyping == 'yes') ? doc('typingdiv').getAttribute('data-othername') + ' is typing...' : '' if (msg.type == 'videochat') lor_videochat_start(msg) if (msg.type == 'voicecall_connected') doc('lor_voicecall_getnumber').style.display = 'none'; if (msg.type == 'killvideochat') if (doc('lor_videodiv')) doc('lor_videodiv').parentElement.removeChild(doc('lor_videodiv')); } if (msg.type == 'chatstatus') chatstatus() if (msg.type == 'chatready') chatready(msg) if (msg.type == 'fileupload') uploadreceive(msg) } function uploadreceive(msg) { var div = document.createElement('div') var filehref = document.createElement('a') filehref.href = LORurl + '/files/' + monitor_sessionid + '/' + msg.filename //filehref.download = msg.filename filehref.target = "_blank" if (msg.filename.indexOf('.png') > 0 || msg.filename.indexOf('.jpg') > 0 || msg.filename.indexOf('.webp') > 0 || msg.filename.indexOf('.jpeg') > 0) { var img = document.createElement("img") img.src = LORurl + '/files/' + monitor_sessionid + '/' + msg.filename img.style.cssText = "width:80%;border-radius:5px;" filehref.appendChild(img) } else filehref.innerHTML = msg.filename div.appendChild(filehref) msg.usermessage = div.innerHTML chatmsg(msg) } function ShowChatForm() { lor_http(LORurl + '/chat_user.xsl?fx_raw=yes&fx_action=entername&activityid=' + lor_activityid, function (xmlcaller) { chatbar.innerHTML = xmlcaller.responseText; }); } function lor_callbackform() { lor_http(LORurl + '/chat_user.xsl?fx_raw=yes&fx_action=callbackform&activityid=' + lor_activityid, function (xmlcaller) { chatbar.innerHTML = xmlcaller.responseText; }); } function HideChatForm() { currchatid = 0; chatbar.innerHTML = ""; chatstatus(); } function dismissChat() { doc('lor_chaticon').style.display = 'none' doc('lor_chaticon_small').style.display='block' lor_setCookie('hidechat',true,1) } function sendmsg(msg) { msg.msgseq = (msg.msgseq || ++msgseq) msg.from = 'user'; msg.to = 'dealer' msg.activityid = lor_activityid log('SEND: ' + JSON.stringify(msg)) lor_http(LORurl + '/poll.aspx?action=sendmsg&sessionGUID=' + monitor_sessionid + '&permguid=' + perm_sessionid + '&msg=' + escape(JSON.stringify(msg)), function (xhr) { }) } var bounceinterval function chatstatus() { if (!currchatid) { lor_http(LORurl + '/chat_user.xsl?fx_raw=yes&fx_action=status&guid=' + monitor_sessionid + '&permguid=' + perm_sessionid + '&activityid=' + lor_activityid, function (xmlcaller) { chatbar.innerHTML = xmlcaller.responseText if (doc('lor_chaticon')) { if (lor_getCookie('hidechat') == 'true') dismissChat() chatbounce() clearInterval(bounceinterval) bounceinterval=setInterval(chatbounce, 5000) } }) } else { lor_http(LORurl + '/chat_user.xsl?fx_raw=yes&fx_action=status&guid=' + monitor_sessionid + '&permguid=' + perm_sessionid + '&from=user&activityid=' + lor_activityid + '&chatid=' + currchatid, function (xmlcaller) { chatbar.innerHTML = xmlcaller.responseText }) } } function chatbounce() { if (doc('lor_chaticon')) { var anim = new Promise(function (resolve) { setTimeout(() => { doc('lor_chaticon').style.transform = 'scale(1.1)'; resolve(); }, 100) }) anim.then(function (resolve) { setTimeout(() => { doc('lor_chaticon').style.transform = 'scale(1)'; }, 200) }) } else { clearInterval(bounceinterval) } } function chatrequest(answerid) { if (doc('chatname').value == '') { alert('Please enter your name') return; } if (doc('chatemail').value == '') { alert('Please enter your email address') return; } var date = new Date(); date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000)); document.cookie = "chatname=" + doc('chatname').value + "; expires=" + date.toGMTString() + "; path=/"; document.cookie = "chatemail=" + doc('chatemail').value + "; expires=" + date.toGMTString() + "; path=/"; sendmsg({ type: 'chatrequest', chatname: doc('chatname').value, chatemail: doc('chatemail').value , answerid: answerid||'' }) } function chatload(msg) { if (msg.type == 'reachout') { lor_http(LORurl + '/chat_user.xsl?fx_raw=yes&from=user&to=dealer&fromguid=' + msg.from_sessionguid + '&fx_action=prompt&text=' + encodeURIComponent(msg.text), function (xmlcaller) { chatbar.innerHTML = xmlcaller.responseText if (doc('lor_endofchat')) doc('lor_endofchat').scrollIntoView() }) return; } if (msg) { //if (msg['type'] == 'chatended') // currchatid = 0; //else currchatid = msg.chatid } //if (msg && msg.status && msg.status == 'Declined') currchatid = 0; if (doc('lor_videodiv')) doc('lor_videodiv').parentElement.removeChild(doc('lor_videodiv')); lor_http(LORurl + '/chat_user.xsl?fx_raw=yes&from=user&to=dealer&chatid=' + currchatid, function (xmlcaller) { chatbar.innerHTML = xmlcaller.responseText if (doc('lor_endofchat')) doc('lor_endofchat').scrollIntoView() }) } function sendchat() { var chatid = doc('lor_chatwindow').getAttribute('data-chatid') var txt = doc('chatmessagebox').value doc('chatmessagebox').value = "" if (txt != '') { var msg = { type: 'chatmsg', chatid: chatid, message: txt, target: 'both' } sendmsg(msg) } dotyping(); } function lor_sendcontact(msg) { if (doc('lor_contactform')) doc('lor_contactform').parentElement.removeChild(doc('lor_contactform')) var contactform = document.createElement('div') lor_http(LORurl + '/chat_user.xsl?fx_raw=yes&fx_action=contactform', function (xmlcaller) { contactform.innerHTML = xmlcaller.responseText doc('chathistorydiv').insertBefore(contactform, doc('typingdiv')) if (doc('lor_endofchat')) doc('lor_endofchat').scrollIntoView() }) } function lor_sendform(msg) { var chatid = doc('lor_chatwindow').getAttribute('data-chatid') if (doc('lor_fieldform')) doc('lor_fieldform').parentElement.removeChild(doc('lor_fieldform')) var fieldform = document.createElement('div') lor_http(LORurl + '/chat_user.xsl?fx_raw=yes&fx_action=fieldform&chatid=' + chatid + '&fieldid=' + msg["fieldid"], function (xmlcaller) { fieldform.innerHTML = xmlcaller.responseText doc('chathistorydiv').insertBefore(fieldform, doc('typingdiv')) if (doc('lor_endofchat')) doc('lor_endofchat').scrollIntoView() }) } function lor_updatecontact() { var chatid = doc('lor_chatwindow').getAttribute('data-chatid') if (doc('lor_contact_tel').value.length < 10 || doc('lor_contact_email').value.length < 10) { doc('lor_contact_errormessage').style.display = 'block' return; } doc('lor_contact_errormessage').style.display = 'none' var msg = { type: 'updatecontact', chatid: chatid, chatname: doc('lor_contact_name').value, tellno: doc('lor_contact_tel').value, email: doc('lor_contact_email').value, target: 'both' } sendmsg(msg) } function lor_updateform() { var formvalues=[] var fields = document.getElementsByClassName('lor_forminput') for (var n = 0; n < fields.length; n++) { formvalues.push({ fieldid: fields[n].getAttribute('data-fieldid'), value: fields[n].value }) } var chatid = doc('lor_chatwindow').getAttribute('data-chatid') var msg = { type: 'updateform', chatid: chatid, target: 'both' } lor_http(LORurl + '/poll.aspx?action=sendmsg&sessionGUID=' + monitor_sessionid + '&msg=' + escape(JSON.stringify(msg)) + '&form=' + escape(JSON.stringify(formvalues)), function () { }) } function lor_updatecontact_received() { doc('lor_contact_updatetable').style.display = 'none' doc('lor_contact_received').style.display = 'block' } function lor_updateform_received() { doc('lor_form_updatetable').style.display = 'none' doc('lor_form_received').style.display = 'block' } function lor_callback() { var chatid = doc('lor_chatwindow').getAttribute('data-chatid') if (doc('lor_callback_tel').value.length < 10 && doc('lor_callback_email').value.length < 10) { doc('lor_callback_errormessage').style.display = 'block' return; } doc('lor_callback_errormessage').style.display = 'none' var jobid = 0; var jobs = document.getElementsByName('lor_jobtitle') for (var n = 0; n < jobs.length; n++) { if (jobs[n].checked) jobid=jobs[n].value } var msg = { type: 'chatcallback', chatid: chatid, tellno: doc('lor_callback_tel').value, email: doc('lor_callback_email').value, callbackmessage: doc('lor_callbackmessage').value, jobid:jobid, target: 'both' } sendmsg(msg) } function lor_adhoccallback() { if (doc('lor_callback_tel').value.length < 10 && doc('lor_callback_email').value.length < 10) { doc('lor_callback_errormessage').style.display = 'block' return; } doc('lor_callback_errormessage').style.display = 'none' var jobid = 0; var jobs = document.getElementsByName('lor_jobtitle') for (var n = 0; n < jobs.length; n++) { if (jobs[n].checked) jobid=jobs[n].value } var msg = { type: 'adhocchatcallback', chatname: doc('lor_callback_name').value, tellno: doc('lor_callback_tel').value, email: doc('lor_callback_email').value, callbackmessage: doc('lor_callbackmessage').value, jobid: jobid } sendmsg(msg) } var flasher var flashinterval function chatmsg(msg) { var name = (msg.from == 'dealer') ? doc('typingdiv').getAttribute('data-othername') : "Me"; var newmsg = document.createElement('DIV') //newmsg.style.marginBottom = '10px' //if (msg.from != 'dealer') newmsg.style.color = '#486da1' if (msg.from == 'dealer') { newmsg.innerHTML = doc('dealerchatbox_template').innerHTML.replace('***', name).replace('$$$', msg.usermessage) lor_flashbar() } else { newmsg.innerHTML = doc('userchatbox_template').innerHTML.replace('$$$', msg.usermessage) } doc('chathistorydiv').insertBefore(newmsg, doc('typingdiv')) if (msg.from == 'dealer') doc('typingdiv').innerHTML = '' if (doc('chathistorydiv')) { doc('chathistorydiv').scrollTop = doc('chathistorydiv').scrollHeight; } } function lor_flashbar() { if (doc('flickImage').getAttribute('data-out') != 'yes') { // flick the title bar to show a new message has arrived. flasher = 4 flashinterval = window.setInterval(function () { doc('lor_chatnamebar').style.backgroundColor = (doc('lor_chatnamebar').style.backgroundColor == 'powderblue') ? 'black' : 'powderblue' flasher--; if (flasher < 0) window.clearInterval(flashinterval) }, 200) } } function chatready(msg) { if (doc('chatbox') && doc('chatbox').getAttribute('data-carid') == msg.carid) { ShowChatForm(msg.carid, msg.name, msg.dealerid) alert('The dealer you are holding for is now available to chat.') } else { if (confirm('The dealer you are holding for is now available to chat. Ok to open a chat?')) { openShowroomList(msg.carid); ShowChatForm(msg.carid, msg.name, msg.dealerid) } } } function dotyping() { var istyping = (doc('chatmessagebox').value == '') ? 'no' : 'yes' var wastyping = doc('chathistorydiv').getAttribute('data-wastyping') if (istyping != wastyping) sendmsg({ type: 'typing', istyping: istyping, to_sessionguid: doc('chathistorydiv').getAttribute('data-from_sessionid'), chatid: doc('lor_chatwindow').getAttribute('data-chatid') }) doc('chathistorydiv').setAttribute('data-wastyping', istyping); } function chatfeedback(chatid) { var msg = { type: 'chatfeedback', chatid: chatid } var inputs = doc('chatfeedbackdiv').getElementsByTagName('INPUT') for (var n = 0; n < inputs.length; n++) { if (inputs[n].checked) msg[inputs[n].name] = inputs[n].value; } if (doc('chatemaildiv').style.display!='none') { if (doc('chatemail').value == '') { alert('Please enter your email address if you want to receive a transcript.') doc('chatemail').style.border = '2px solid red' return } msg["chatemail"] = doc('chatemail').value } msg["chatcomment"] = doc('chatcomment').value currchatid = msg.chatid sendmsg(msg) HideChatForm() } function chatend(msg) { if (doc('lor_videodiv')) doc('lor_videodiv').parentElement.removeChild(doc('lor_videodiv')) currchatid = msg.chatid sendmsg(msg, chatload) } function flickChat(elem) { if (elem.getAttribute('data-out') == 'yes') { doc('lor_chatwindow').style.height = '60px' doc('flickImage').src = elem.getAttribute('data-imageroot') + 'uparrow.png' elem.setAttribute('data-out', 'no') } else { doc('lor_chatnamebar').style.backgroundColor = 'black' doc('lor_chatwindow').style.height = '450px' doc('flickImage').src = elem.getAttribute('data-imageroot') + 'downarrow.png?2' elem.setAttribute('data-out', 'yes') } } function lor_videochat() { if (hasGetUserMedia() || true) { var msg = { type: 'videochat', chatid: doc('lor_chatwindow').getAttribute('data-chatid') } sendmsg(msg) } else alert('Your browser does not support video calling') } function lor_videochat_start(msg) { if (doc('lor_videodiv')) doc('lor_videodiv').parentElement.removeChild(doc('lor_videodiv')) lor_http(LORurl + '/video.aspx?videochatguid=' + msg["videochatguid"], function (xmlcaller) { var viddiv = document.createElement('DIV') viddiv.id = "lor_videodiv" viddiv.innerHTML = xmlcaller.responseText document.body.appendChild(viddiv) document.body.focus() }) } function killvideochat() { if (doc('lor_videodiv')) doc('lor_videodiv').parentElement.removeChild(doc('lor_videodiv')) var msg = { type: 'killvideochat', chatid: doc('lor_chatwindow').getAttribute('data-chatid') } sendmsg(msg) } function lor_voicecall() { if (doc('lor_voicecall_getnumber')) doc('lor_voicecall_getnumber').parentElement.removeChild(doc('lor_voicecall_getnumber')) var newmsg = document.createElement('DIV') newmsg.id = 'lor_voicecall_getnumber' newmsg.style.marginBottom = '10px' newmsg.style.clear='both' newmsg.innerHTML = doc('lor_callback').innerHTML newmsg.getElementsByClassName('lor_phoneerror')[0].id = 'lor_phoneerror' newmsg.getElementsByClassName('lor_tellno')[0].id = 'lor_tellno' newmsg.getElementsByClassName('lor_connectingcall')[0].id = 'lor_connectingcall' newmsg.getElementsByClassName('lor_connectingcallbutton')[0].id = 'lor_connectingcallbutton' doc('chathistorydiv').insertBefore(newmsg, doc('typingdiv')) if (doc('chathistorydiv')) { doc('chathistorydiv').scrollTop = doc('chathistorydiv').scrollHeight; } } function lor_startcall() { doc('lor_phoneerror').style.display = 'none' if (doc('lor_tellno').value.length < 10) { doc('lor_phoneerror').style.display = 'block' return } var msg = { type: 'voicecall', userphone: doc('lor_tellno').value, chatid: doc('lor_chatwindow').getAttribute('data-chatid') } doc('lor_voicecall_getnumber').getElementsByClassName('lor_connectingcall')[0].style.display='block' doc('lor_voicecall_getnumber').getElementsByClassName('lor_connectingcallbutton')[0].style.display = 'none' sendmsg(msg); } function lor_uploadfile() { var frm = new FormData() frm.append("file", doc('lor_file').files[0]) var msg = { type: 'fileupload', chatid: doc('lor_chatwindow').getAttribute('data-chatid'), from: 'user' } frm.append("msg", JSON.stringify(msg)) var xhr = createCORSRequest('post', LORurl + "/poll.aspx?sessionGUID=" + monitor_sessionid) xhr.upload.addEventListener("progress", lor_prg, false); xhr.onloadstart = function (e) { console.log("start") } xhr.onload = function (pm) { return function () { if (pm.status == '200') { } else { var newmsg = document.createElement('DIV') newmsg.id = 'lor_uploaddiv' newmsg.style = "margin-bottom:10px;font-weight:bold;border:1px solid gainsoboro;border-radius:5px;padding:5px" doc('chathistorydiv').insertBefore(newmsg, doc('typingdiv')) window.setTimeout(function () { doc('lor_uploaddiv').parentElement.removeChild(doc('lor_uploaddiv')) },3000) } }}(xhr) xhr.send(frm); } function lor_dorating(ratingtype) { var radios = document.querySelectorAll('.lor_' + ratingtype) var foundchecked=false for (var n = 0; n < radios.length; n++) { doc('lor_' + ratingtype + 'img_' + n).src = doc('lor_' + ratingtype + 'img_' + n).src.replace('rate_full','rate_open') if (radios[n].checked) { for (var i = 0; i < n+1; i++) { doc('lor_' + ratingtype + 'img_' + i).src = doc('lor_' + ratingtype + 'img_' + i).src.replace('rate_open','rate_full') } } } } /////////////////////////////////////////////////////////////// var lor_screencache=null function lor_sendscreen(force) { log('sending: can-' + lor_cansendscreen + " havesent-" + lor_havesentscreen) if (!lor_cansendscreen && !force) return if (lor_havesentscreen && !force) return lor_havesentscreen=true if (!window.html2canvas) { lor_havesentscreen=false screeninterval = window.setTimeout(lor_sendscreen, 500) return; } if (doc('lor_chatwindow')) { lor_observe() return; } var imgs = document.body.getElementsByTagName('img') var anyfail=false for (var n = 0; n < imgs.length; n++) { try { var imgurl = new URL(imgs[n].src) //log(imgurl.href) if (imgurl.hostname != window.location.hostname && !LORurl.includes(imgurl.hostname) && !imgurl.href.includes('.svg') && !imgurl.href.includes('data:') && !imgurl.href.includes('google')) { anyfail = true if (!imgs[n].fetching) { imgs[n].fetching=true var xhr = createCORSRequest('GET', LORurl + '/getimage.aspx?url=' + encodeURIComponent(imgs[n].src) + '&xsd'); if (!xhr) return; xhr.img = imgs[n] xhr.onload = function (xhr) { return function () { //log(xhr.img) if (xhr.responseText!="") xhr.img.src = xhr.responseText } }(xhr) xhr.send() } } } catch (imge) { } } if (anyfail) { screeninterval = window.setTimeout(function () { lor_sendscreen(true) }, 2000) return; } html2canvas(document.body, { scale: 200/window.innerWidth }).then(function (canvas) { var dataurl = canvas.toDataURL('image/jpeg', 1) if (dataurl != lor_screencache) { var url = LORurl + '/poll.aspx?sessionGUID=' + monitor_sessionid + '&tm=' + new Date().getTime(); var form = new FormData() var msg = { "type": 'screen', "activityid": lor_activityid, "data": dataurl, scrollX: window.scrollX, scrollY: window.scrollY, width: window.innerWidth, height: window.innerHeight } form.append("msg", JSON.stringify(msg)); lor_postform(url, form) lor_screencache=dataurl } lor_observe() }); } function lor_observe() { lor_mutationObserver.observe(document.documentElement, { attributes: true, //characterData: true, childList: true, subtree: true, //attributeOldValue: true, // characterDataOldValue: true }); } function lor_sendscreenpos() { if (!lor_cansendscreen) return var url = LORurl + '/poll.aspx?sessionGUID=' + monitor_sessionid + '&tm=' + new Date().getTime(); var form = new FormData() var msg = { "type": 'screen', "activityid": lor_activityid, scrollX: window.scrollX, scrollY: window.scrollY, width: window.innerWidth, height: window.innerHeight } form.append("msg", JSON.stringify(msg)); lor_postform(url, form) } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function lor_prg(e) { if (e.lengthComputable) { doc('lor_uploaddiv').innerHTML = (Math.round(e.loaded / 1024)) + "KB / " + (Math.round(e.total / 1024)) + "KB (" + (Math.round(e.loaded / e.total * 100)) + "%)" console.log(e.loaded + " / " + e.total) } } function createCORSRequest(method, url) { var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { xhr.open(method, url, true); } else if (typeof XDomainRequest != "undefined") { xhr = new XDomainRequest(); xhr.open(method, url); } else { xhr = null; } return xhr; } function lor_http(url, callback) { url = url + ((url.indexOf('?') > -1) ? '&' : '?') url = url + new Date().getTime() var xhr = createCORSRequest('GET', url); if (!xhr) { return; } xhr.onload = function () { callback(xhr) } xhr.send() } function lor_postform(page, frm, callback) { var xhr = new XMLHttpRequest(); xhr.open("post", page, true); xhr.onload = function (xhr) { return function () { if (xhr.status == '200') { if (callback) callback(xhr) } } }(xhr) xhr.send(frm); } function doc(id) { var elems = document.querySelectorAll("[id='" + id + "']") if (elems.length > 0) return elems[elems.length - 1]; else return null } function log() { if (window.console && (window.location.href.indexOf('//me.') > 0 || window.location.href.indexOf('//x') > -1)) { for (var n = 0; n < arguments.length; n++) { var msg = arguments[n] if (typeof (msg) == 'object' && console.dirxml) try { console.dirxml(msg) } catch (e) { } else try { console.log(msg) } catch (e) { } } } } function hasGetUserMedia() { return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia); } function lor_setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (encodeURIComponent(value) || "") + expires + "; path=/"; } function lor_getCookie(name) { var nameEQ = name + "="; 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, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } function eraseCookie(name) { document.cookie = name + '=; Max-Age=-99999999;'; }