Show names in call history
This commit is contained in:
parent
0ac9f4d4ae
commit
060889df69
@ -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 4
|
// @version 5
|
||||||
// @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*
|
||||||
@ -230,27 +230,38 @@ const tapi = {
|
|||||||
element.appendChild(form);
|
element.appendChild(form);
|
||||||
},
|
},
|
||||||
|
|
||||||
showCallNotification: (element) => {
|
extractNumber: (s) => {
|
||||||
var number = element.dataset.id;
|
var match = /(\+?[0-9]+)/.exec(s);
|
||||||
console.log('TAPI call notification', number);
|
|
||||||
var rx = /(\+?[0-9]+)/;
|
|
||||||
var match = rx.exec(number);
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
console.log('TAPI callerid no number found');
|
return undefined;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
number = match[1];
|
number = match[1];
|
||||||
|
|
||||||
if (number.startsWith('+')) {
|
if (number.startsWith('+')) {
|
||||||
number = number.replace('+', '00');
|
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);
|
console.log('TAPI searching callerid for', number);
|
||||||
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),
|
||||||
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 callerId = JSON.parse(response.responseText);
|
||||||
var notification = {
|
var notification = {
|
||||||
text: number
|
text: number
|
||||||
@ -261,8 +272,42 @@ const tapi = {
|
|||||||
GM.notification(notification);
|
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, true);
|
waitForKeyElements('div.nav-search', tapi.createSearchBox, true);
|
||||||
waitForKeyElements('call-view', tapi.showCallNotification, false);
|
waitForKeyElements('call-view', tapi.showCallNotification, false);
|
||||||
|
waitForKeyElements('.call-history-list call', tapi.showCallHistory, false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user