-
Notifications
You must be signed in to change notification settings - Fork 2
/
aboutstartup.js
94 lines (89 loc) · 3.26 KB
/
aboutstartup.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
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
const Cc = Components.classes;
const Ci = Components.interfaces;
Components.utils.import('resource://aboutstartup/startupdata.jsm');
function init() {
var table = document.getElementById('table');
var data = StartupData._data;
var prev;
var headers_row = table.getElementsByTagName('tr')[0];
var headers = headers_row.getElementsByTagName('th');
for (var d of Object.keys(data).sort(Cc['@mozilla.org/xpcom/version-comparator;1'].getService(Ci.nsIVersionComparator).compare)) {
var total = { };
var num = { };
for (var h = 1; h < headers.length; h++) {
total[headers[h].textContent] = 0;
num[headers[h].textContent] = 0;
}
for (var entry of data[d]) {
var tr = document.createElement('tr');
for (var h = 1; h < headers.length; h++) {
var td = document.createElement('td');
var value = entry[headers[h].textContent];
td.className = headers[h].className;
td.appendChild(document.createTextNode(value));
if ((value < 0) || isNaN(value)) {
td.className += ' weird';
} else {
total[headers[h].textContent] += value;
num[headers[h].textContent]++;
}
tr.appendChild(td);
}
Object.keys(entry).filter(function(element, index, array) {
if (['version', 'appBuildID'].some(function(elm) { return element == elm; }))
return false;
for (var h = 1; h < headers.length; h++)
if (element == headers[h].textContent)
return false;
return true;
}).forEach(function(key, index, array) {
total[key] = 0;
num[key] = 0;
var th = document.createElement('th');
th.appendChild(document.createTextNode(key));
headers_row.appendChild(th);
var td = document.createElement('td');
var value = entry[key];
td.appendChild(document.createTextNode(value));
if ((value < 0) || isNaN(value)) {
td.className += ' weird';
} else {
total[key] += value;
num[key]++;
}
tr.appendChild(td);
});
if ((d == StartupData.key(StartupData.current)) &&
StartupData.cmp(StartupData.current, entry))
tr.className = 'current';
if (prev)
table.insertBefore(tr, prev);
else
table.appendChild(tr);
prev = tr;
}
var td = document.createElement('td');
td.appendChild(document.createTextNode(data[d][0].version));
td.appendChild(document.createElement('br'));
td.appendChild(document.createTextNode(data[d][0].appBuildID));
td.rowSpan = data[d].length;
td.className = 'string';
tr.insertBefore(td, tr.firstChild);
tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('average'));
td.className = 'string';
tr.appendChild(td);
tr.className = 'average';
for (var h = 1; h < headers.length; h++) {
td = document.createElement('td');
td.className = headers[h].className;
var value = (total[headers[h].textContent] / num[headers[h].textContent]).toFixed(2);
td.appendChild(document.createTextNode(value));
tr.appendChild(td);
}
table.insertBefore(tr, prev);
prev = tr;
}
}
window.addEventListener("load", init, false);