-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRanking.js
More file actions
99 lines (65 loc) · 2.95 KB
/
Ranking.js
File metadata and controls
99 lines (65 loc) · 2.95 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
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
94
95
96
97
98
99
let search_user_input = document.getElementById("search-user-input");
let ranking_table = document.getElementById("ranking-table");
// ------------------------------------------------------------------------------------------------
let brogrammerz = JSON.parse(localStorage.getItem("brogrammerz")) || [];
let logged_in_user_email = JSON.parse(localStorage.getItem("logged-in-user-email")) || "";
// ------------------------------------------------------------------------------------------------
let logged_in_user = brogrammerz.find((filter_user) => {
return filter_user.email == logged_in_user_email;
});
// ------------------------------------------------------------------------------------------------
window.addEventListener("load", () => {
if (!logged_in_user) {
alert("User Is Not Logged In! Redirecting To Login Page.");
location = "index.html";
};
show_ranking();
});
// ------------------------------------------------------------------------------------------------
function search_users() {
if (search_user_input.value != "") {
location = `Search.html?name=${search_user_input.value}`;
}
else {
alert("Please Insert The User's Name!");
}
};
// ------------------------------------------------------------------------------------------------
function explore() {
location = "Explore.html";
};
// ------------------------------------------------------------------------------------------------
function your_profile() {
location = "Profile.html";
};
// ------------------------------------------------------------------------------------------------
function show_ranking() {
let ranked_users = brogrammerz.sort((a, b) => b.followers.length - a.followers.length);
ranked_users.forEach((user, rank) => {
let new_row = document.createElement("tr");
let rank_td = document.createElement("td");
rank_td.textContent = rank + 1;
let name_td = document.createElement("td");
name_td.textContent = user.name;
name_td.onmouseover = function () {
name_td.style.color = "blue";
name_td.style.textDecoration = "underline";
name_td.style.cursor = "pointer";
};
name_td.onmouseout = function () {
name_td.style.color = "black";
name_td.style.textDecoration = "none";
name_td.style.cursor = "pointer";
};
name_td.addEventListener("click", () => {
localStorage.setItem("show-user-email", JSON.stringify(user.email));
location = "User.html";
});
let followers_td = document.createElement("td");
followers_td.textContent = user.followers.length;
new_row.appendChild(rank_td);
new_row.appendChild(name_td);
new_row.appendChild(followers_td);
ranking_table.appendChild(new_row);
});
};