From e120564551b325f90b446c490b1e2c80a2f6f311 Mon Sep 17 00:00:00 2001 From: NateN1222 Date: Fri, 18 Aug 2017 13:06:04 -0500 Subject: added graphical output to contact finder --- contact_finder.js | 59 ++++++++++++++++++++------------ eval_test.js | 48 ++++---------------------- html/display_panel/content/main_panel.js | 2 -- manifest.json | 2 +- 4 files changed, 46 insertions(+), 65 deletions(-) diff --git a/contact_finder.js b/contact_finder.js index a46ccab..4c7c74e 100644 --- a/contact_finder.js +++ b/contact_finder.js @@ -102,9 +102,6 @@ var usaPhoneNumber = new RegExp(/(?:\+ ?1 ?)?\(?[2-9]{1}[0-9]{2}\)?(?:\-|\.| )?[ * */ var button_i = 0; -if(document.getElementById("abc123_main_div") !== null){ - document.getElementById("abc123_main_div").remove(); -} function new_debug_button(name_text,callback){ if(document.getElementById("abc123_main_div") === null){ var to_insert = '
'; @@ -159,7 +156,7 @@ function attempt(certainty_lvl, first=true){ if(first){ return {"fail":false,"result":document.links[i]}; } else{ - console.log(document.links[i].href + " matched " + contactStr[j][certainty_lvl][k]); + //console.log(document.links[i].href + " matched " + contactStr[j][certainty_lvl][k]); matches.push(document.links[i]); fail_flag = false; flag = false; @@ -169,7 +166,6 @@ function attempt(certainty_lvl, first=true){ } } } - console.log(matches); return {"fail":fail_flag,"result":matches}; } @@ -183,48 +179,69 @@ function find_contacts(){ var twitlinks = []; var identi = []; var contact_pages = []; - console.log("certain:"); var res = attempt("certain"); var flag = true; + var type = ""; if(res["fail"] == false){ - console.log("certain contact found:" + res["result"]); + type = "certain"; res = res["result"]; flag = false; } if(flag){ - console.log("probable:"); res = attempt("probable"); if(res["fail"] == false){ - console.log("probable contact found:" + res["result"]); + type = "probable"; res = res["result"]; flag = false; } } if(flag){ - console.log("uncertain:"); res = attempt("uncertain"); - console.log(res); if(res["fail"] == false){ - console.log("uncertain contact found:" + res["result"]); + type = "uncertain"; res = res["result"]; flag = false; } } if(flag){ - console.log("No contact found"); + return res; } - console.log("final result:"); - console.log(res); + return [type,res]; } // need to have this so the handler doesn't take too long function handler(){ - find_contacts(); + var res = find_contacts(); + if(document.getElementById("librejs_contactfinder") != null){ + document.getElementById("librejs_contactfinder").remove(); + } + var to_insert; + if("fail" in res){ + to_insert = '
'+ + "Contact finder failed." + '
'; + } else{ + if(typeof(res[1]) == "string"){ + to_insert = '
Result:
'+ + res[0] + ": " + 'Result:
'+ + res[0]+": "+res[1].outerHTML + + '
'; + + } + } + setTimeout(function(){document.getElementById("librejs_contactfinder").remove()}, 7500); + document.body.insertAdjacentHTML("afterbegin",to_insert); return 0; + } new_debug_button("Complain to website",handler); -new_debug_button("Remove these buttons",function(){ - if(document.getElementById("abc123_main_div") !== null){ - document.getElementById("abc123_main_div").remove(); - } -}); diff --git a/eval_test.js b/eval_test.js index d8183cf..ffdb0e9 100644 --- a/eval_test.js +++ b/eval_test.js @@ -42,7 +42,6 @@ var intrinsicEvents = [ - Automatic whitelist: (http://bzr.savannah.gnu.org/lh/librejs/dev/annotate/head:/data/script_libraries/script-libraries.json_ -
which may be linked to by a link tag identified by rel="jslicense" or data-jslicense="1" - In the first script tag, declare the license with @licstart/@licend - */ var licenses = { @@ -227,7 +226,7 @@ function is_whitelisted(){ /** -* Parses the weblabels table from a DOM object +* Parses the weblabels table from a DOM object * */ function read_weblabels_table(weblabel){ @@ -266,14 +265,16 @@ function get_table(url){ } xml.send(); } -function read_w_table(table_data){ +function read_w_table(table_data=false){ // Call license_read on all the document's scripts // This is done just to debug before we can implement this in a background script, // where it will have access to the individual script requests and HTML document. + + for(var i = 0; i < document.scripts.length; i++){ // convert between relative link and file name (table_data indexes by file name) var scriptname = document.scripts[i].src.split("/")[document.scripts[0].src.split("/").length-1]; - if(table_data !== undefined && scriptname in table_data){ + if(table_data != false && scriptname in table_data){ console.log("script contained in weblabel data."); if(table_data[scriptname] == "free"){ console.log("script is free"); @@ -309,41 +310,6 @@ function read_w_table(table_data){ } } } -function read_wo_table(){ - // Call license_read on all the document's scripts - // This is done just to debug before we can implement this in a background script, - // where it will have access to the individual script requests and HTML document. - for(var i = 0; i < document.scripts.length; i++){ - var scriptname = document.scripts[i].src.split("/")[document.scripts[0].src.split("/").length-1]; - console.log(scriptname); - if(document.scripts[i].src != ""){ - // it is a remote script ("") - var name = document.scripts[i].src; - var xml = new XMLHttpRequest(); - xml.open("get", document.scripts[i].src); - xml.onload = function(response){ - console.log("%c Script " + i + ":","color:red;"); - console.log(name); - license_read(this.responseText); - } - xml.send(); - } else{ - // it is an inline script ("") - console.log("%c Script " + i + ": (src: inline)","color:red;"); - //console.log(document.scripts[i].innerText); - license_read(document.scripts[i].innerText); - } - } - // Find all the document's elements with intrinsic events - for(var i = 0; i < document.all.length; i++){ - for(var j = 0; j < intrinsicEvents.length; j++){ - if(intrinsicEvents[j] in document.all[i].attributes){ - console.log("intrinsic event '"+intrinsicEvents[j]+"' JS found in element document.all[" + i + "]"); - license_read(document.all[i].attributes[intrinsicEvents[j]].value); - } - } - } -} // called when invoked by the button function analyze(){ // TODO: Call get_whitelisted_status on this page's URL @@ -393,10 +359,10 @@ function analyze(){ var weblabel = document.getElementById("jslicense-labels1"); if(weblabel !== undefined && weblabel != null && found_table_flag == false){ console.log("Found web labels table"); - read_w_table(read_weblabels_table(weblabel)); + read_w_table(table_data=read_weblabels_table(weblabel)); } if(found_table_flag == false){ - read_wo_table(); + read_w_table(); } } diff --git a/html/display_panel/content/main_panel.js b/html/display_panel/content/main_panel.js index c6d2059..a0877a3 100644 --- a/html/display_panel/content/main_panel.js +++ b/html/display_panel/content/main_panel.js @@ -40,9 +40,7 @@ function new_debug_button(name_text,callback){ var to_insert = '
'; document.body.insertAdjacentHTML('afterbegin', to_insert); } - 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; diff --git a/manifest.json b/manifest.json index bcf91f1..d38a57a 100644 --- a/manifest.json +++ b/manifest.json @@ -41,5 +41,5 @@ "background": { "scripts": ["main_background.js"] }, - "content_scripts": [{"matches": [""],"js": ["eval_test.js"]}] + "content_scripts": [{"matches": [""],"js": ["eval_test.js","contact_finder.js"]}] } -- cgit v1.2.3