-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
37 lines (35 loc) · 1.03 KB
/
options.js
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
function renderJson(root, obj) {
if (Array.isArray(obj)) {
var list = document.createElement("ol");
root.appendChild(list);
obj.forEach(function (elm) {
var item = document.createElement("li");
list.appendChild(item);
renderJson(item, elm);
});
} else if (typeof obj == "object") {
var list = document.createElement("ul")
root.appendChild(list);
Map.wrap(obj).forEach(function (key, value) {
var item = document.createElement("li");
list.appendChild(item);
var span = document.createElement("span");
item.appendChild(span);
span.style.fontWeight = "bold";
renderJson(span, key);
renderJson(item, " = ");
renderJson(item, value);
});
} else {
root.appendChild(document.createTextNode(obj));
}
}
function handleMessage(message) {
renderJson(document.body, message);
}
function onLoad() {
var browser = getBrowserController();
browser.sendRequest("getAlerts")
.onFulfilled(handleMessage)
.onFailed(browser.getLogCallback());
}