Skip to content

Commit 2aadf2a

Browse files
committed
Update emissions notice
1 parent 49b043f commit 2aadf2a

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

assets/js/main.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,14 @@ if (!("ontouchstart" in window)) {
214214
/* ------------------- Emissions (Beacon) ------------------- */
215215

216216
(async () => {
217-
const response = await fetch(
218-
`https://digitalbeacon.co/badge?url=${encodeURIComponent(location.href)}`
219-
);
217+
const apiUrl = `https://digitalbeacon.co/badge?url=${encodeURIComponent(window.location.href)}`;
218+
219+
const { url, co2 } = await (await fetch(apiUrl)).json();
220220

221-
const { url, co2 } = await response.json();
222-
223-
const value = Number(co2).toFixed(3);
221+
const value = parseFloat(co2);
224222

225223
document.getElementById("data-co2").innerHTML =
226-
`<a href="${url}" target="_blank">${value}g CO₂e</a>`;
224+
`<a href="${url}" target="_blank">${Number.isFinite(value) ? value.toFixed(3) : "N/A"}g CO₂e</a>`;
227225
})();
228226

229227
/* ------------------- References ------------------- */

0 commit comments

Comments
 (0)