diff --git a/index.html b/index.html index 6484c80e..e6170561 100644 --- a/index.html +++ b/index.html @@ -118,6 +118,8 @@

Awesome GitHub Profile READMEs

diff --git a/scripts/retriveprofile.js b/scripts/retriveprofile.js index 72fd80c1..7073b1ee 100644 --- a/scripts/retriveprofile.js +++ b/scripts/retriveprofile.js @@ -254,6 +254,10 @@ function renderProfiles(filter = "") { viewCount.className = "view-count"; viewCount.innerHTML = ' Views: Loading...'; // Placeholder text + const likeCount = document.createElement("p"); + likeCount.className = "like-count"; + likeCount.innerHTML = ' Likes: Loading...'; + // Retrieve and listen to view count from Firebase const profileRef = firebase.database().ref(`profiles/${contributor.login}/views`); profileRef.on("value", (snapshot) => { @@ -266,6 +270,17 @@ function renderProfiles(filter = "") { } }); + // Retrieve and listen to like count from Firebase + const profileRefLikes = firebase.database().ref(`profiles/${contributor.login}/likes`); + profileRefLikes.on("value", (snapshot) => { + if (snapshot.exists()) { + likeCount.innerHTML = ` Likes: ${snapshot.val()}`; + } else { + profileRefLikes.set(0); + likeCount.innerHTML = ' Likes: 0'; + } + }); + // Increment view count on click card.addEventListener("click", (e) => { e.preventDefault(); @@ -279,6 +294,7 @@ function renderProfiles(filter = "") { card.appendChild(imgContainer); card.appendChild(name); card.appendChild(viewCount); + card.appendChild(likeCount); card.classList.add("profile-card"); container.appendChild(card); @@ -293,6 +309,7 @@ document.addEventListener('DOMContentLoaded', () => { const caretDown = document.getElementById('caret-down'); const closeButton = document.getElementById('close-button'); const views = document.getElementsByClassName('views'); + const likes = document.getElementsByClassName('likes'); Array.from(views).map((ele)=>{ @@ -340,6 +357,52 @@ document.addEventListener('DOMContentLoaded', () => { } }) }) + + Array.from(likes).map((ele)=>{ + ele.addEventListener(('click'),(e)=>{ + close() + if(e.target.innerHTML=="Least Likes"){ + + fetch("https://raw.githubusercontent.com/recodehive/awesome-github-profiles/main/.all-contributorsrc") + .then((response) => response.json()) + .then((data) => { + contributors = data.contributors; + contributors.map((data)=>{ + const profileRefLikes = firebase.database().ref(`profiles/${data.login}/likes`) + profileRefLikes.on("value", (snapshot) => { + if (snapshot.exists()) { + data['likes']=snapshot.val() + } else { + profileRefLikes.set(0); + } + }); + }) + contributors=contributors.sort((a,b)=>a.likes-b.likes) + renderProfiles(); + }); + }else{ + fetch("https://raw.githubusercontent.com/recodehive/awesome-github-profiles/main/.all-contributorsrc") + .then((response) => response.json()) + .then((data) => { + contributors = data.contributors; + contributors.map((data)=>{ + const profileRefLikes = firebase.database().ref(`profiles/${data.login}/likes`) + profileRefLikes.on("value", (snapshot) => { + if (snapshot.exists()) { + data['likes']=snapshot.val() + } else { + // Handle new profile + profileRefLikes.set(0); + } + }); + }) + contributors=contributors.sort((a,b)=>b.likes-a.likes) + renderProfiles(); + }); + } + }) + }) + caretDown.addEventListener('click', (event) => { if(modal.style.display=="block"){ modal.style.display="none"