-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
75 lines (59 loc) · 2.02 KB
/
content.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
window.onload = function(){
setInterval(function() {
if (user_username == "rootcf" && !document.getElementById("bettergithub-owner")) {
document.querySelector('.vcard-username').insertAdjacentHTML('beforeend', '<img title="Creator of BetterGitHub" src="https://cdn-icons-png.flaticon.com/512/6364/6364343.png" id="bettergithub-owner">');
}
if (!document.getElementById("bettergithub-follows-you")){
var login_username = String(document.querySelector('meta[name="user-login"]').getAttribute("content"));
var user_username = String(document.querySelector('meta[name="octolytics-dimension-user_login"]').getAttribute("content"));
const followingLink = document.querySelectorAll('.Link--secondary.no-underline.no-wrap');
const perPage = 100;
let page = 1;
let users = [];
const getFollowings = async (username) => {
let followingURL = `https://api.github.com/users/${username}/following`;
let followings = [];
while (followingURL) {
const response = await fetch(followingURL);
const data = await response.json();
followings = followings.concat(data);
// sonraki sayfaya ait bağlantıyı al
const linkHeader = response.headers.get('Link');
if (linkHeader) {
const nextLink = linkHeader.split(',').find(link => link.includes('rel="next"'));
if (nextLink) {
followingURL = nextLink.split(';')[0].trim().slice(1, -1);
} else {
followingURL = null;
}
} else {
followingURL = null;
}
}
return followings;
};
const myPromise = new Promise((resolve, reject) => {
const followings = getFollowings(String(user_username));
resolve(followings);
});
myPromise.then((result) => {
for (const following of result) {
if (following.login === login_username) {
if (!document.getElementById("bettergithub-follows-you")){
followingLink[1].insertAdjacentHTML('afterend', '<br><p id="bettergithub-follows-you">Follows you</p>');
break;
}
else{
return;
}
}
}
}).catch((error) => {
// Handle error
});
}
else{
return;
}
},200);
};