From ec120cf896aee2c595d957745f9909a506c8036c Mon Sep 17 00:00:00 2001 From: NateN1222 Date: Thu, 10 Aug 2017 15:27:48 -0500 Subject: Started to implement the buttons in the pop-up and the "open in new tab" option --- html/display_panel/content/display-panel.html | 13 +++++--- html/display_panel/content/main_panel.js | 46 +++++++++++++++++++++------ html/display_panel/content/panel-styles.css | 7 ---- 3 files changed, 45 insertions(+), 21 deletions(-) (limited to 'html/display_panel') diff --git a/html/display_panel/content/display-panel.html b/html/display_panel/content/display-panel.html index 5fc1242..e8345ae 100644 --- a/html/display_panel/content/display-panel.html +++ b/html/display_panel/content/display-panel.html @@ -29,8 +29,8 @@ -
-
+
+
gnu.org/software/librejs
- LibreJS 7.0 + LibreJS 7.0

-
- +
+
+
+
+

diff --git a/html/display_panel/content/main_panel.js b/html/display_panel/content/main_panel.js index 19cad89..54db745 100644 --- a/html/display_panel/content/main_panel.js +++ b/html/display_panel/content/main_panel.js @@ -62,12 +62,15 @@ function write_elements(data,name,color){ var button_html_3 = '
'; var heading = document.getElementById(name).getElementsByTagName("h2")[0]; var list = document.getElementById(name).getElementsByTagName("ul")[0]; - if(data[name] === undefined || data[name].length == 0){ + if(typeof(data[name]) == "undefined" || data[name].length == 0){ // default message list.innerHTML = "
  • No "+ name +" scripts on this page.
  • " + data[name] = []; } else{ heading.innerHTML = "

    List of
    " + name.toUpperCase() + "
    javascript in " + data["url"]+":

    "; } + console.log(data); + console.log(data[name]); // Iterate over data[name] and generate bulleted list for(var i = 0; i < data[name].length; i++){ list.innerHTML += "
  • "+data[name][i][0]+ ":
    " + data[name][i][1]+"\n"+button_html+"

    \n"+button_html_2+"

    \n"+button_html_3+"
  • "; @@ -96,16 +99,26 @@ function write_elements(data,name,color){ 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; - this.parentElement.parentElement.getElementsByTagName("b")[0].insertAdjacentHTML("beforebegin","

    Refresh the page to revaluate this script.

    "); - myPort.postMessage({"forget": temp}); + if(this.parentElement.parentElement.innerHTML.indexOf("Refresh the page") == -1){ + this.parentElement.parentElement.getElementsByTagName("b")[0].insertAdjacentHTML("beforebegin","

    Refresh the page to revaluate this script.

    "); + myPort.postMessage({"forget": temp}); + } }); } } } - - +/** +* displays the button specified by HTML string "button" +*/ +var num_buttons = 0; +function write_button(button,lr,callback){ + + document.getElementById("buttons-"+lr).insertAdjacentHTML("beforeend","
    " + button + "
    "); + document.getElementById("buttonno_"+num_buttons).addEventListener("click",callback); + num_buttons = num_buttons + 1; +} /** * update the HTML of the pop-up window. * If return_HTML is true, it returns the HTML of the popup window without updating it. @@ -124,13 +137,13 @@ function generate_HTML(blocked_data){ current_blocked_data = blocked_data;//unused? // This should send a message to invoke the content finder - var button_complain = 'Complain to site owner'; + var button_complain = 'Complain to site owner'; // This should update the persistent options - var button_allow_all = 'Allow all scripts in this page'; + var button_allow_all = 'Allow all scripts in this page'; // This will call "Forget preferences" on every script. - var button_block_nonfree = 'Block all nonfree/nontrivial scripts from this page'; + var button_block_nonfree = 'Block all nonfree/nontrivial scripts from this page'; // This should send a message that calls "open_popup_tab()" in the background script - var button_new_tab = 'Open this report in a new tab'; + var button_new_tab = 'Open this report in a new tab'; var to_clr = document.getElementsByClassName("blocked-js"); @@ -141,6 +154,21 @@ function generate_HTML(blocked_data){ write_elements(blocked_data,"whitelisted","green"); write_elements(blocked_data,"blocked","red"); write_elements(blocked_data,"blacklisted","red"); + + if( blocked_data["blacklisted"].length != 0 || blocked_data["blocked"].length != 0 || + blocked_data["whitelisted"].length != 0 || blocked_data["accepted"].length != 0){ + write_button(button_allow_all,"l",function(){console.log("button_allow_all");}); + write_button(button_block_nonfree,"r",function(){console.log("button_block_nonfree");}); + write_button(button_complain,"l",function(){console.log("button_complain");}); + write_button(button_new_tab,"r",function(){ + myPort.postMessage({"open_popup_tab": blocked_data}); + }); + } else{ + write_button(button_new_tab,"l",function(){ + // NOTE: does not + myPort.postMessage({"open_popup_tab": blocked_data}); + }); + } } myPort.onMessage.addListener(function(m) { diff --git a/html/display_panel/content/panel-styles.css b/html/display_panel/content/panel-styles.css index 075c0d2..802c7f9 100644 --- a/html/display_panel/content/panel-styles.css +++ b/html/display_panel/content/panel-styles.css @@ -93,7 +93,6 @@ ul.blocked-js ul li, ul.accepted-js ul li, ul.dryrun-js ul li { float:right; padding:10px; display:none; - clear:both; margin:10px; } @@ -109,13 +108,7 @@ ul.blocked-js ul li, ul.accepted-js ul li, ul.dryrun-js ul li { text-decoration: none; font: 14px/100% Arial, Helvetica, sans-serif; padding: .5em 2em .55em; - text-shadow: 0 1px 1px rgba(0,0,0,.3); - -webkit-border-radius: .5em; - -moz-border-radius: .5em; border-radius: .5em; - -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2); - -moz-box-shadow: 0 1px 2px rgba(0,0,0,.2); - box-shadow: 0 1px 2px rgba(0,0,0,.2); } .small.button { font-size:11px; -- cgit v1.2.3