-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
82 lines (62 loc) · 2.18 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!doctype html>
<html class="no-js" lang="">
<head>
<link href="resources/favicon.ico" rel="shortcut icon" type="image/x-icon">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<button class="action hide" id="theButton">Bet you wont</button>
<audio class="meow" id="meow"></audio>
<div class="loading" id="loading">
<img src="resources/OGSpaceCat.jpg" />
<img src="resources/GiphyLogo.png" alt="Powered By Giphy.com">
</div>
<img class="cat-pic" id="pictureGoesHere" src="" />
<div class="issues-container">
<a class="issues-link" href="https://github.com/what-a-time-to-be-alive/what-a-time-to-be-alive/issues" target="_blank">Help us improve this site.</a>
</div>
<script>
var button = document.getElementById('theButton');
var meow = document.getElementById('meow');
var loading = document.getElementById('loading');
var img = document.getElementById('pictureGoesHere');
var xhttp = new XMLHttpRequest();
var array = [];
var meowSrcArray = [
'./resources/audio/meow-1.mp3',
'./resources/audio/meow-2.mp3',
'./resources/audio/meow-3.mp3',
'./resources/audio/meow-4.mp3',
'./resources/audio/meow-5.mp3',
'./resources/audio/meow-6.mp3',
'./resources/audio/meow-7.mp3',
'./resources/audio/meow-8.mp3',
];
function transferComplete() {
array = JSON.parse(this.responseText).data;
loading.classList.add('hide');
button.classList.remove('hide');
return array;
}
function returnItem(array) {
return array[Math.floor(Math.random() * array.length)];
}
xhttp.addEventListener("load", transferComplete);
xhttp.open("GET", "https://api.giphy.com/v1/gifs/search?q=space+cat&api_key=dc6zaTOxFJmzC", true);
xhttp.send();
button.addEventListener("click", function () {
var item = returnItem(array);
var audioMeow = returnItem(meowSrcArray);
meow.setAttribute("src", audioMeow);
loading.classList.remove('hide');
img.classList.add('hide');
img.src = item.images.original.url;
setTimeout(function () {
loading.classList.add('hide');
img.classList.remove('hide');
meow.play();
}, 1000)
});
</script>
</body>
</html>