diff options
author | NateN1222 <nathannichols454@gmail.com> | 2017-08-10 15:27:48 -0500 |
---|---|---|
committer | NateN1222 <nathannichols454@gmail.com> | 2017-08-10 15:27:48 -0500 |
commit | ec120cf896aee2c595d957745f9909a506c8036c (patch) | |
tree | c34bf42d9dfb232fdd95a11b207cfa8fd9d1d5a5 | |
parent | 1d3226b53975374b266431203cdb3a355480eb60 (diff) |
Started to implement the buttons in the pop-up and the "open in new tab" option
-rw-r--r-- | contact_finder.js | 12 | ||||
-rw-r--r-- | html/display_panel/content/display-panel.html | 13 | ||||
-rw-r--r-- | html/display_panel/content/main_panel.js | 46 | ||||
-rw-r--r-- | html/display_panel/content/panel-styles.css | 7 | ||||
-rw-r--r-- | main_background.js | 30 |
5 files changed, 67 insertions, 41 deletions
diff --git a/contact_finder.js b/contact_finder.js index 69b9254..a46ccab 100644 --- a/contact_finder.js +++ b/contact_finder.js @@ -215,18 +215,6 @@ function find_contacts(){ } console.log("final result:"); console.log(res); - /* - console.log("********************************************************"); - console.log("%c RESULTS: ","color: #dd0000;"); - console.log("%c " + phone_num.length + "%c phone numbers","color: red;","color: purple;"); - console.log("%c " + twitlinks.length + "%c twitter links","color: red;","color: purple;"); - console.log("%c " + identi.length + "%c identi.ca links","color: red;","color: purple;"); - console.log("%c " + contact_pages.length + "%c possible contact pages","color: red;","color: purple;"); - console.log("********************************************************"); - */ - - - } // need to have this so the handler doesn't take too long function handler(){ 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 @@ <body> <script src="main_panel.js"></script> - <div class="title-area"> - <div> + <div style="float:left; display:inline;" class="title-area"> + <div> <a class="libre" id="ljs-settings" href="javascript:void" @@ -44,10 +44,13 @@ >gnu.org/software/librejs</a> </div> <div> - <strong>LibreJS 7.0</strong> + <strong>LibreJS 7.0 <br><br></strong> </div> - </div> - + </div> + <div id="buttons" style="float:right; display:inline;" class="title-area"> + <div id="buttons-l" style="float:center;"></div> + <div id="buttons-r" style="float:right; clear: right;"></div> + </div> <div id="info"> <div id="whitelisted"> <h2 class="blocked-js"></h2> 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 = '<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] === undefined || data[name].length == 0){ + if(typeof(data[name]) == "undefined" || data[name].length == 0){ // default message list.innerHTML = "<li>No "+ name +" scripts on this page.</li>" + data[name] = []; } else{ heading.innerHTML = "<h2 class='blocked-js'>List of <div style='display:inline; color:"+color+";'>" + name.toUpperCase() + "</div> javascript in " + data["url"]+":</h2>"; } + 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 += "<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>"; @@ -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","<h3>Refresh the page to revaluate this script.</h3>"); - myPort.postMessage({"forget": temp}); + if(this.parentElement.parentElement.innerHTML.indexOf("Refresh the page") == -1){ + this.parentElement.parentElement.getElementsByTagName("b")[0].insertAdjacentHTML("beforebegin","<h3>Refresh the page to revaluate this script.</h3>"); + 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","<div id='buttonno_"+num_buttons+"'>" + button + "</div>"); + 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 = '<a id="complain-contact" class="button white" href="#"><span>Complain to site owner</span></a>'; + var button_complain = '<a id="complain-contact" class="button white" href="#">Complain to site owner</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>'; + var button_allow_all = '<a id="allow-button" class="button white" href="#">Allow all scripts in this page</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>'; + var button_block_nonfree = '<a id="disallow-button" class="button white" href="#">Block all nonfree/nontrivial scripts from this page</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_new_tab = '<a id="open-in-tab" class="button white" href="#">Open this report in a new tab</a>'; 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; diff --git a/main_background.js b/main_background.js index 75a5917..0d8fb13 100644 --- a/main_background.js +++ b/main_background.js @@ -48,9 +48,15 @@ function options_listener(changes, area){ * by opening a new tab with whatever HTML is in the popup * at the moment. */ -function open_popup_tab(){ +var active_connections = {}; +var unused_data = {}; +function open_popup_tab(data){ + console.log(data); function gotPopup(popupURL){ - var creating = webex.tabs.create({"url":popupURL}); + var creating = webex.tabs.create({"url":popupURL},function(a){ + console.log("[TABID:"+a["id"]+"] creating unused data entry from parent window's content"); + unused_data[a["id"]] = data; + }); } var gettingPopup = webex.browserAction.getPopup({},gotPopup); @@ -95,8 +101,6 @@ function debug_print_local(){ * } * */ -var active_connections = {}; -var unused_data = {}; function update_popup(tab_id,blocked_info_arg,update=false){ var new_blocked_data; @@ -238,6 +242,10 @@ function connected(p) { set_script(m["forget"][0],"forget"); update = true; } + // + if(m["open_popup_tab"] !== undefined){ + open_popup_tab(m["open_popup_tab"]); + } // a debug feature if(m["printlocalstorage"] !== undefined){ debug_print_local(); @@ -249,10 +257,16 @@ function connected(p) { function logTabs(tabs) { if(update){ - console.log("%c updating tab "+tabs[0]["id"],"color: red;"); - update_popup(tabs[0]["id"],unused_data[tabs[0]["id"]],true); - active_connections[tabs[0]["id"]] = p; - return; + + // TODO: check the Firefox equivalent reserved URL pattern + if(typeof(tabs[0]["url"].match(/chrome\-extension:\/\/.*display-panel\.html/g)) == "object"){ + console.log("%c Not updating popup because this is a reserved page","color: red;"); + return; + } else{ + console.log("%c updating tab "+tabs[0]["id"],"color: red;"); + update_popup(tabs[0]["id"],unused_data[tabs[0]["id"]],true); + active_connections[tabs[0]["id"]] = p; + } } for(var i = 0; i < tabs.length; i++) { var tab = tabs[i]; |