-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
139 lines (117 loc) · 4.84 KB
/
index.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Who is not following you back on GitHub?</title>
<style>
.clean-link {
color: inherit;
text-decoration: none; /* no underline */
}
</style>
</head>
<body>
<header>
<h1>
<a href="" class="clean-link">
Who is not following you back on GitHub?
</a>
</h1>
</header>
<main>
<!-- username input -->
<form id="username_form">
<input type="text" name="username" id="username" value="" placeholder="Your GitHub username">
<input type="submit" value="Submit" id="username_submit" />
</form>
<!-- who's not following div -->
<div id="whos_not_following"></div>
</main>
<footer>
<hr>
<p>
<span>🤝</span> Please, support the project if you like it:
</p>
<ul>
<li><span>⭐️</span> Star us on Github: <a href="https://github.com/whosnotfollowing/whosnotfollowing.github.io">https://github.com/whosnotfollowing/whosnotfollowing.github.io</a></li>
<li><span>✉️</span> Send a link to your friend: <a href="https://whosnotfollowing.github.io">https://whosnotfollowing.github.io</a></li>
<li><span>🌐</span> Post a link on social media: <a href="https://whosnotfollowing.github.io">https://whosnotfollowing.github.io</a></li>
</ul>
<p>
<a href="https://github.com/artkirienko" title="Follow me, I'll follow back 😉">Artem Kirienko</a> © 2012-<span id="year">2022</span>
</p>
</footer>
<script type="module">
console.log('Setting current copyright year')
document.getElementById("year").innerHTML = new Date().getFullYear();
console.log('Loading octokit directly from cdn.skypack.dev...');
import { Octokit, App } from "https://esm.sh/octokit";
console.log('Success!');
const octokit = new Octokit();
let username_form = document.getElementById("username_form");
username_form.addEventListener("submit", async function(event){
event.preventDefault();
// Remove whos_not_following div
// get elements
let child = document.getElementById("whos_not_following");
let parent = document.body.querySelector('main');
// Delete child
if (!!child) {
parent.removeChild(child)
}
// Get username
let login = username_form.querySelector('input[name=username]').value;
if (!!login) {
console.log('Click');
// Disable username submit button
document.getElementById('username_submit').disabled = true;
// Get followers
console.log(`Geting followers for ${login}`);
let followers = (await octokit.paginate(octokit.rest.users.listFollowersForUser, {username: login, per_page: 100})).map(a => a.login);
console.log(followers);
// Get following
console.log(`Geting following for ${login}`);
let following = (await octokit.paginate(octokit.rest.users.listFollowingForUser, {username: login, per_page: 100})).map(a => a.login);
console.log(following);
// Calculate who is not following back
console.log(`Who is not following ${login} back on GitHub?`);
let whos_not_following = following.filter(x => !followers.includes(x));
console.log(whos_not_following);
// Re-create whos_not_following div
let container = document.createElement("div");
container.setAttribute("id", "whos_not_following");
parent.appendChild(container);
// Create title
let h2 = document.createElement("h2");
let not_following_text = document.createTextNode(`Who is not following ${login} back on GitHub?`);
h2.appendChild(not_following_text);
container.appendChild(h2);
if (whos_not_following.length === 0) {
container.appendChild(document.createElement("h2").appendChild(document.createTextNode(`Success! Everyone is following ${login} back on GitHub`)));
} else {
// Create list
let list = document.createElement("ul");
container.appendChild(list);
whos_not_following.forEach((element) => {
let list_item = document.createElement("li");
let link_text = `https://github.com/${element}`;
let link = document.createElement("a");
link.setAttribute("href", link_text);
link.appendChild(document.createTextNode(element));
list_item.appendChild(link);
list.appendChild(list_item);
});
};
// Clear input
document.getElementById('username').value = '';
// Enable username submit button
document.getElementById('username_submit').disabled = false;
} else {
console.log('Click; no input');
};
});
</script>
</body>
</html>