From 33db5e1fd5f3d94d070ed37f46f370adcdaf1b3b Mon Sep 17 00:00:00 2001 From: NateN1222 Date: Tue, 1 Aug 2017 11:10:34 -0500 Subject: UI improvements, removed ES6 'for ... of' statements --- html/display_panel/content/main_panel.js | 19 ++++++++++++++----- main_background.js | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/html/display_panel/content/main_panel.js b/html/display_panel/content/main_panel.js index 2becb4e..44be902 100644 --- a/html/display_panel/content/main_panel.js +++ b/html/display_panel/content/main_panel.js @@ -18,6 +18,10 @@ function set_webex(){ } set_webex(); + +var myPort = webex.runtime.connect({name:"port-from-cs"}); +var current_blocked_data; + /** * update the HTML of the pop-up window. * If return_HTML is true, it returns the HTML of the popup window without updating it. @@ -31,6 +35,7 @@ set_webex(); * */ function generate_HTML(blocked_data){ + current_blocked_data = blocked_data; var a = blocked_data; var button_complain = 'Complain to site owner'; var button_allow_all = 'Allow all scripts in this page'; @@ -70,17 +75,21 @@ function generate_HTML(blocked_data){ } if(a["blocked"].length != 0){ blocked.innerHTML += ""; + // 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}); + }); + } } // 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). } - -// content-script.js - -var myPort = webex.runtime.connect({name:"port-from-cs"}); - myPort.onMessage.addListener(function(m) { if(m["show_info"] !== undefined){ generate_HTML(m["show_info"]); diff --git a/main_background.js b/main_background.js index 300cfb7..caa40cd 100644 --- a/main_background.js +++ b/main_background.js @@ -36,7 +36,8 @@ function options_listener(changes, area){ var changedItems = Object.keys(changes); var changed_items = ""; - for (var item of changedItems) { + for (var i = 0; i < changedItems.length; i++;) { + var item = changedItems[i]; changed_items += item + ","; } console.log(changed_items); @@ -91,10 +92,20 @@ function update_popup(tab_id,blocked_info){ */ var portFromCS; function connected(p) { + console.log("Message:"); console.log(p); p.onMessage.addListener(function(m) { + + + if(m["whitelist_script"] !== undefined){ + console.log("whitelisting script " + m["whitelist_script"][0]); + return; + } + + function logTabs(tabs) { - for(let tab of 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){ -- cgit v1.2.3