-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalo-api.js
More file actions
48 lines (40 loc) · 1.9 KB
/
valo-api.js
File metadata and controls
48 lines (40 loc) · 1.9 KB
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
41
42
43
44
45
46
47
48
async function fetchAgent() {
try {
const agentName = document.getElementById("agentName").value.toLowerCase();
const response = await fetch(`https://valorant-api.com/v1/agents`);
if (!response.ok) {
throw new Error("Could not fetch agents data");
}
const parsedData = await response.json();
let foundAgent = null;
parsedData.data.forEach(agent => {
if (agent.displayName.toLowerCase() === agentName) {
foundAgent = agent;
return; // Exit the loop once the agent is found
}
});
//if the input is matched with the displayName then we return the following fields
if (foundAgent) {
const agentInfoContainer = document.getElementById("agentInfo");
agentInfoContainer.innerHTML = ""; // Clear previous data
const nameElement = document.createElement("p");
nameElement.textContent = `Agent Name: ${foundAgent.displayName}`;
agentInfoContainer.appendChild(nameElement);
const developerElement = document.createElement("p");
developerElement.textContent = `Agent Developer Name: ${foundAgent.developerName}`;
agentInfoContainer.appendChild(developerElement);
const descriptionElement = document.createElement("p");
descriptionElement.textContent = `Agent Description: ${foundAgent.description}`;
agentInfoContainer.appendChild(descriptionElement);
const imageElement = document.getElementById("agentImage");
imageElement.src = foundAgent.displayIcon;
imageElement.style.display = "block"; // Show the image
} else {
alert("Agent not found");
console.log('Agent not found');
}
} catch (error) {
console.error("Error:", error);
}
}
fetchAgent(); //call the function