Improve call history

This commit is contained in:
Daniel Triendl 2020-11-04 15:02:41 +01:00
parent 060889df69
commit 10c1a9185b

View File

@ -3,7 +3,7 @@
// @author Daniel Triendl // @author Daniel Triendl
// @namespace http://cp-solutions.at // @namespace http://cp-solutions.at
// @copyright Copyright 2020 CP Solutions GmbH // @copyright Copyright 2020 CP Solutions GmbH
// @version 5 // @version 6
// @grant GM.xmlHttpRequest // @grant GM.xmlHttpRequest
// @grant GM.notification // @grant GM.notification
// @include https://192.168.0.154:5001/webclient* // @include https://192.168.0.154:5001/webclient*
@ -259,15 +259,14 @@ const tapi = {
url: 'http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number), url: 'http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number),
onload: function (response) { onload: function (response) {
console.log('TAPI callerid response', response); console.log('TAPI callerid response', response);
if (response.status != 200) {
return;
}
var callerId = JSON.parse(response.responseText);
var notification = { var notification = {
text: number text: number
}; };
if (callerId) { if (response.status == 200) {
notification.text = callerId.tD_NAME + '\r\n' + number; var callerId = JSON.parse(response.responseText);
if (callerId) {
notification.text = callerId.tD_NAME + '\r\n' + number;
}
} }
GM.notification(notification); GM.notification(notification);
} }
@ -279,27 +278,33 @@ const tapi = {
showCallHistory: (element) => { showCallHistory: (element) => {
var span = element.querySelector('span'); var span = element.querySelector('span');
var number = tapi.extractNumber(span.textContent); var number = tapi.extractNumber(span.textContent);
console.log('TAPI call histroy number found', number) if (!number) {
return;
}
if (tapi.callerIds.hasOwnProperty(number)) { if (tapi.callerIds.hasOwnProperty(number)) {
span.textContent = tapi.callerIds[number].tD_NAME + ' ' + span.textContent; span.textContent = tapi.callerIds[number].tD_NAME + ' ' + span.textContent;
} else { } else {
//http://celestia.fim.trellmor.com:62406/callerid/
//http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/
GM.xmlHttpRequest({ GM.xmlHttpRequest({
method: 'GET', method: 'GET',
url: 'http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number), url: 'http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number),
context: span, context: span,
onload: function (response) { 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); var number = tapi.extractNumber(span.textContent);
tapi.callerIds[number] = { 'td_NAME': '' }; var callerId = { 'tD_NAME': '' };
if (callerId) { if (response.status == 200) {
tapi.callerIds[number] = callerId; callerId = JSON.parse(response.responseText);
response.context.textContent = callerId.tD_NAME + ' ' + response.context.textContent; }
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);
} }
} }
}); });