From 08e2c650cacb372b913e60c91874af9fcbb786a0 Mon Sep 17 00:00:00 2001 From: NateN1222 Date: Fri, 28 Jul 2017 12:16:55 -0500 Subject: Initial commit --- html/display_panel/content/main_panel.js | 96 ++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 html/display_panel/content/main_panel.js (limited to 'html/display_panel/content/main_panel.js') diff --git a/html/display_panel/content/main_panel.js b/html/display_panel/content/main_panel.js new file mode 100644 index 0000000..3bcb164 --- /dev/null +++ b/html/display_panel/content/main_panel.js @@ -0,0 +1,96 @@ +/** +* +* Sets global variable "webex" to either "chrome" or "browser" for +* use on Chrome or a Firefox variant. +* +* Change this to support a new browser that isn't Chrome or Firefox, +* given that it supports webExtensions. +* +* (Use the variable "webex" for all API calls after calling this) +*/ +var webex; +function set_webex(){ + if(typeof(browser) == "undefined"){ + webex = chrome; + } else{ + webex = browser; + } +} +set_webex(); + +/** +* 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" +* } +* +*/ +function generate_HTML(blocked_data){ + var a = blocked_data; + var button_complain = 'Complain to site owner'; + var button_allow_all = 'Allow all scripts in this page'; + var button_block_nonfree = 'Block all nonfree/nontrivial scripts from this page'; + var button_new_tab = 'Open this report in a new tab'; + 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 = '
  • LibreJS did not allow the execution of any scripts on this page: \n\n
  • '; + } else{ + accept.innerHTML = ""; + accept.innerHTML = '

    List of
    ACCEPTED
    javascript in '+a["url"]+':

    '; + accept.innerHTML += '"; + } + // HTML taken directly from the current LibreJS, display-panel.html + if(a["blocked"].length == 0){ + blocked.innerHTML += '
  • LibreJS did not block any scripts on this page: \n\n
  • '; + } else{ + blocked.innerHTML = ""; + blocked.innerHTML = "

    List of
    BLOCKED
    javascript in" + a["url"]+":

    "; + blocked.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). + +} + + +// 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"]); + } +}); +function onGot(tabInfo) { + myPort.postMessage({"tab_info": tabInfo}); +} +var gettingCurrent = webex.tabs.getCurrent(onGot); + + -- cgit v1.2.3