-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (54 loc) · 2.1 KB
/
Copy pathscript.js
File metadata and controls
68 lines (54 loc) · 2.1 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
const detailsContainer = document.querySelector(".details")
const inputBox = document.querySelector(".inputBox")
const searchBtn = document.querySelector(".search")
const repoList = document.querySelector(".repoList")
const pp = document.querySelector(".pp")
const gusername = document.querySelector(".username")
const bio = document.querySelector(".bio")
const follower = document.querySelector(".follower")
const following = document.querySelector(".following")
const repository = document.querySelector(".repository")
const repoH = document.querySelector(".repoH")
// initially its my profile
loadPrfile("Codeyry")
searchBtn.addEventListener("click", () => {
loadPrfile(inputBox.value)
})
async function loadPrfile(username) {
try {
if (inputBox.value === "" && username === "") {
alert("Please enter a username")
return
}
const url = `https://api.github.com/users/${username}`
const response = await fetch(url)
const data = await response.json()
console.log(data)
pp.src = data.avatar_url
gusername.textContent = data.name
bio.textContent = data.bio
follower.textContent = data.followers
following.textContent = data.following
repository.textContent = data.public_repos
detailsContainer.classList.remove("hidden");
const repoUrl = `https://api.github.com/users/${username}/repos`
const repoResponse = await fetch(repoUrl)
const repoData = await repoResponse.json()
console.log(repoData)
repoH.textContent = `Repositories (${repoData.length}):`
// repoData.sort((a, b) => b.stargazers_count - a.stargazers_count)
// const topRepos = repoData.slice(0, 5)
// console.log(topRepos)
repoList.innerHTML = "";
repoData.forEach(repo => {
const a = document.createElement("a")
a.href = repo.html_url
a.target = "_blank"
a.textContent = repo.name
repoList.appendChild(a)
});
inputBox.value = ""
} catch (error) {
console.log(error)
}
}