-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
62 lines (47 loc) · 1.65 KB
/
script.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
"use strict";
window.onload = function () {
var el = function (elem) {
return document.getElementById(elem);
}
var DATA = JSON.parse(el("carbon-offset-data").innerHTML);
DATA.sort(function (a, b) {
var B = b[2];
var A = a[2];
if (B > A) return 1;
return -1;
})
var FIRST = DATA[0][0]
if (FIRST !== "No Certificate Available") el("IFRAME_CARBON_OFFSET").src = `./carbon_offsets/${FIRST}.pdf`;
var TOTAL_TONS = 0
var UL = el("carbon-offset-ul-list");
for (var i = 0; i < DATA.length; i++) {
var LI = document.createElement("li");
var S = document.createElement("div");
TOTAL_TONS += parseFloat(DATA[i][1]);
var UUID = DATA[i][0];
S.innerText = UUID;
var A = document.createElement("a");
A.innerText = 'Download';
if (UUID !== "No Certificate Available") {
S.id = UUID + "-btn";
A.href = "./carbon_offsets/" + UUID + ".pdf";
A.rel = "nofollow noopener noreferrer";
LI.append(S);
LI.append(A);
UL.append(LI);
var BTN = el(`${UUID}-btn`)
BTN.addEventListener("click", function (e) {
var ID = e.target.innerText;
el("IFRAME_CARBON_OFFSET").src = `./carbon_offsets/${ID}.pdf`;
})
} else {
S.className = "no-cert";
A.className = "no-cert";
LI.append(S);
LI.append(A);
UL.append(LI);
}
}
el("my-total").innerText = ` ${TOTAL_TONS.toPrecision(5)}`;
el("trees-total").innerText = `${TOTAL_TONS.toPrecision(5)*38.5}`;
}