diff --git a/background.js b/background.js index 5e0e384..a458513 100644 --- a/background.js +++ b/background.js @@ -583,82 +583,86 @@ let Listener_SelectionNumber = ""; browser.runtime.onMessage.addListener(function (request, sender, sendResponse){ //console.log("request",request) - if ( request.hasOwnProperty("settings_change") ) { - settings_changed(); - } - - /* - if ( request.hasOwnProperty("python erreichbar") ) { - CallMonitor_connnect(); - } - */ - if( request.hasOwnProperty("callListTransfer") ){ - blink_missed("off"); - sendResponse({ - callList: GL_call_list_popup, - callList_raw: GL_call_list_popup_raw - }); - } - - if( request.hasOwnProperty("phoneListTransfer") ){ - sendResponse({ - phoneList: GL_phone_list_popup, - phoneList_raw: GL_phone_list_popup_raw - }); - } - - if ( request.hasOwnProperty("call_test") ) { - let info = request["call_test"].split(";") - //console.warn(info); - work(info); - } + switch(true){ - if ( request.hasOwnProperty("Call_Number") ) { - //Nummer anrufen - callNumber( request["Call_Number"], sendResponse ); - callNumber_check = true; + case request.settings_change: + settings_changed(); + break; - //wenn nach 3 sek callNumber_check noch true ist, ist alles gut. Anstonsten gabe es probleme - setTimeout(() => { - if(callNumber_check == true){ - startGetDialConfig(); - } - }, 3000); - } - - if( request.hasOwnProperty("HangUp") ){ - hangup(sendResponse); - } - - if( request.hasOwnProperty("checkCalling") ){ - if(Listener_Dial == ""){ + /* + case request.python_erreichbar: + CallMonitor_connnect(); + break; + */ + + case request.callListTransfer: + blink_missed("off"); sendResponse({ - "Listener_Dial": "" + callList: GL_call_list_popup, + callList_raw: GL_call_list_popup_raw }); - } - else{ + break; + + case request.phoneListTransfer: sendResponse({ - "Listener_Dial": Listener_Dial.concat( returnNumberName(Listener_Dial[1]) ) + phoneList: GL_phone_list_popup, + phoneList_raw: GL_phone_list_popup_raw }); - } - } - - if( request.hasOwnProperty("checkSelectionNumber") ){ - sendResponse({ - "callSelectionNumber": [Listener_SelectionNumber, returnNumberName(Listener_SelectionNumber)] - }); + break; - Listener_SelectionNumber = ""; - } - - if( request.hasOwnProperty("refresh_phonebook") ){ - phoneList_start(); - } - - if( request.hasOwnProperty("checkPython") ){ - sendResponse({ - "pythonCheck": GL_PythonListen.isRunning() - }); + case request.call_test: + let info = request["call_test"].split(";") + //console.warn(info); + work(info); + break; + + case request.Call_Number: + //Nummer anrufen + callNumber( request["Call_Number"], sendResponse ); + callNumber_check = true; + + //wenn nach 3 sek callNumber_check noch true ist, ist alles gut. Anstonsten gabe es probleme + setTimeout(() => { + if(callNumber_check == true){ + startGetDialConfig(); + } + }, 3000); + break; + + case request.HangUp: + hangup(sendResponse); + break; + + case request.checkCalling: + if(Listener_Dial == ""){ + sendResponse({ + "Listener_Dial": "" + }); + } + else{ + sendResponse({ + "Listener_Dial": Listener_Dial.concat( returnNumberName(Listener_Dial[1]) ) + }); + } + break; + + case request.checkSelectionNumber: + sendResponse({ + "callSelectionNumber": [Listener_SelectionNumber, returnNumberName(Listener_SelectionNumber)] + }); + + Listener_SelectionNumber = ""; + break; + + case request.refresh_phonebook: + phoneList_start(); + break; + + case request.checkPython: + sendResponse({ + "pythonCheck": GL_PythonListen.isRunning() + }); + break; } }) diff --git a/options.js b/options.js index 83759ca..5a970a3 100644 --- a/options.js +++ b/options.js @@ -620,7 +620,7 @@ save_button.addEventListener("click", function(){ ); */ - GL_accessAllWebsitesPermission[0] != check_url_Fbox(); + GL_accessAllWebsitesPermission[0] = !check_url_Fbox(); GL_accessAllWebsitesPermission[1] = check_tel_link.checked; accessAllWebsites(-1); @@ -768,7 +768,7 @@ function init(x){ change_volume(tmp); //Rechte für alle Seiten entfernen, wenn es nicht mehr gebruacht wird - GL_accessAllWebsitesPermission[0] != check_url_Fbox(); + GL_accessAllWebsitesPermission[0] = !check_url_Fbox(); GL_accessAllWebsitesPermission[1] = check_tel_link.checked; accessAllWebsites(-1); } diff --git a/telLink.js b/telLink.js index 9386c1e..adeb285 100644 --- a/telLink.js +++ b/telLink.js @@ -1,32 +1,56 @@ -function telLinkClick(evt){ - let target = evt.target +try{ + //try - beim 1. mal gibt es varListen noch nicht. wenn executeScript erneut ausgeführt wird, wird das Skript fortlaufend unten angehängt + browser.runtime.onMessage.removeListener(varListen); //vorherige Listener löschen +} +catch(e){} + + +controller = new AbortController(); + +varTelLinkClick = function telLinkClick(evt){ - if(target.tagName == "A" && target.protocol == "tel:"){ - - evt.preventDefault(); //Linkausführung verhindern - - - let tel = target.href.slice(4).trim().replace(/[^0-9()+*]/g, ""); - if(tel != ""){ - let x = confirm( browser.i18n.getMessage("pop_askNumberText_Number", [tel]) ) - if(x == true){ - browser.runtime.sendMessage({ - "Call_Number": tel - }); - } + evt.preventDefault(); //Linkausführung verhindern + + + let tel = this.href.replace(/[^0-9()+*]/g, ""); + if(tel != ""){ + let x = confirm( browser.i18n.getMessage("pop_askNumberText_Number", [tel]) ) + if(x == true){ + browser.runtime.sendMessage({ + "Call_Number": tel + }); } - } } -browser.runtime.onMessage.addListener(function (request, sender, sendResponse){ +varListen = function (request, sender, sendResponse){ //console.log("rec", request) if( request.hasOwnProperty("telLink_func_destroy") ){ - document.removeEventListener("click", telLinkClick); + //document.removeEventListener("click", varTelLinkClick); + controller.abort(); // entfernt alle Listener vom Addon auf der Seite } -}); +} + + + + +for(tagName of document.getElementsByTagName("a")){ + if(tagName.protocol == "tel:"){ + console.log(tagName) + + tagName.addEventListener("click", varTelLinkClick, { signal: controller.signal }); + } +} + +browser.runtime.onMessage.addListener(varListen); + + + + + + + + -document.removeEventListener("click", telLinkClick); //falls noch alter listerner da war -document.addEventListener("click", telLinkClick); \ No newline at end of file