File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ------------------- */
You can’t perform that action at this time.
0 commit comments