-
Notifications
You must be signed in to change notification settings - Fork 6
/
apps.js
55 lines (48 loc) · 1.31 KB
/
apps.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
document.addEventListener("DOMContentLoaded", function() {
chrome.management.getAll(getAllCallback);
});
var getAllCallback = function(list) {
chrome.storage.sync.get({
"showApps": true
}, function(items) {
if (items["showApps"] == true) {
var apps = document.getElementById("apps");
function isEnabledApp(x) {
return x.isApp;
}
list = list.filter(isEnabledApp);
for(var i=0;i<Math.min(list.length,6);i++) {
// we don't want to do anything with extensions
var extInf = list[i];
if(extInf.isApp && extInf.enabled) {
var app = document.createElement("div");
var img = new Image();
img.className = "image";
img.src = find128Image(extInf.icons);
img.addEventListener("click", (function(ext) {
return function() {
chrome.management.launchApp(ext.id);
window.close();
};
})(extInf));
var name = document.createElement("div");
name.className = "name";
name.textContent = extInf.name;
app.className = "app";
app.setAttribute("data-id", i+1);
app.appendChild(img);
app.appendChild(name);
apps.appendChild(app);
}
}
}
});
};
var find128Image = function(icons) {
for(var icon in icons) {
if(icons[icon].size == "128") {
return icons[icon].url;
}
}
return "/noicon.png";
};