-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.js
62 lines (57 loc) · 1.9 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
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
const usernameRef = document.querySelector(".username");
const submitBtnRef = document.querySelector(".submit");
const listRef = document.querySelector(".unFUser");
const errorRef = document.querySelector(".error");
const spinner = document.querySelector(".spinner-border");
var gh = new GitHub();
const generateTemplate = (user) => {
const htmlTemplate = `<li class="list-group-item d-flex justify-content-between align-items-center">
<a class="link" target="_blank" href="${user.html_url}">${user.login}</a>
<i class="fas fa-times delete" style="color:red;"></i>
</li>`;
listRef.innerHTML = htmlTemplate + listRef.innerHTML;
};
listRef.addEventListener("click", (e) => {
if (e.target.classList.contains("delete")) {
e.target.parentElement.remove();
const toDelete = e.target.parentElement.textContent.trim();
todosList = todosList.filter((item) => {
return item !== toDelete;
});
localStorage.clear();
localStorage.setItem("prevTodos", JSON.stringify(todosList));
}
});
submitBtnRef.addEventListener("click", (e) => {
e.preventDefault();
submitBtnRef.disabled = true;
listRef.innerHTML = "";
errorRef.innerHTML = "";
const userName = usernameRef.value.trim();
spinner.classList.remove("d-none");
gh.get(`users/${userName}/followers`, { all: true }, function (err, followers) {
if (err) {
console.log(err);
spinner.classList.add("d-none");
errorRef.innerHTML = "User Not Found";
} else {
errorRef.innerHTML = "";
gh.get(`users/${userName}/following`, { all: true }, function (err, following) {
if (err) {
console.log(err);
} else {
var diffrence = following.filter(function (obj) {
return !followers.some(function (obj2) {
return obj.login == obj2.login;
});
});
diffrence.forEach((user) => {
generateTemplate(user);
});
spinner.classList.add("d-none");
submitBtnRef.disabled = false;
}
});
}
});
});