aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNateN1222 <nathannichols454@gmail.com>2017-09-02 13:19:39 -0500
committerNateN1222 <nathannichols454@gmail.com>2017-09-02 13:19:39 -0500
commitfb43001ad1c389d7d6598389ebe66f8a950a9d5d (patch)
treeb5dc8db4881733d3f91abedd45bb5d21930263fa
parente615086e3322f9a7eee63cddcf4dc1329d55c55a (diff)
Contact founder now generates "mailto:" links
-rw-r--r--contact_finder.js91
-rw-r--r--main_background.js16
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 = '<div style="opacity: 0.5; font-size: small; z-index: 2147483647; position: fixed; right: 1%; top: 4%;" id="abc123_main_div"></div>';
document.body.insertAdjacentHTML('afterbegin', to_insert);
}
- if(document.getElementById("abc123_button_"+button_i) === undefined){
- var button_html = '<input id="abc123_button_' + button_i + '" value="' + name_text +'"type="button"></input><br>';
- 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 = '<input id="abc123_button_complain" value="' + name_text +'" type="button"></input><br>';
+ 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 = '<div style="font-size: small; z-index: 2147483647; background-color: #eeeeee;'+
'position: fixed; display:inline-block; border: 3px solid #990000; width: 50%;"'+
' id="librejs_contactfinder">'+
- "Contact finder failed."
- '</div>';
+ "Contact finder failed.";
} else{
if(typeof(res[1]) == "string"){
to_insert = '<div style="font-size: small; z-index: 2147483647; background-color: #eeeeee;'+
'position: fixed; display:inline-block; border: 3px solid #990000; width: 50%;"'+
' id="librejs_contactfinder"><b>Result:</b><br>'+
- res[0] + ": " + '<a href="' + res[1] + '>'+res[1]+'</a>' +
- '</div>';
+ res[0] + ": " + '<a href="' + res[1] + '>'+res[1]+'</a>';
}
if(typeof(res[1]) == "object"){
to_insert = '<div style="font-size: small; z-index: 2147483647; background-color: #eeeeee;'+
'position: fixed; display:inline-block; border: 3px solid #990000; width: 50%;"'+
' id="librejs_contactfinder"><b>Result:</b><br>'+
- res[0]+": "+res[1].outerHTML +
- '</div>';
+ 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 += '<br>' + 'Possible email: <a href="' + mailto + '">'+email[i]+'</a>';
}
}
+
+ to_insert += '</div>';
+
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");