-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
75 lines (56 loc) · 2.13 KB
/
main.js
File metadata and controls
75 lines (56 loc) · 2.13 KB
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
// Main Variables
let theInput = document.querySelector(".get-repos input");
let getButton = document.querySelector(".get-button");
let reposData = document.querySelector(".show-data");
getButton.onclick = function () {
getRepos();
};
// Get Repos Function
function getRepos() {
if (theInput.value == "") {
// If Value Is Empty
reposData.innerHTML = "<span>Please Write Github Username.</span>";
} else {
fetch(`https://api.github.com/users/${theInput.value}/repos`)
.then((response) => response.json())
.then((repositories) => {
// Empty The Container
reposData.innerHTML = "";
// Loop On Repositories
repositories.forEach((repo) => {
// Create The Main Div Element
let mainDiv = document.createElement("div");
// Create Repo Name Text
let repoName = document.createTextNode(repo.name);
// Append The Text To Main Div
mainDiv.appendChild(repoName);
// Create Repo URL Anchor
let theUrl = document.createElement("a");
// Create Repo Url Text
let theUrlText = document.createTextNode("Visit");
// Append The Repo Url Text To Anchor Tag
theUrl.appendChild(theUrlText);
// Add Thje Hypertext Reference "href"
theUrl.href = `https://github.com/${theInput.value}/${repo.name}`;
// Set Attribute Blank
theUrl.setAttribute("target", "_blank");
// Append Url Anchor To Main Div
mainDiv.appendChild(theUrl);
// Create Stars Count Span
let starsSpan = document.createElement("span");
// Create The Stars Count Text
let starsText = document.createTextNode(
`Stars ${repo.stargazers_count}`
);
// Add Stars Count Text To Stars Span
starsSpan.appendChild(starsText);
// Append Stars Count Span To Main Div
mainDiv.appendChild(starsSpan);
// Add Class On Main Div
mainDiv.className = "repo-box";
// Append The Main Div To Container
reposData.appendChild(mainDiv);
});
});
}
}