15 lines
488 B
JavaScript
15 lines
488 B
JavaScript
import tgwf from "https://cdn.skypack.dev/@tgwf/co2";
|
|
|
|
export function calculerImpactCO2(totalBytes) {
|
|
const emissions = new tgwf.co2();
|
|
const greenHost = true;
|
|
|
|
let estimatedCO2 = emissions.perByte(totalBytes, greenHost).toFixed(1);
|
|
let totalMB = (totalBytes / (1024 * 1024)).toFixed(1);
|
|
|
|
const target = document.getElementById("network-usage");
|
|
if (target) {
|
|
target.innerHTML = `Transfert : ${totalMB} Mo<br>CO₂eq estimé : ${estimatedCO2} g`;
|
|
}
|
|
}
|