GitHub Search
@@ -30,4 +32,5 @@
+
\ No newline at end of file
diff --git a/js/index.js b/js/index.js
index e69de29..7cc1b78 100644
--- a/js/index.js
+++ b/js/index.js
@@ -0,0 +1,49 @@
+document.addEventListener("DOMContentLoaded", function () {
+ const form = document.getElementsByTagName("form")[0];
+ const userList = document.getElementById("user-list");
+ const repoList = document.getElementById("repos-list");
+ const inputVal = document.getElementById("search");
+ form.addEventListener("submit", searchUser);
+ function searchUser(e) {
+ e.preventDefault();
+ userList.innerHTML = "";
+ repoList.innerHTML = "";
+ return fetch(`https://api.github.com/search/users?q=${inputVal.value}`)
+ .then((response) => response.json())
+ .then((profile) => {
+ profile.items.forEach((user) => {
+ let listItem = document.createElement("li");
+ listItem.innerHTML = `${user.login}
+ GitHub Search
+ Profile Link
+
+
+
+
+ `;
+ let btn = listItem.querySelector(".repo-btn");
+ btn.addEventListener("click", function () {
+ searchRepo(user);
+ });
+ userList.appendChild(listItem);
+ });
+ inputVal.value = "";
+ });
+ }
+
+ function searchRepo(user) {
+ return fetch(`https://api.github.com/users/${user.login}/repos`)
+ .then((response) => response.json())
+ .then((json) =>
+ json.forEach((repo) => {
+ let repoListItem = document.createElement("li");
+ repoListItem.innerHTML = `
+ ${repo.name}
+ `;
+ repoList.appendChild(repoListItem);
+ })
+ );
+ }
+});