-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathindex.html
40 lines (40 loc) · 1.22 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<html>
<body>
<div id="github-content" class="loading">Loading...</div>
<div id="weather-content" class="loading">Loading...</div>
<script type="application/javascript">
const githubContentEl = document.getElementById("github-content")
fetch("https://api.github.com/users/ijpiantanida")
.then(r => {
if (r.status >= 400) {
throw "error"
}
return r.json()
})
.then(json => {
githubContentEl.innerHTML = json.login
githubContentEl.classList.toggle("loading")
})
.catch(() => {
githubContentEl.innerHTML = "ERROR"
githubContentEl.classList.toggle("loading")
})
const weatherContentEl = document.getElementById("weather-content")
fetch("https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m,relativehumidity_2m,windspeed_10m")
.then(r => {
if (r.status >= 400) {
throw "error"
}
return r.json()
})
.then(json => {
weatherContentEl.innerHTML = json.elevation
weatherContentEl.classList.toggle("loading")
})
.catch(() => {
weatherContentEl.innerHTML = "ERROR"
weatherContentEl.classList.toggle("loading")
})
</script>
</body>
</html>