-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
45 lines (37 loc) · 984 Bytes
/
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
<!DOCTYPE html>
<html>
<head></head>
<body style="display:flex;height: 100vh;flex-direction: column;justify-content: center;align-items: center;margin: 0;">
<h1>Hmmmm</h1>
<button type="button" id="another">Another one pls</button>
<div style="height: 100%;">
<img id="img" style="max-height: 80%; max-width: 100%"/>
</div>
<script>
function random() {
fetch('https://www.reddit.com/r/hmmm/random.json')
.then(data => data.json())
.then(json => {
if(json[0].data.children[0].data.over_18) {
return Promise.reject('nsfw');
}
return json[0].data.children[0].data.url
})
.then(url => {
document.getElementById('img').setAttribute('src', url);
})
.catch(err => {
console.log(err);
random();
})
}
document.getElementById("another").onclick = function(e) {
random();
}
window.onload = function(e){
random();
setInterval(random, 60*1000);
}
</script>
</body>
</html>