From b2fefd0e24363593afbd4ae734fb9094410fe6b6 Mon Sep 17 00:00:00 2001 From: fershad <27988517+fershad@users.noreply.github.com> Date: Sun, 17 Mar 2024 21:42:32 +0100 Subject: [PATCH] remove exported functions --- src/co2.js | 102 ----------------------------------------------------- 1 file changed, 102 deletions(-) diff --git a/src/co2.js b/src/co2.js index 70a3149..665911d 100644 --- a/src/co2.js +++ b/src/co2.js @@ -186,108 +186,6 @@ class CO2 { ); } } - - perDomain(pageXray, greenDomains) { - const co2PerDomain = []; - for (let domain of Object.keys(pageXray.domains)) { - let co2; - if (greenDomains && greenDomains.indexOf(domain) > -1) { - co2 = this.perByte(pageXray.domains[domain].transferSize, true); - } else { - co2 = this.perByte(pageXray.domains[domain].transferSize); - } - co2PerDomain.push({ - domain, - co2, - transferSize: pageXray.domains[domain].transferSize, - }); - } - co2PerDomain.sort((a, b) => b.co2 - a.co2); - - return co2PerDomain; - } - - perPage(pageXray, green) { - // Accept an xray object, and if we receive a boolean as the second - // argument, we assume every request we make is sent to a server - // running on renwewable power. - - // if we receive an array of domains, return a number accounting the - // reduced CO2 from green hosted domains - - const domainCO2 = this.perDomain(pageXray, green); - let totalCO2 = 0; - for (let domain of domainCO2) { - totalCO2 += domain.co2; - } - return totalCO2; - } - - perContentType(pageXray, greenDomains) { - const co2PerContentType = {}; - for (let asset of pageXray.assets) { - const domain = new URL(asset.url).domain; - const transferSize = asset.transferSize; - const co2ForTransfer = this.perByte( - transferSize, - greenDomains && greenDomains.indexOf(domain) > -1 - ); - const contentType = asset.type; - if (!co2PerContentType[contentType]) { - co2PerContentType[contentType] = { co2: 0, transferSize: 0 }; - } - co2PerContentType[contentType].co2 += co2ForTransfer; - co2PerContentType[contentType].transferSize += transferSize; - } - // restructure and sort - const all = []; - for (let type of Object.keys(co2PerContentType)) { - all.push({ - type, - co2: co2PerContentType[type].co2, - transferSize: co2PerContentType[type].transferSize, - }); - } - all.sort((a, b) => b.co2 - a.co2); - return all; - } - - dirtiestResources(pageXray, greenDomains) { - const allAssets = []; - for (let asset of pageXray.assets) { - const domain = new URL(asset.url).domain; - const transferSize = asset.transferSize; - const co2ForTransfer = this.perByte( - transferSize, - greenDomains && greenDomains.indexOf(domain) > -1 - ); - allAssets.push({ url: asset.url, co2: co2ForTransfer, transferSize }); - } - allAssets.sort((a, b) => b.co2 - a.co2); - - return allAssets.slice(0, allAssets.length > 10 ? 10 : allAssets.length); - } - - perParty(pageXray, greenDomains) { - let firstParty = 0; - let thirdParty = 0; - // calculate co2 per first/third party - const firstPartyRegEx = pageXray.firstPartyRegEx; - for (let d of Object.keys(pageXray.domains)) { - if (!d.match(firstPartyRegEx)) { - thirdParty += this.perByte( - pageXray.domains[d].transferSize, - greenDomains && greenDomains.indexOf(d) > -1 - ); - } else { - firstParty += this.perByte( - pageXray.domains[d].transferSize, - greenDomains && greenDomains.indexOf(d) > -1 - ); - } - } - return { firstParty, thirdParty }; - } } export { CO2 };