-
Notifications
You must be signed in to change notification settings - Fork 1
/
content.js
39 lines (32 loc) · 1.06 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
chrome.runtime.sendMessage({ action: "contentScriptLoaded" });
setTimeout(() => {
chrome.storage.local.get(["githubToken"], function (result) {
const aTags = document.querySelectorAll("a[href*='github.com/']");
const starCounts = [];
let responses = 0;
for (let i = 0; i < aTags.length; i++) {
let hrefWithoutHashTags = aTags[i].href.split("#")[0];
displayCachedOrRemoteGithubStars(
hrefWithoutHashTags,
result.githubToken,
stargazersCount => {
responses++;
if (stargazersCount === "NOT_A_REPO") {
return;
}
if (typeof stargazersCount !== "number") {
return;
}
aTags[i].innerHTML = `${aTags[i].innerHTML} [${GITHUB_STAR_MARK}${stargazersCount}]`;
starCounts.push({ repo: aTags[i].href, stargazersCount });
if (responses === aTags.length) {
chrome.runtime.sendMessage({
action: "storeStarCounts",
starCounts,
});
}
}
);
}
});
}, 2000);