graphql-browser-client/js/currency.js

20 lines
No EOL
862 B
JavaScript

const currency = new URLSearchParams(window.location.search).get("currency");
const countryList = document.getElementById("country-list");
fetch("https://countries.trevorblades.com/", {
"method": "POST",
"body": JSON.stringify(
{
query: "", // Fill in Query here
"operationName": "countriesPayingIn",
"variables": { "currency": currency }
}),
headers: { "Content-Type": "application/json" }
}).then(response => response.json()).then(({ data }) => {
document.getElementById("currency").innerText = currency;
const countries = data.countries;
for (const country of countries) {
const newListItem = document.createElement("li");
newListItem.innerHTML = `<a href="/country.html?code=${country.code}"> ${country.name} </a>`;
countryList.append(newListItem);
}
});