3 Commits

Author SHA1 Message Date
060889df69 Show names in call history 2020-11-04 13:05:34 +01:00
0ac9f4d4ae Improve caller id 2020-11-02 15:34:34 +01:00
44628074c0 Call caller id notification 2020-10-27 15:57:47 +01:00

View File

@ -3,8 +3,9 @@
// @author Daniel Triendl
// @namespace http://cp-solutions.at
// @copyright Copyright 2020 CP Solutions GmbH
// @version 2
// @version 5
// @grant GM.xmlHttpRequest
// @grant GM.notification
// @include https://192.168.0.154:5001/webclient*
// @include https://cpsolution.my3cx.at:5001/webclient*
// @downloadURL http://scootaloo.cp-austria.at/gitlist/3cx_tapi.git/raw/master/3CX_TAPI.user.js
@ -227,7 +228,86 @@ const tapi = {
searchWrapper.appendChild(icon);
element.appendChild(form);
},
extractNumber: (s) => {
var match = /(\+?[0-9]+)/.exec(s);
if (!match) {
return undefined;
}
number = match[1];
if (number.startsWith('+')) {
number = number.replace('+', '00');
}
return number;
},
showCallNotification: (element) => {
var number = element.dataset.id;
console.log('TAPI call notification', number);
number = tapi.extractNumber(number);
if (!number) {
console.log('TAPI callerid no number found');
return;
}
console.log('TAPI searching callerid for', number);
GM.xmlHttpRequest({
method: 'GET',
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;
}
GM.notification(notification);
}
});
},
callerIds: {},
showCallHistory: (element) => {
var span = element.querySelector('span');
var number = tapi.extractNumber(span.textContent);
console.log('TAPI call histroy number found', number)
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;
}
}
});
}
}
};
waitForKeyElements('div.nav-search', tapi.createSearchBox, false);
waitForKeyElements('div.nav-search', tapi.createSearchBox, true);
waitForKeyElements('call-view', tapi.showCallNotification, false);
waitForKeyElements('.call-history-list call', tapi.showCallHistory, false);