var currenttext = ""; var longer_active = false; var current_tags = "{}"; var result = "ERROR"; var original_text = "ERROR"; var current_sum =""; console.log( "Background - Loaded" ); var privacy_location= "https://www.uni-hannover.de/datenschutzerklaerung/"; /** * This function will be fired if a javascript, sending a message to Firefox. * The scripts cannont send messages directly to other scripts. They have to create a so called "promise first" * **/ async function listener(msg){ try{ console.log("hallo vom bg script"); if(msg.auswertung === "auswerten"){ return Promise.resolve({msg: result}); } else if(msg.auswertung === "getCurrent"){ return Promise.resolve({msg: currenttext}); } else if(msg.auswertung === "getTags"){ return Promise.resolve({msg: current_tags}); } else if(msg.createadvanced === "context"){ await browser.tabs.query({active: true, currentWindow: true}) .then(tabs => { tab = tabs.pop(); console.log(tab.url); privacy_location = tab.url; }); console.log("leite weiter an das content"); browser.tabs.sendMessage(tab.id, {func: "create_advanced", advanced: current_sum}); //console.log(response); } else if(msg.auswertung === "summary"){ current_sum = msg.set; } else if(msg.auswertung === "getsum"){ return Promise.resolve({msg: current_sum}); } else if(msg.auswertung === "getoriginal"){ return Promise.resolve({msg: original_text}); } else if(msg.auswertung === "get_privacy_location"){ return Promise.resolve({url: privacy_location}); } else if(msg.get === "summary"){ var html_code = "ERR"; var tab = ""; await browser.tabs.query({active: true, currentWindow: true}) .then(tabs => { tab = tabs.pop(); console.log(tab.url); privacy_location = tab.url; }); await browser.tabs.sendMessage(tab.id, {func: "get_policy"}).then(response => { console.log(response); html_code = response.html; //console.log(html_code); }); return Promise.resolve({back: html_code}); } else if(msg.get === "summary_with_id"){ var html_code = "ERR"; var tab = ""; await browser.tabs.query({active: true, currentWindow: true}) .then(tabs => { tab = tabs.pop(); console.log(tab.url); privacy_location = tab.url; }); console.log("dieser Promise backend"); await browser.tabs.sendMessage(tab.id, {func: "get_policy_and_id"}).then(response => { console.log(response); html_code = response.html; //console.log(html_code); }); return Promise.resolve({back: html_code}); } else if(msg.auswertung == "check_if_dsgvo") { await browser.tabs.query({active: true, currentWindow: true}) .then(tabs => { tab = tabs.pop(); console.log(tab.url); privacy_location = tab.url; }); console.log("checke auf dsgvo"); let dsgvo = false; let thirdparty = ""; await browser.tabs.sendMessage(tab.id, {func: "check_if_dsgvo"}).then(response => { console.log(response.is_dsgvo); dsgvo = response.is_dsgvo; thirdparty = response.third; console.log(thirdparty); }); return Promise.resolve({is_dsgvo: dsgvo, third: thirdparty}); } else { return Promise.resolve({result: ""}); } } catch(e){ console.log(e); } } /** * This function is connection the content-script and tries to get the url from the tab where the content-script is running */ function getInfosFromContentScript(stmt){ var html_code = "ERR"; browser.tabs.query({active: true, currentWindow: true}) .then(tabs => { let tab = tabs.pop(); console.log(tab.url); privacy_location = tab.url; browser.tabs.sendMessage(tab.id, {func: stmt}).then(response => { //console.log(response); html_code = response.html; console.log(html_code); return Promise.resolve({html: response.html}); }) }); return html_code; } /** * Debug function for the tab change bug */ function debug(){ browser.tabs.query({}) .then(tabs => { console.log(tabs.length + " anzahl der tabs"); }); } /*chrome.tabs.onActivated.addListener(function(activeInfo) { console.log(activeInfo.tabId); });*/ /** * register the listener */ browser.runtime.onMessage.addListener(listener);