-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathscripts.js
70 lines (58 loc) · 2.12 KB
/
scripts.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
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
const app = document.getElementById('root')
const container = document.createElement('div')
container.setAttribute('class', 'container')
app.appendChild(container)
var request = new XMLHttpRequest()
request.open('GET', 'https://gsconfessions.herokuapp.com/?format=json', true)
// request.open('GET', 'https://localhost:8000', true)
request.onload = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response)
if (request.status >= 200 && request.status < 400) {
console.log(data)
data.forEach((movie,index) => {
const card = document.createElement('div')
card.setAttribute('id', index)
card.setAttribute('class', 'card')
card.setAttribute('ondblclick', 'setLikeDislike(this)')
const h1 = document.createElement('h1')
h1.textContent = '<Name for whom this is>'
const p = document.createElement('p')
p.textContent = movie.title
const cardBut = document.createElement('div')
cardBut.setAttribute('class', 'card-buttons')
const span = document.createElement('i')
span.setAttribute('class','fa fa-eye icon')
span.textContent=(' 111')
const span2 = document.createElement('i')
span2.setAttribute('class','fa fa-heart icon heart-icon')
span2.textContent=('')
span2.setAttribute('onclick', 'setIconLikeDislike(this)')
var t = document.createElement('div')
t.setAttribute('class','date')
var timestamp = Date.now();
var d = new Date(timestamp);
t.textContent=(d)
cardBut.appendChild(span)
cardBut.appendChild(span2)
container.appendChild(card)
card.appendChild(h1)
card.appendChild(p)
card.appendChild(t)
card.appendChild(cardBut)
})
} else {
const errorMessage = document.createElement('marquee')
errorMessage.textContent = `Gah, it's not working!`
app.appendChild(errorMessage)
}
}
request.send()
function setLikeDislike(obj){
var t1 = document.getElementById(obj.id).childNodes;
var t2 = t1[3].childNodes;
t2[1].classList.toggle("liked");
}
function setIconLikeDislike(obj){
obj.classList.toggle("liked");
}