diff --git a/3CX_TAPI.user.js b/3CX_TAPI.user.js index 39b8da9..a47fceb 100644 --- a/3CX_TAPI.user.js +++ b/3CX_TAPI.user.js @@ -3,7 +3,7 @@ // @author Daniel Triendl // @namespace http://cp-solutions.at // @copyright Copyright 2020 CP Solutions GmbH -// @version 5 +// @version 6 // @grant GM.xmlHttpRequest // @grant GM.notification // @include https://192.168.0.154:5001/webclient* @@ -259,15 +259,14 @@ const tapi = { url: 'http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number), onload: function (response) { console.log('TAPI callerid response', response); - if (response.status != 200) { - return; - } - var callerId = JSON.parse(response.responseText); var notification = { text: number }; - if (callerId) { - notification.text = callerId.tD_NAME + '\r\n' + number; + if (response.status == 200) { + var callerId = JSON.parse(response.responseText); + if (callerId) { + notification.text = callerId.tD_NAME + '\r\n' + number; + } } GM.notification(notification); } @@ -279,27 +278,33 @@ const tapi = { showCallHistory: (element) => { var span = element.querySelector('span'); var number = tapi.extractNumber(span.textContent); - console.log('TAPI call histroy number found', number) + if (!number) { + return; + } if (tapi.callerIds.hasOwnProperty(number)) { span.textContent = tapi.callerIds[number].tD_NAME + ' ' + span.textContent; } else { - //http://celestia.fim.trellmor.com:62406/callerid/ - //http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/ GM.xmlHttpRequest({ method: 'GET', url: 'http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number), context: span, onload: function (response) { - console.log('TAPI call histroy callerid response', response); - if (response.status != 200) { - return; - } - var callerId = JSON.parse(response.responseText); var number = tapi.extractNumber(span.textContent); - tapi.callerIds[number] = { 'td_NAME': '' }; - if (callerId) { - tapi.callerIds[number] = callerId; - response.context.textContent = callerId.tD_NAME + ' ' + response.context.textContent; + var callerId = { 'tD_NAME': '' }; + if (response.status == 200) { + callerId = JSON.parse(response.responseText); + } + tapi.callerIds[number] = callerId; + console.log('TAPI call histroy callerid response', number, response, callerId); + if (callerId.tD_NAME != '') { + var text = response.context.textContent; + response.context.textContent = callerId.tD_NAME; + var br = document.createElement('br'); + var span2 = document.createElement('span'); + span2.style.fontSize = "small"; + span2.textContent = text; + response.context.parentNode.insertBefore(br, response.context.nextSibling); + response.context.parentNode.insertBefore(span2, response.context.nextSibling); } } });