aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--html/display_panel/content/display-panel.html19
-rw-r--r--html/display_panel/content/main_panel.js168
-rw-r--r--main_background.js102
3 files changed, 193 insertions, 96 deletions
diff --git a/html/display_panel/content/display-panel.html b/html/display_panel/content/display-panel.html
index 9ef3eef..f8959d2 100644
--- a/html/display_panel/content/display-panel.html
+++ b/html/display_panel/content/display-panel.html
@@ -49,24 +49,23 @@
</div>
<div id="info">
- <div id="dryrun">
- <h2 class="dryrun-js"></h2>
- <ul class="dryrun-js"></ul>
+ <div id="whitelisted">
+ <h2 class="blocked-js"></h2>
+ <ul class="blocked-js"></ul>
</div>
<div id="accepted">
- <h2 class="accepted-js"></h2>
- <ul class="accepted-js"></ul>
+ <h2 class="blocked-js"></h2>
+ <ul class="blocked-js"></ul>
</div>
<div id="blocked">
<h2 class="blocked-js"></h2>
- <ul class="blocked-js">
+ <ul class="blocked-js"></ul>
</div>
-
- <div id="librejs-web-labels-pages">
- <h2></h2>
- <ul></ul>
+ <div id="blacklisted">
+ <h2 class="blocked-js"></h2>
+ <ul class="blocked-js"></ul>
</div>
</div>
</body>
diff --git a/html/display_panel/content/main_panel.js b/html/display_panel/content/main_panel.js
index a724c75..880d963 100644
--- a/html/display_panel/content/main_panel.js
+++ b/html/display_panel/content/main_panel.js
@@ -22,72 +22,126 @@ set_webex();
var myPort = webex.runtime.connect({name:"port-from-cs"});
var current_blocked_data;
+
+
+
+/*
+* Makes a button appear that calls a function when you press it.
+*
+* I copied and pasted this from something else I wrote. It's quite useful.
+*
+*/
+var button_i = 0;
+function new_debug_button(name_text,callback){
+ 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);
+ }
+
+ 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;
+}
+
+
+
+
+
+
+/*
+* Takes in the script data and color of h2 element
+* Writes to category specified by "name" as used in HTML
+* (name will probably either be "blacklisted", "whitelisted", "accepted", or "blocked")
+*/
+function write_elements(data,name,color){
+ var url = data["url"];
+ var button_html = '<div style="float:right"><input id="temp" type="button" value="blacklist"></input></div>';
+ var button_html_2 = '<div style="float:right"><input id="temp2" type="button" value="whitelist"></input></div>';
+ var button_html_3 = '<div style="float:right"><input id="temp3" type="button" value="forget preference"></input></div>';
+ var heading = document.getElementById(name).getElementsByTagName("h2")[0];
+ var list = document.getElementById(name).getElementsByTagName("ul")[0];
+ if(data[name].length == 0){
+ // default message
+ list.innerHTML = "<li>No "+ name +" scripts on this page.</li>"
+ } else{
+ heading.innerHTML = "<h2 class='blocked-js'>List of <div style='display:inline; color:"+color+";'>" + name.toUpperCase() + "</div> javascript in " + data["url"]+":</h2>";
+ }
+ // Iterate over data[name] and generate bulleted list
+ for(var i = 0; i < data[name].length; i++){
+ list.innerHTML += "<li><b>"+data[name][i][0]+ ":</b><br>" + data[name][i][1]+"\n"+button_html+"<br><br>\n"+button_html_2+"<br><br>\n"+button_html_3+"</li>";
+ document.getElementById("temp").id = name+"_"+i;
+ document.getElementById("temp2").id = name+"_2_"+i;
+ document.getElementById("temp3").id = name+"_3_"+i;
+ }
+ if(data[name].length != 0){
+ // add click listeners to the buttons
+ for(var i = 0; i < data[name].length; i++){
+ // Make sure this causes generate_html to get called again with updated data
+ document.getElementById(name+"_"+i).addEventListener("click",function(info){
+ var temp = current_blocked_data[name][parseInt(info.path[0].id.match(/\d/g)[0])];
+ console.log("Moving script " + temp[0] + " to blacklist");
+ var script_name = this.parentElement.parentElement.parentElement.parentElement.id;
+ myPort.postMessage({"blacklist": temp});
+ });
+ document.getElementById(name+"_2_"+i).addEventListener("click",function(info){
+ var temp = current_blocked_data[name][parseInt(info.path[0].id.match(/\d/g)[1])];
+ console.log("Moving script " + temp[0] + " to whitelist");
+ var script_name = this.parentElement.parentElement.parentElement.parentElement.id;
+ myPort.postMessage({"whitelist": temp});
+ });
+
+ document.getElementById(name+"_3_"+i).addEventListener("click",function(info){
+ var temp = current_blocked_data[name][parseInt(info.path[0].id.match(/\d/g)[1])];
+ console.log("Forget preferences for script " + temp[0]);
+ var script_name = this.parentElement.parentElement.parentElement.parentElement.id;
+ myPort.postMessage({"forget": temp});
+ });
+ }
+ }
+
+}
+
+
+
/**
* update the HTML of the pop-up window.
* If return_HTML is true, it returns the HTML of the popup window without updating it.
* example input:
*
* var example_input = {
-* "accepted": [["REASON 1","SOURCE 1"],["REASON 2","SOURCE 2"]],
-* "blocked": [["REASON 1","SOURCE 1"],["REASON 2","SOURCE 2"]],
-* "url": "example.com"
-* }
+* "accepted": [["FILENAME 1","REASON 1"],["FILENAME 2","REASON 2"]],
+* "blocked": [["FILENAME 1","REASON 1"],["FILENAME 2","REASON 2"]],
+* "whitelisted": [["FILENAME 1","REASON 1"],["FILENAME 2","REASON 2"]],
+* "blacklisted": [["FILENAME 1","REASON 1"],["FILENAME 2","REASON 2"]],
+* "url":"example.com"
+* };
*
*/
function generate_HTML(blocked_data){
-
- current_blocked_data = blocked_data;
- var a = blocked_data;
+ current_blocked_data = blocked_data;//unused?
+
+ // This should send a message to invoke the content finder
var button_complain = '<a id="complain-contact" class="button white" href="#"><span>Complain to site owner</span></a>';
+ // This should update the persistent options
var button_allow_all = '<a id="allow-button" class="button white" href="#"><span>Allow all scripts in this page</span></a>';
+ // This will call "Forget preferences" on every script.
var button_block_nonfree = '<a id="disallow-button" class="button white" href="#"><span>Block all nonfree/nontrivial scripts from this page</span></a>';
+ // This should send a message that calls "open_popup_tab()" in the background script
var button_new_tab = '<a id="open-in-tab" class="button white" href="#"><span>Open this report in a new tab</span></a>';
- var button_whitelist = '<div style="float:right"><input id="temp" type="button" value="whitelist"></input></div>';
- var htmlDoc = document;// Not neccessary
- var accept = htmlDoc.getElementById("accepted");
- var blocked = htmlDoc.getElementById("blocked");
- // HTML taken directly from the current LibreJS, display-panel.html
- if(a["accepted"].length == 0){
- accept.innerHTML = '<li>LibreJS did not allow the execution of any scripts on this page: \n\n<ul><li>There may be no scripts on this page (check source, C-u)</li><li>The inline and on-page JavaScript code may not be free and/or may not have proper license information and external scripts (if present) may have been removed by default.</li><li>External scripts may not be free and/or may not have proper licensing and are not part of the whitelist of free JavaScript libraries.</li></ul></li>';
- } else{
- accept.innerHTML = "";
- accept.innerHTML = '<h2 class="accepted-js">List of <div style="display:inline; color: green;">ACCEPTED</div> javascript in '+a["url"]+':</h2>';
- accept.innerHTML += '<ul class="accepted-js">';
- }
- // Iterate over a["accepted"] and generate bulleted list
- for(var i = 0; i < a["accepted"].length; i++){
- accept.innerHTML += "<li>" + a["accepted"][i][0] + "<br>" + a["accepted"][i][1] + "</li>";
- }
- if(a["accepted"].length != 0){
- accept.innerHTML += "</ul>";
- }
- // HTML taken directly from the current LibreJS, display-panel.html
- if(a["blocked"].length == 0){
- blocked.innerHTML += '<li>LibreJS did not block any scripts on this page: \n\n<ul><li>There may be no scripts on this page (check source, C-u).</li><li>All the scripts on this page may be trivial and/or free.</li><li>You may have whitelisted this domain name or url from the preferences (Type about:addons in your location bar to check)</li><li>You may have clicked the "allow all scripts" button, which causes LibreJS to load all JavaScript on a page regardless of whether it is free, trivial, nontrivial or nonfree. This policy is effective for the entire duration of a Firefox session.</li><li>If for any reason you think LibreJS should have blocked JavaScript code on this page, please report this issue to: <a id="report" href="mailto:bug-librejs@gnu.org" target="_blank">bug-librejs@gnu.org</a></li></ul></li>';
- } else{
- blocked.innerHTML = "";
- blocked.innerHTML = "<h2 class='blocked-js'>List of <div style='display:inline; color: red;'>BLOCKED</div> javascript in" + a["url"]+":</h2>";
- blocked.innerHTML += '<ul class="blocked-js">';
- }
- // Iterate over a["blocked"] and generate bulleted list
- for(var i = 0; i < a["blocked"].length; i++){
- blocked.innerHTML += "<li>"+a["blocked"][i][0]+ "<br>" + a["blocked"][i][1]+"\n"+button_whitelist+"</li>";
- document.getElementById("temp").id = "wl_"+i;
- }
- if(a["blocked"].length != 0){
- blocked.innerHTML += "</ul>";
- // add click listeners to the buttons
- for(var i = 0; i < a["blocked"].length; i++){
- document.getElementById("wl_"+i).addEventListener("click",function(a){
- console.log(a.path[0].id + " clicked");
- var temp = current_blocked_data["blocked"][parseInt(a.path[0].id.substr(3))];
- console.log(temp);
- myPort.postMessage({"whitelist_script": temp});
- });
- }
+
+ var to_clr = document.getElementsByClassName("blocked-js");
+
+ for(var i = 0; i < to_clr.length; i++){
+ to_clr[i].innerHTML = "";
}
- // At this point, it has the HTML that the popup needs and the only problem is
- // getting it into the popup. (browserAction() needs a (local) URL to work).
+
+
+ write_elements(blocked_data,"accepted","green");
+ write_elements(blocked_data,"whitelisted","green");
+ write_elements(blocked_data,"blocked","red");
+ write_elements(blocked_data,"blacklisted","red");
}
@@ -96,9 +150,19 @@ myPort.onMessage.addListener(function(m) {
generate_HTML(m["show_info"]);
}
});
+// Sends a message that tells the background script the window is open
function onGot(tabInfo) {
myPort.postMessage({"tab_info": tabInfo});
}
var gettingCurrent = webex.tabs.getCurrent(onGot);
+
+
+
+
+function print_local_storage(){
+ myPort.postMessage({"printlocalstorage": true});
+}
+
+new_debug_button("Print local storage",print_local_storage);
diff --git a/main_background.js b/main_background.js
index 27b788b..97cd792 100644
--- a/main_background.js
+++ b/main_background.js
@@ -34,6 +34,7 @@ function set_webex(){
*
*
* {
+ // pref_* items are from the options page
* pref_body : "",
* pref_complaint_tab : "",
* pref_notify_analyze : "",
@@ -52,11 +53,20 @@ function set_webex(){
* "a.js" : true,
* "b.js" : false
* }
+* },
+* blacklist : {
+* "website.com":{
+* "a.js" : true
+* },
+* "test.com": {
+* "a.js" : true,
+* "b.js" : false
+* }
* }
* }
*
-*
-*
+* If something is set to false under whitelist/blacklist, it is the same as if it were undefined.
+* If something is undefined in whitelist/blacklist, then it should be judged by its content as LibreJS does by default.
*
*
*
@@ -87,6 +97,26 @@ function open_popup_tab(){
var gettingPopup = webex.browserAction.getPopup({},gotPopup);
}
+
+/**
+*
+* Prints local storage (the persistent data)
+*
+*/
+function debug_print_local(){
+ function storage_got(items){
+ console.log("\n\nLocal Storage:");
+ console.log("\npref_complaint_tab:"+items["pref_complaint_tab"]);
+ console.log("pref_notify_analyze:"+items["pref_notify_analyze"]);
+ console.log("pref_subject:"+items["pref_subject"]);
+ console.log("pref_body:"+items["pref_body"]);
+ console.log("\nWHITELIST:");
+ console.log(items["whitelist"]);
+ console.log("\nBLACKLIST:");
+ console.log(items["blacklist"]);
+ }
+ webex.storage.local.get(storage_got);
+}
/**
*
* This is what you call when a page gets changed to update the info box.
@@ -100,7 +130,8 @@ function open_popup_tab(){
* }
*
*/
-
+// This might be wasting memory
+// I now realize it doesn't need to store the connections, this is left over from when I thought it did
var active_connections = {};
var unused_data = {};
function update_popup(tab_id,blocked_info){
@@ -122,17 +153,16 @@ function update_popup(tab_id,blocked_info){
*/
var portFromCS;
function connected(p) {
- console.log("Message:");
- console.log(p);
p.onMessage.addListener(function(m) {
-
+ console.log("Message:");
+ console.log(p);
/**
- * Updates the entry of the current URL in whitelist with
- *
+ * Updates the entry of the current URL in whitelist/blacklist (possible values of arg "key") with either true or false.
+ * (Perhaps it should actually delete it to not leak memory? Not sure how that is done.)
*/
- function set_script(script,tof){
- console.log("setting script '" + script + "' whitelisted status to "+tof);
- // Remember that we do not trust the names of whitelisted scripts.
+ function set_script(script,key,tof){
+ console.log("setting script '" + script + "'s entry to "+ tof + " with key '" + key + "'");
+ // Remember that we do not trust the names of scripts.
var current_url = "";
function geturl(tabs) {
// Got the URL of the current open tab
@@ -141,14 +171,15 @@ function connected(p) {
console.log("got storage:");
console.log(items);
var new_items = items;
- if(new_items["whitelist"] === undefined){
- new_items["whitelist"] = {};
+ if(new_items[key] === undefined){
+ new_items[key] = {};
}
- if(new_items["whitelist"][current_url] === undefined){
- new_items["whitelist"][current_url] = {};
+ if(new_items[key][current_url] === undefined){
+ new_items[key][current_url] = {};
}
console.log(script);
- new_items["whitelist"][current_url][script] = tof;
+
+ new_items[key][current_url][script] = tof;
webex.storage.local.set(new_items);
}
webex.storage.local.get(storage_got);
@@ -156,17 +187,26 @@ function connected(p) {
var querying = webex.tabs.query({active: true,currentWindow: true},geturl);
return;
}
- if(m["whitelist_script"] !== undefined){
- set_script(m["whitelist_script"][0],true);
+ if(m["whitelist"] !== undefined){
+ set_script(m["whitelist"][0],"whitelist",true);
+ set_script(m["whitelist"][0],"blacklist",false);
+ }
+ if(m["blacklist"] !== undefined){
+ set_script(m["blacklist"][0],"blacklist",true);
+ set_script(m["blacklist"][0],"whitelist",false);
}
- if(m["unwhitelist_script"] !== undefined){
- set_script(m["whitelist_script"][0],false);
+ if(m["forget"] !== undefined){
+ set_script(m["unwhitelist"][0],"whitelist",false);
+ set_script(m["unwhitelist"][0],"blacklist",false);
+ }
+ // a debug feature
+ if(m["printlocalstorage"] !== undefined){
+ debug_print_local();
}
function logTabs(tabs) {
for(var i = 0; i < tabs.length; i++) {
var tab = tabs[i]
var tab_id = tab["id"]
- console.log(tab_id)
if(unused_data[tab_id] !== undefined){
// If we have some data stored here for this tabID, send it and then delete our copy
console.log("[TABID:"+tab_id+"]"+"Sending stored data associated with browser action");
@@ -217,15 +257,6 @@ init_addon();
/**************** some misc. debugging: ***************************/
-
-function debug_print_local(){
- function storage_got(items){
- console.log("Local Storage:");
- console.log(items);
- }
- webex.storage.local.get(storage_got);
-}
-
function clr_local(){
webex.storage.local.set({});
}
@@ -234,11 +265,14 @@ function clr_local(){
var example_input = {
"accepted": [["FILENAME 1","REASON 1"],["FILENAME 2","REASON 2"]],
"blocked": [["FILENAME 1","REASON 1"],["FILENAME 2","REASON 2"]],
+ "whitelisted": [["FILENAME 1","REASON 1"],["FILENAME 2","REASON 2"]],
+ "blacklisted": [["FILENAME 1","REASON 1"],["FILENAME 2","REASON 2"]],
"url":"example.com"
};
-update_popup(2,example_input);
// To test the default text
-//example_input["accepted"] = [];
-//example_input["blocked"] = [];
+example_input["accepted"] = [];
+example_input["blocked"] = [];
+
+
+update_popup(2,example_input);
-debug_print_local();