forked from EFForg/https-everywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevtools-panel.js
More file actions
67 lines (60 loc) · 2.17 KB
/
devtools-panel.js
File metadata and controls
67 lines (60 loc) · 2.17 KB
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
function e(id) {
return document.getElementById(id);
}
function sendMessage(type) {
chrome.runtime.sendMessage({
type: type,
tabId: chrome.devtools.inspectedWindow.tabId,
});
}
// Turn on the Switch Planner recording mode, and hide the long description.
function enableSwitchPlanner() {
sendMessage("enable");
e("SwitchPlannerDescription").style.display = "none";
e("SwitchPlannerDetails").style.display = "block";
// Hack: Fetch and display summary information from background page
// once per second.
setInterval(display, 1000);
chrome.devtools.inspectedWindow.reload();
}
// Disable the switch planner and reload, so any state is forgotten and
// the long description is restored.
function disableSwitchPlanner() {
sendMessage("disable");
document.location.reload();
}
// Fetch summary HTML of the planner results from the background page for
// display in the devtools panel.
function display() {
chrome.runtime.sendMessage({
type: "getSmallHtml",
tabId: chrome.devtools.inspectedWindow.tabId,
}, function(response) {
e("SwitchPlannerDetails").innerHTML = response.html;
e("SwitchPlannerResults").style.display = "block";
});
}
window.onload = function() {
// Open a connection to the background page. Right now this is only used
// by the background page so it knows when the devtools pane has closed.
// We don't receive messages from the background page currently, though that
// may be a future improvement. Sending messages to the background page doesn't
// require an existing connection.
chrome.runtime.connect({ name: "devtools-page" });
var checkbox = e("SwitchPlannerCheckbox");
checkbox.addEventListener("change", function() {
if (checkbox.checked) {
enableSwitchPlanner();
} else {
disableSwitchPlanner();
}
});
e("SwitchPlannerDetailsLink").addEventListener("click", function() {
window.open("switch-planner.html?tab=" + chrome.devtools.inspectedWindow.tabId);
});
// Since this is rendered in a devtools console, we have to make clicks on the
// link open a new window.
e("MixedContentLink").addEventListener("click", function(e) {
window.open(e.target.href);
});
};