-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
36 lines (33 loc) · 1.12 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Nekosia API</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<button onclick="catchNeko()">Catch neko</button>
<img src="" alt="Meow" id="neko">
<script>
const nekoImg = document.getElementById('neko');
const catchNeko = async () => {
try {
const res = await fetch('https://api.nekosia.cat/api/v1/images/catgirl');
const json = await res.json();
if (json.success) {
nekoImg.src = json.image.compressed.url;
nekoImg.alt = `ID: ${json.id}`;
nekoImg.title = json.attribution.copyright;
nekoImg.style.boxShadow = `0 0 22px ${json.colors.main}`;
} else {
alert('Request failed, please try again.')
}
} catch (err) {
console.error(err);
alert(err.message);
}
};
</script>
</body>
</html>