/**
*
* 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();
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.
* 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){
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';
var button_block_nonfree = 'Block all nonfree/nontrivial scripts from this page';
var button_new_tab = 'Open this report in a new tab';
var button_whitelist = '
';
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
There may be no scripts on this page (check source, C-u)
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.
External scripts may not be free and/or may not have proper licensing and are not part of the whitelist of free JavaScript libraries.
";
}
// 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
There may be no scripts on this page (check source, C-u).
All the scripts on this page may be trivial and/or free.
You may have whitelisted this domain name or url from the preferences (Type about:addons in your location bar to check)
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.
If for any reason you think LibreJS should have blocked JavaScript code on this page, please report this issue to: bug-librejs@gnu.org
";
// 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).
}
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);