aboutsummaryrefslogtreecommitdiff
path: root/html/display_panel/content/main_panel.js
blob: 3bcb16483042bcfe099710692d6faab1a4ef578e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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 = '<a id="complain-contact" class="button white" href="#"><span>Complain to site owner</span></a>';
    var button_allow_all = '<a id="allow-button" class="button white" href="#"><span>Allow all scripts in this page</span></a>';
    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_new_tab = '<a id="open-in-tab" class="button white" href="#"><span>Open this report in a new tab</span></a>';
	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 = '<li>LibreJS did not allow the execution of any scripts on this page: \n\n<ul><li>There may be no scripts on this page (check source, C-u)</li><li>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.</li><li>External scripts may not be free and/or may not have proper licensing and are not part of the whitelist of free JavaScript libraries.</li></ul></li>';
	} else{
		accept.innerHTML = "";
		accept.innerHTML = '<h2 class="accepted-js">List of <div style="color: green;">ACCEPTED</div> javascript in '+a["url"]+':</h2>';
		accept.innerHTML += '<ul class="accepted-js">';
	}
	// Iterate over a["accepted"] and generate bulleted list
	for(var i = 0; i < a["accepted"].length; i++){
		accept.innerHTML += "<li>";
		accept.innerHTML += a["accepted"][i][0] + "<br>" + a["accepted"][i][1];
		accept.innerHTML += "</li>";
	}
	if(a["accepted"].length != 0){
		accept.innerHTML += "</ul>";
	}
	// HTML taken directly from the current LibreJS, display-panel.html
	if(a["blocked"].length == 0){
		blocked.innerHTML += '<li>LibreJS did not block any scripts on this page: \n\n<ul><li>There may be no scripts on this page (check source, C-u).</li><li>All the scripts on this page may be trivial and/or free.</li><li>You may have whitelisted this domain name or url from the preferences (Type about:addons in your location bar to check)</li><li>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.</li><li>If for any reason you think LibreJS should have blocked JavaScript code on this page, please report this issue to: <a id="report" href="mailto:bug-librejs@gnu.org" target="_blank">bug-librejs@gnu.org</a></li></ul></li>';
	} else{
		blocked.innerHTML = "";
		blocked.innerHTML = "<h2 class='blocked-js'>List of <div style='color: red;'>BLOCKED</div> javascript in" + a["url"]+":</h2>";
		blocked.innerHTML += '<ul class="blocked-js">';
	}
	// Iterate over a["blocked"] and generate bulleted list
	for(var i = 0; i < a["blocked"].length; i++){
		blocked.innerHTML += "<li>";
		blocked.innerHTML += a["blocked"][i][0]+ "<br>" + a["blocked"][i][1];
		blocked.innerHTML += "</li>";
	}
	if(a["blocked"].length != 0){
		blocked.innerHTML += "</ul>";
	}
	// 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);