From 93a8fbf55492880ddebd9f47064940c2d49000d3 Mon Sep 17 00:00:00 2001 From: Anurag Pandey Date: Tue, 4 Jun 2024 20:06:19 +0530 Subject: [PATCH 1/2] fixed api fetch issue --- assets/contributors/contributor.js | 172 ++++++++++++++++------------- 1 file changed, 97 insertions(+), 75 deletions(-) diff --git a/assets/contributors/contributor.js b/assets/contributors/contributor.js index 7515bfe46..c4ff3dba3 100644 --- a/assets/contributors/contributor.js +++ b/assets/contributors/contributor.js @@ -2,103 +2,125 @@ const hamBurger = document.querySelector(".hamburger"); const nMenu = document.querySelector(".nav-menu"); document.addEventListener("DOMContentLoaded", function () { - setTimeout(function () { - document.querySelector("body").classList.add("loaded"); - }, 500) + setTimeout(function () { + document.querySelector("body").classList.add("loaded"); + }, 500); }); -// Hamburger menu +// Hamburger menu hamBurger.addEventListener("click", mobileMenu); function mobileMenu() { - hamBurger.classList.toggle("active"); - nMenu.classList.toggle("active"); + hamBurger.classList.toggle("active"); + nMenu.classList.toggle("active"); } -const cont = document.getElementById('contributor'); -const owner = 'Rakesh9100'; -const repoName = 'CalcDiverse'; +const cont = document.getElementById("contributor"); +const owner = "Rakesh9100"; +const repoName = "CalcDiverse"; async function fetchContributors(pageNumber) { - const perPage = 100; - const url = `https://api.github.com/repos/${owner}/${repoName}/contributors?page=${pageNumber}&per_page=${perPage}`; + const apiUrl = + "https://script.googleusercontent.com/macros/echo?user_content_key=HIngl5N6XqT87RP5_NGfOvh4Owd0vsFxGl4j7WfN5JA7XmZ3wfLP6Lm9KtE8MvYr-xqtib3jFCNoJ3gLd--RXPTM6yeCqYRMm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnJlUuZlL1ANkgTfzluynVq_ujwIhHMAx6EPfzKkWJ1uCshAjBuwXySyQgwTqiBx63rp_lIW_4lqd8qNYusW-W_j7amvZZ0XS2Q&lib=MVYp2QNGGJIwIlwc0BFDww2ojRkgaZCOe"; - const response = await fetch(url); - if (!response.ok) { - throw new Error(`Failed to fetch contributors data. Status code: ${response.status}`); + async function getkey() { + try { + const response = await fetch(apiUrl); + if (!response.ok) { + throw new Error("Network response was not ok"); + } + const data = await response.json(); + return data.apik[0].apikey; + } catch (error) { + console.error("Error fetching data:", error); } - - const contributorsData = await response.json(); - return contributorsData; + } + const token = await getkey(); + const perPage = 100; + const url = `https://api.github.com/repos/${owner}/${repoName}/contributors?page=${pageNumber}&per_page=${perPage}`; + + const response = await fetch(url, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + if (!response.ok) { + throw new Error( + `Failed to fetch contributors data. Status code: ${response.status}` + ); + } + + const contributorsData = await response.json(); + return contributorsData; } // Function to fetch all contributors async function fetchAllContributors() { - let allContributors = []; - let pageNumber = 1; - - try { - while (true) { - const contributorsData = await fetchContributors(pageNumber); - if (contributorsData.length === 0) { - break; - } - allContributors = allContributors.concat(contributorsData); - pageNumber++; - } - allContributors.forEach((contributor) => { - if (contributor.login === owner) { - return; - } - - const contributorCard = document.createElement('div'); - contributorCard.classList.add('contributor-card'); - - const avatarImg = document.createElement('img'); - avatarImg.src = contributor.avatar_url; - avatarImg.alt = `${contributor.login}'s Picture`; - - const loginLink = document.createElement('a'); - loginLink.href = contributor.html_url; - loginLink.target = '_blank'; - loginLink.appendChild(avatarImg); - - contributorCard.appendChild(loginLink); - - cont.appendChild(contributorCard); - }); - } catch (error) { - console.error(error); + let allContributors = []; + let pageNumber = 1; + + try { + while (true) { + const contributorsData = await fetchContributors(pageNumber); + if (contributorsData.length === 0) { + break; + } + allContributors = allContributors.concat(contributorsData); + pageNumber++; } + allContributors.forEach((contributor) => { + if (contributor.login === owner) { + return; + } + + const contributorCard = document.createElement("div"); + contributorCard.classList.add("contributor-card"); + + const avatarImg = document.createElement("img"); + avatarImg.src = contributor.avatar_url; + avatarImg.alt = `${contributor.login}'s Picture`; + + const loginLink = document.createElement("a"); + loginLink.href = contributor.html_url; + loginLink.target = "_blank"; + loginLink.appendChild(avatarImg); + + contributorCard.appendChild(loginLink); + + cont.appendChild(contributorCard); + }); + } catch (error) { + console.error(error); + } } fetchAllContributors(); let calcScrollValue = () => { - let scrollProg = document.getElementById("progress"); - let pos = document.documentElement.scrollTop; - let calcHeight = - document.documentElement.scrollHeight - - document.documentElement.clientHeight; - let scrollValue = Math.round((pos * 100) / calcHeight); - if (pos > 100) { - scrollProg.style.display = "grid"; - } else { - scrollProg.style.display = "none"; - } - scrollProg.addEventListener("click", () => { - document.documentElement.scrollTop = 0; - }); - scrollProg.style.background = `conic-gradient(#0063ba ${scrollValue}%, #d499de ${scrollValue}%)`; + let scrollProg = document.getElementById("progress"); + let pos = document.documentElement.scrollTop; + let calcHeight = + document.documentElement.scrollHeight - + document.documentElement.clientHeight; + let scrollValue = Math.round((pos * 100) / calcHeight); + if (pos > 100) { + scrollProg.style.display = "grid"; + } else { + scrollProg.style.display = "none"; + } + scrollProg.addEventListener("click", () => { + document.documentElement.scrollTop = 0; + }); + scrollProg.style.background = `conic-gradient(#0063ba ${scrollValue}%, #d499de ${scrollValue}%)`; }; -window.addEventListener('scroll', function () { - var scrollToTopButton = document.getElementById('progress'); - if (window.pageYOffset > 200) { - scrollToTopButton.style.display = 'block'; - } else { - scrollToTopButton.style.display = 'none'; - } +window.addEventListener("scroll", function () { + var scrollToTopButton = document.getElementById("progress"); + if (window.pageYOffset > 200) { + scrollToTopButton.style.display = "block"; + } else { + scrollToTopButton.style.display = "none"; + } }); window.onscroll = calcScrollValue; -window.onload = calcScrollValue; \ No newline at end of file +window.onload = calcScrollValue; From 69b57dc553193df687dd21b3be9d3597ec97957d Mon Sep 17 00:00:00 2001 From: Rakesh Roshan Date: Thu, 6 Jun 2024 18:47:27 +0530 Subject: [PATCH 2/2] Update contributor.js --- assets/contributors/contributor.js | 184 ++++++++++++++--------------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/assets/contributors/contributor.js b/assets/contributors/contributor.js index c4ff3dba3..1c4ce55ba 100644 --- a/assets/contributors/contributor.js +++ b/assets/contributors/contributor.js @@ -2,16 +2,17 @@ const hamBurger = document.querySelector(".hamburger"); const nMenu = document.querySelector(".nav-menu"); document.addEventListener("DOMContentLoaded", function () { - setTimeout(function () { - document.querySelector("body").classList.add("loaded"); - }, 500); + setTimeout(function () { + document.querySelector("body").classList.add("loaded"); + }, 500); }); // Hamburger menu hamBurger.addEventListener("click", mobileMenu); + function mobileMenu() { - hamBurger.classList.toggle("active"); - nMenu.classList.toggle("active"); + hamBurger.classList.toggle("active"); + nMenu.classList.toggle("active"); } const cont = document.getElementById("contributor"); @@ -19,107 +20,106 @@ const owner = "Rakesh9100"; const repoName = "CalcDiverse"; async function fetchContributors(pageNumber) { - const apiUrl = - "https://script.googleusercontent.com/macros/echo?user_content_key=HIngl5N6XqT87RP5_NGfOvh4Owd0vsFxGl4j7WfN5JA7XmZ3wfLP6Lm9KtE8MvYr-xqtib3jFCNoJ3gLd--RXPTM6yeCqYRMm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnJlUuZlL1ANkgTfzluynVq_ujwIhHMAx6EPfzKkWJ1uCshAjBuwXySyQgwTqiBx63rp_lIW_4lqd8qNYusW-W_j7amvZZ0XS2Q&lib=MVYp2QNGGJIwIlwc0BFDww2ojRkgaZCOe"; - - async function getkey() { - try { - const response = await fetch(apiUrl); - if (!response.ok) { - throw new Error("Network response was not ok"); - } - const data = await response.json(); - return data.apik[0].apikey; - } catch (error) { - console.error("Error fetching data:", error); + const apiUrl = "https://script.googleusercontent.com/macros/echo?user_content_key=HIngl5N6XqT87RP5_NGfOvh4Owd0vsFxGl4j7WfN5JA7XmZ3wfLP6Lm9KtE8MvYr-xqtib3jFCNoJ3gLd--RXPTM6yeCqYRMm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnJlUuZlL1ANkgTfzluynVq_ujwIhHMAx6EPfzKkWJ1uCshAjBuwXySyQgwTqiBx63rp_lIW_4lqd8qNYusW-W_j7amvZZ0XS2Q&lib=MVYp2QNGGJIwIlwc0BFDww2ojRkgaZCOe"; + + async function getkey() { + try { + const response = await fetch(apiUrl); + if (!response.ok) { + throw new Error("Network response was not ok"); + } + const data = await response.json(); + return data.apik[0].apikey; + } catch (error) { + console.error("Error fetching data:", error); + } + } + const token = await getkey(); + const perPage = 100; + const url = `https://api.github.com/repos/${owner}/${repoName}/contributors?page=${pageNumber}&per_page=${perPage}`; + + const response = await fetch(url, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + if (!response.ok) { + throw new Error( + `Failed to fetch contributors data. Status code: ${response.status}` + ); } - } - const token = await getkey(); - const perPage = 100; - const url = `https://api.github.com/repos/${owner}/${repoName}/contributors?page=${pageNumber}&per_page=${perPage}`; - - const response = await fetch(url, { - headers: { - Authorization: `Bearer ${token}`, - }, - }); - if (!response.ok) { - throw new Error( - `Failed to fetch contributors data. Status code: ${response.status}` - ); - } - - const contributorsData = await response.json(); - return contributorsData; + + const contributorsData = await response.json(); + return contributorsData; } // Function to fetch all contributors async function fetchAllContributors() { - let allContributors = []; - let pageNumber = 1; - - try { - while (true) { - const contributorsData = await fetchContributors(pageNumber); - if (contributorsData.length === 0) { - break; - } - allContributors = allContributors.concat(contributorsData); - pageNumber++; - } - allContributors.forEach((contributor) => { - if (contributor.login === owner) { - return; - } - - const contributorCard = document.createElement("div"); - contributorCard.classList.add("contributor-card"); - - const avatarImg = document.createElement("img"); - avatarImg.src = contributor.avatar_url; - avatarImg.alt = `${contributor.login}'s Picture`; + let allContributors = []; + let pageNumber = 1; - const loginLink = document.createElement("a"); - loginLink.href = contributor.html_url; - loginLink.target = "_blank"; - loginLink.appendChild(avatarImg); - - contributorCard.appendChild(loginLink); - - cont.appendChild(contributorCard); - }); - } catch (error) { - console.error(error); - } + try { + while (true) { + const contributorsData = await fetchContributors(pageNumber); + if (contributorsData.length === 0) { + break; + } + allContributors = allContributors.concat(contributorsData); + pageNumber++; + } + allContributors.forEach((contributor) => { + if (contributor.login === owner) { + return; + } + + const contributorCard = document.createElement("div"); + contributorCard.classList.add("contributor-card"); + + const avatarImg = document.createElement("img"); + avatarImg.src = contributor.avatar_url; + avatarImg.alt = `${contributor.login}'s Picture`; + + const loginLink = document.createElement("a"); + loginLink.href = contributor.html_url; + loginLink.target = "_blank"; + loginLink.appendChild(avatarImg); + + contributorCard.appendChild(loginLink); + + cont.appendChild(contributorCard); + }); + } catch (error) { + console.error(error); + } } fetchAllContributors(); let calcScrollValue = () => { - let scrollProg = document.getElementById("progress"); - let pos = document.documentElement.scrollTop; - let calcHeight = - document.documentElement.scrollHeight - - document.documentElement.clientHeight; - let scrollValue = Math.round((pos * 100) / calcHeight); - if (pos > 100) { - scrollProg.style.display = "grid"; - } else { - scrollProg.style.display = "none"; - } - scrollProg.addEventListener("click", () => { - document.documentElement.scrollTop = 0; - }); - scrollProg.style.background = `conic-gradient(#0063ba ${scrollValue}%, #d499de ${scrollValue}%)`; + let scrollProg = document.getElementById("progress"); + let pos = document.documentElement.scrollTop; + let calcHeight = + document.documentElement.scrollHeight - + document.documentElement.clientHeight; + let scrollValue = Math.round((pos * 100) / calcHeight); + if (pos > 100) { + scrollProg.style.display = "grid"; + } else { + scrollProg.style.display = "none"; + } + scrollProg.addEventListener("click", () => { + document.documentElement.scrollTop = 0; + }); + scrollProg.style.background = `conic-gradient(#0063ba ${scrollValue}%, #d499de ${scrollValue}%)`; }; window.addEventListener("scroll", function () { - var scrollToTopButton = document.getElementById("progress"); - if (window.pageYOffset > 200) { - scrollToTopButton.style.display = "block"; - } else { - scrollToTopButton.style.display = "none"; - } + var scrollToTopButton = document.getElementById("progress"); + if (window.pageYOffset > 200) { + scrollToTopButton.style.display = "block"; + } else { + scrollToTopButton.style.display = "none"; + } }); window.onscroll = calcScrollValue;