From fb43001ad1c389d7d6598389ebe66f8a950a9d5d Mon Sep 17 00:00:00 2001 From: NateN1222 Date: Sat, 2 Sep 2017 13:19:39 -0500 Subject: Contact founder now generates "mailto:" links --- contact_finder.js | 91 +++++++++++++++++++++++++++++++++++++++++++++--------- main_background.js | 16 +++++++--- 2 files changed, 88 insertions(+), 19 deletions(-) diff --git a/contact_finder.js b/contact_finder.js index f26ef61..22d12a5 100644 --- a/contact_finder.js +++ b/contact_finder.js @@ -93,9 +93,11 @@ var contactStr = { }; var usaPhoneNumber = new RegExp(/(?:\+ ?1 ?)?\(?[2-9]{1}[0-9]{2}\)?(?:\-|\.| )?[0-9]{3}(?:\-|\.| )[0-9]{4}(?:[^0-9])/mg); - +// Taken from http://emailregex.com/ +var email_regex = new RegExp(/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/g); //********************************************************************************************* +var prefs; /** * @@ -103,18 +105,18 @@ var usaPhoneNumber = new RegExp(/(?:\+ ?1 ?)?\(?[2-9]{1}[0-9]{2}\)?(?:\-|\.| )?[ * * */ -var button_i = 0; function new_debug_button(name_text,callback){ + if(document.getElementById("abc123_main_div") !== null){ + document.getElementById("abc123_main_div").remove(); + } + console.log("adding button"); if(document.getElementById("abc123_main_div") === null){ var to_insert = '
'; document.body.insertAdjacentHTML('afterbegin', to_insert); } - if(document.getElementById("abc123_button_"+button_i) === undefined){ - var button_html = '
'; - document.getElementById("abc123_main_div").insertAdjacentHTML('afterbegin', button_html); - document.getElementById("abc123_button_"+button_i).addEventListener("click",callback); - button_i = button_i + 1; - } + var button_html = '
'; + document.getElementById("abc123_main_div").insertAdjacentHTML('afterbegin', button_html); document.getElementById("abc123_button_complain").addEventListener("click",callback); + } /** * returns input with all elements not of type string removed @@ -223,29 +225,88 @@ function handler(){ to_insert = '
'+ - "Contact finder failed." - '
'; + "Contact finder failed."; } else{ if(typeof(res[1]) == "string"){ to_insert = '
Result:
'+ - res[0] + ": " + 'Result:
'+ - res[0]+": "+res[1].outerHTML + - '
'; + res[0]+": "+res[1].outerHTML; + + } + } + var email = document.documentElement.innerText.match(email_regex); + if(email != null){ + var max_i = 0; + if(email.length >= 10){ + max_i = 10; + } else{ + max_i = email.length; + } + for(var i = 0; i < max_i; i++){ + var mailto = "mailto:"+email[i]+"?subject="+encodeURI(prefs["pref_subject"])+"&body="+encodeURI(prefs["pref_body"]); + to_insert += '
' + 'Possible email:
'+email[i]+''; } } + + to_insert += ''; + setTimeout(function(){document.getElementById("librejs_contactfinder").remove()}, 7500); document.body.insertAdjacentHTML("afterbegin",to_insert); return 0; } -new_debug_button("Complain to website",handler); +function main(){ + new_debug_button("Complain to website",handler); +} + +// See main_background.js +var webex; +var myPort; +function set_webex(){ + if(typeof(browser) == "object"){ + webex = browser; + } + if(typeof(chrome) == "object"){ + webex = chrome; + } +} +set_webex(); +var myPort = webex.runtime.connect({name:"contact_finder"}); + +myPort.onMessage.addListener(function(m) { + prefs = m; + main(); +}); + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/main_background.js b/main_background.js index 37df5aa..18312ed 100644 --- a/main_background.js +++ b/main_background.js @@ -517,6 +517,14 @@ function get_domain(url){ */ var portFromCS; function connected(p) { + if(p["name"] == "contact_finder"){ + // Send a message back with the relevant settings + function cb(items){ + p.postMessage(items); + } + webex.storage.local.get(cb); + return; + } p.onMessage.addListener(function(m) { /** * Updates the entry of the current URL in storage @@ -580,7 +588,7 @@ function connected(p) { function logTabs(tabs) { if(contact_finder){ console.log("[TABID:"+tab_id+"] Injecting contact finder"); - inject_contact_finder(tabs[0]["id"]); + //inject_contact_finder(tabs[0]["id"]); } if(update){ console.log("%c updating tab "+tabs[0]["id"],"color: red;"); @@ -651,8 +659,8 @@ function change_csp(e) { keywords[j] = keywords[j].replace(/;/g,""); // This is the string that we add to every CSP keywords[j] += " data: blob: 'report-sample'"; - console.log("%c new script-src section:","color:green;") - console.log(keywords[j]+ "; "); + //console.log("%c new script-src section:","color:green;") + //console.log(keywords[j]+ "; "); } } var csp_header = ""; @@ -991,7 +999,7 @@ function test_url_whitelisted(url){ return; } var regex; - for(i in wl){ + for(var i in wl){ var s = wl[i].replace(/\*/g,"\\S*"); s = s.replace(/\./g,"\\."); regex = new RegExp(s, "g"); -- cgit v1.2.3