-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
30 lines (27 loc) · 1.04 KB
/
app.js
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
var after = ''
function fetchMemes(){
colorChange();
if (document.getElementById('memes')) {
document.getElementById('memes').remove()
}
let parentdiv = document.createElement("div")
parentdiv.id = "memes";
fetch(`https://www.reddit.com/r/memes.json?after=${after}`)
.then(response => response.json())
.then(body => {
after=body.data.after;
for (let index = 0; index < body.data.children.length; index++){
if (body.data.children[index].data.post_hint === "image"){
let div = document.createElement("div");
let h4 = document.createElement("h4");
let image = document.createElement("img");
image.src = body.data.children[index].data.url_overridden_by_dest;
h4.textContent = body.data.children[index].data.title;
div.appendChild(h4);
div.appendChild(image);
parentdiv.appendChild(div);
}
}
document.body.appendChild(parentdiv);
})
}