Skip to content

Commit 6b2a285

Browse files
committed
Initial commit
0 parents  commit 6b2a285

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

icons/icon-48.png

1.25 KB
Loading

icons/icon-96.png

2.96 KB
Loading

manifest.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Hacktoberfest Tag Detector",
4+
"version": "1.0",
5+
"description": "Detect whether the repository has opted into the 2020 Hacktoberfest.",
6+
"icons": {
7+
"96": "icons/icon-96.png",
8+
"48": "icons/icon-48.png"
9+
},
10+
"permissions": [
11+
"https://api.github.com/*"
12+
],
13+
"content_scripts": [
14+
{
15+
"matches": [
16+
"*://github.com/*"
17+
],
18+
"js": [
19+
"optindetector.js"
20+
]
21+
}
22+
]
23+
}

optindetector.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function checkIfEnrolled() {
2+
console.log("Requested tag check")
3+
let headers = new Headers();
4+
headers.append('Authorization', 'Basic ', btoa(`{GITHUB_API_USERNAME}:{GITHUB_API_TOKEN}`))
5+
6+
const targetItems = document.querySelector("[data-tab-item='code-tab']").attributes['href'].value.split("/")
7+
const user = targetItems[1]
8+
const repo = targetItems[2]
9+
console.log(targetItems);
10+
console.log(`Test user: ${user}, ${repo}`)
11+
console.log("TEST");
12+
13+
fetch("https://api.github.com/repos/" + user + "/" + repo + "/labels", {
14+
method: 'GET',
15+
headers: headers
16+
})
17+
.then(response => response.json())
18+
.then(json => {
19+
console.log(json);
20+
labelNames = json.map(i => i.name)
21+
const isHacktoberfestRepo = "hacktoberfest" in labelNames || "hacktoberfest-accepted" in labelNames
22+
document.body.style.border = isHacktoberfestRepo ? "5px solid green" : "5px solid blue";
23+
console.log(isHacktoberfestRepo ? "Hacktoberfest Tag Detector - Opted-in repository" : "Hacktoberfest Tag Detector - Not opted-in repository")
24+
})
25+
.catch(e => console.log(e))
26+
27+
}
28+
29+
let isGithubProjectPage = false;
30+
try {
31+
isGithubProjectPage = document.querySelector(".application-main").children[0].attributes["itemtype"].value === "http://schema.org/SoftwareSourceCode"
32+
} catch (e) {
33+
isGitHubProjectPage = false;
34+
}
35+
36+
if (isGithubProjectPage) {
37+
console.log("Hacktoberfest Tag Detector - GitHub Project detected");
38+
document.addEventListener("keyup", function (e) {
39+
var key = e.key || e.keyCode;
40+
if (key === 'h' || key === 'KeyH' || key === 72) {
41+
checkIfEnrolled()
42+
}
43+
});
44+
} else {
45+
console.log("Hacktoberfest Tag Detector - GitHub Project not detected");
46+
}

0 commit comments

Comments
 (0)