const username = '2kabhishek'; const maxPages = 2; 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 function () { const res = await fetch( `https://api.github.com/users/${username}` // { // headers: { // Accept: 'application/vnd.github+json', // Authorization: 'token your-personal-access-token-here' // } // } ); const profile = await res.json(); displayProfile(profile); }; getProfile(); // display infomation from github profile const displayProfile = function (profile) { const userInfo = document.querySelector('.user-info'); userInfo.innerHTML = `
user avatar

${profile.name}

${profile.bio}

Location: ${profile.location}

@${profile.login} Repos: ${profile.public_repos} Gists: ${profile.public_gists}

`; }; // get list of user's public repos const getRepos = async function () { let repos = []; let res; for (let i = 1; i <= maxPages; i++) { res = await fetch( `https://api.github.com/users/${username}/repos?&sort=pushed&per_page=100&page=${i}` // { // headers: { // Accept: 'application/vnd.github+json', // Authorization: // 'token your-personal-access-token-here' // } // } ); let data = await res.json(); repos = repos.concat(data); } displayRepos(repos); }; getRepos(); // display list of all user's public repos const displayRepos = function (repos) { filterInput.classList.remove('hide'); for (const repo of repos) { let listItem = document.createElement('li'); listItem.classList.add('repo'); listItem.innerHTML = `

${repo.name}

${repo.description}

${devicons[repo.language]}

View Project`; repoList.append(listItem); } }; // dynamic search filterInput.addEventListener('input', function (e) { const search = e.target.value; const repos = document.querySelectorAll('.repo'); const searchLowerText = search.toLowerCase(); for (const repo of repos) { const lowerText = repo.innerText.toLowerCase(); if (lowerText.includes(searchLowerText)) { repo.classList.remove('hide'); } else { repo.classList.add('hide'); } } }); // for programming language icons const devicons = { Assembly: ' Assembly', 'C#': ' C#', 'C++': ' C++', C: ' C', Clojure: ' C', CoffeeScript: ' CoffeeScript', Crystal: ' Crystal', CSS: ' CSS', Dart: ' Dart', Dockerfile: ' Docker', Elixir: ' Elixir', Elm: ' Elm', Erlang: ' Erlang', 'F#': ' F#', Go: ' Go', Groovy: ' Groovy', HTML: ' HTML', Haskell: ' Haskell', Java: ' Java', JavaScript: ' JavaScript', Julia: ' Julia', 'Jupyter Notebook': ' Jupyter', Kotlin: ' Kotlin', Latex: ' Latex', Lua: ' Lua', Matlab: ' Matlab', Nim: ' Nim', Nix: ' Nix', ObjectiveC: ' ObjectiveC', OCaml: ' OCaml', Perl: ' Perl', PHP: ' PHP', PLSQL: ' PLSQL', Processing: ' Processing', Python: ' Python', R: ' R', Ruby: ' Ruby', Rust: ' Rust', Sass: ' Sass', Scala: ' Scala', Shell: ' Shell', Solidity: ' Solidity', Stylus: ' Stylus', Svelte: ' Svelte', Swift: ' Swift', Terraform: ' Terraform', TypeScript: ' TypeScript', 'Vim Script': ' Vim Script', Vue: ' Vue', null: ' Markdown' };