diff --git a/src/scripts/index.ts b/src/scripts/index.ts index f22d6a8..393b95a 100644 --- a/src/scripts/index.ts +++ b/src/scripts/index.ts @@ -1,18 +1,16 @@ - - async function fetchCarbon() : Promise { - const url : string = "https://corsproxy.io/?https://api.websitecarbon.com/site?url=" + window.location.hostname; - const response : Response = await fetch(url, { - method: "GET" - }); + const url : string = "https://corsproxy.io/?url=https://api.websitecarbon.com/site?url=" + window.location.hostname; + + const response : Response = await fetch(url); + console.log(response); return await response.json().then(data => data.statistics.co2.grid.litres); } window.onload = async function() { try { document.getElementById('carbon').innerHTML = "your visit to this website produced " + Math.round(await fetchCarbon() * 1000) + " mL of carbon dioxide!"; - } catch { + } catch (error) { document.getElementById('carbon').innerHTML = "unable to load carbon usage!"; + console.log(error); } - }; \ No newline at end of file