forked from sage31/Gradient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
93 lines (82 loc) · 3.01 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
let year1 = new Date().getFullYear();
let year2 = year1 + 1;
let year3 = year2 + 1;
let year4 = year3 + 1;
let year5 = year4 + 1;
y1 = document.getElementById("y1");
y1.innerHTML = year1;
y2 = document.getElementById("y2");
y2.innerHTML = year2;
y3 = document.getElementById("y3");
y3.innerHTML = year3;
y4 = document.getElementById("y4");
y4.innerHTML = year4;
y5 = document.getElementById("y5");
y5.innerHTML = year5;
function formatName(name) {
//only capitalize first letter of name, rest is lowercase
return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
}
function removeCrush(removeID, uid, parent, name, year) {
fetch("https://SCUCrushes-Server.ethancl.repl.co/removeCrush", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ removeID: removeID, uid: window.uid, community: localStorage.getItem("community") }),
})
.then((response) => response.json())
.then((data) => {
if (data.success) {
if (data.match) {
//find match in matchesHTML and delete it
let matchesHTML = document.getElementById("matchesHTML");
let matches = matchesHTML.children;
for (let i = 0; i < matches.length; i++) {
if (matches[i].children[0].children[0].children[0].innerHTML == name && matches[i].children[0].children[0].children[2].innerHTML == year) {
matches[i].remove();
break;
}
}
//decrement matchesNum
let matchesNum = document.getElementById("matchesNum");
matchesNum.innerHTML = parseInt(matchesNum.innerHTML) - 1;
if (document.getElementById("matchesNum").innerHTML == 1) {
document.getElementById("matchText").innerHTML = "Match";
}
else {
document.getElementById("matchText").innerHTML = "Matches";
}
}
//remove crush from HTML
parent.remove();
//decrement crushesNum
let crushesNum = document.getElementById("crushesNum");
crushesNum.innerHTML = parseInt(crushesNum.innerHTML) - 1;
if (document.getElementById("crushesNum").innerHTML == 1) {
document.getElementById("crushText").innerHTML = "Crush";
}
else {
document.getElementById("crushText").innerHTML = "Crushes";
}
}
else {
alert("Error removing crush.");
}
});
}
function openPopup(node) {
var firstName = node.children[0].children[0].innerHTML;
var removeID = node.children[2].children[0].innerHTML;
var year = node.children[0].children[2].innerHTML;
document.getElementById("popup").style.display = "flex";
document.getElementById("popup-name").innerHTML = firstName;
//if they press popup-delete, remove crush
document.getElementById("popup-delete").onclick = function () {
removeCrush(removeID, localStorage.getItem("userID"), node.parentNode, firstName, year);
closePopup();
}
}
function closePopup() {
document.getElementById("popup").style.display = "none";
}