const username = 'littleblack111';
const hideForks = true;
const repoList = document.querySelector('.repo-list');
const reposSection = document.querySelector('.repos');
const filterInput = document.querySelector('.filter-repos');
// get information from github profile
const getProfile = async () => {
const res = await fetch(
`https://api.github.com/users/${username}`,
);
const profile = await res.json();
displayProfile(profile);
};
getProfile();
// display infomation from github profile
const displayProfile = (profile) => {
const userInfo = document.querySelector('.user-info');
userInfo.innerHTML = `
${profile.bio}
Mail: ${profile.email}
Location: ${profile.location}
@${profile.login}
Repos: ${profile.public_repos}
Gists: ${profile.public_gists}
`;
};
// get list of user's public repos
const getRepos = async () => {
let repos = [];
let res;
res = await fetch(
`https://api.github.com/users/${username}/repos?&sort=pushed`,
);
let data = await res.json();
repos = repos.concat(data);
repos.sort((a, b) => b.forks_count - a.forks_count);
repos.sort((a, b) => b.stargazers_count - a.stargazers_count);
displayRepos(repos);
};
getRepos();
// display list of all user's public repos
const displayRepos = (repos) => {
const userHome = `https://github.com/${username}`
filterInput.classList.remove('hide');
for (const repo of repos) {
if (repo.fork && hideForks) {
continue;
}
const langUrl = `${userHome}?tab=repositories&q=&language=${repo.language}`
const starsUrl = `${userHome}/${repo.name}/stargazers`
const forksUrl = `${userHome}/${repo.name}/network/members`
let listItem = document.createElement('li');
listItem.classList.add('repo', 'animate', 'zoomIn')
listItem.innerHTML = `