-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
45 lines (43 loc) · 1.44 KB
/
main.js
File metadata and controls
45 lines (43 loc) · 1.44 KB
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
var thumbUp = document.getElementsByClassName("fa-thumbs-up");
var trash = document.getElementsByClassName("fa-trash-o");
Array.from(thumbUp).forEach(function(element) {
element.addEventListener('click', function(){
const name = this.parentNode.parentNode.childNodes[1].innerText
const msg = this.parentNode.parentNode.childNodes[3].innerText
const thumbUp = parseFloat(this.parentNode.parentNode.childNodes[5].innerText)
fetch('messages', {
method: 'put',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
'name': name,
'msg': msg,
'thumbUp':thumbUp
})
})
.then(response => {
if (response.ok) return response.json()
})
.then(data => {
console.log(data)
window.location.reload(true)
})
});
});
Array.from(trash).forEach(function(element) {
element.addEventListener('click', function(){
const name = this.parentNode.parentNode.childNodes[1].innerText
const msg = this.parentNode.parentNode.childNodes[3].innerText
fetch('messages', {
method: 'delete',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'name': name,
'msg': msg
})
}).then(function (response) {
window.location.reload()
})
});
});