-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetCityDetail.js
38 lines (33 loc) · 1.06 KB
/
getCityDetail.js
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
import config from "./config.js";
import prepareSVG from "./prepareSVG.js";
import svgtopng from "./svgtopng.js";
export default async function (cityURL) {
const corsProxy = config.corsProxy;
const coreURL = `https://weatherspark.com${cityURL}`;
const url = corsProxy + coreURL;
const parser = new DOMParser();
return fetch(url, {
headers: {
accept: "application/json",
},
})
.then((response) => response.text())
.then((text) => parser.parseFromString(text, "text/html"))
.then((doc) => {
const theParent = doc.querySelectorAll(".Figure-title");
let relevantParent;
theParent.forEach((title) => {
if (title.textContent.includes("Average Hourly Temperature")) {
relevantParent = title.parentElement;
}
});
const childSVG = relevantParent.querySelector("svg");
infographic.innerHTML = childSVG.outerHTML;
prepareSVG();
document.querySelector("#search-results").style.display = "none";
svgtopng();
})
.catch((error) => {
console.log(error);
});
}