From 44628074c0929cf40d841e946518da62bd2220f8 Mon Sep 17 00:00:00 2001 From: Daniel Triendl Date: Tue, 27 Oct 2020 15:57:35 +0100 Subject: [PATCH] Call caller id notification --- 3CX_TAPI.user.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/3CX_TAPI.user.js b/3CX_TAPI.user.js index 570e243..3d177b8 100644 --- a/3CX_TAPI.user.js +++ b/3CX_TAPI.user.js @@ -3,8 +3,9 @@ // @author Daniel Triendl // @namespace http://cp-solutions.at // @copyright Copyright 2020 CP Solutions GmbH -// @version 2 +// @version 3 // @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,30 @@ const tapi = { searchWrapper.appendChild(icon); element.appendChild(form); + }, + + showCallNotification: (element) => { + var number = element.textContent; + var rx = /\+([0-9]+)/ + var match = rx.exec(number); + number = '00' + match[1]; + GM.xmlHttpRequest({ + method: 'GET', + url: 'http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number), + onload: function (response) { + console.log('TAPI Search response', response); + var callerId = JSON.parse(response.responseText); + var notification = { + text: number + }; + if (callerId) { + notification.text = callerId.tD_NAME + '\r\n' + number; + } + GM.notification(notification); + } + }); } }; -waitForKeyElements('div.nav-search', tapi.createSearchBox, false); +waitForKeyElements('div.nav-search', tapi.createSearchBox, true); +waitForKeyElements('.toasterName', tapi.showCallNotification, false);