Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimized the render function #8075

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,18 @@ function filterUsers(str = "ContributorName", array) {
* @param {Array} array - The array of contributors to render.
*/
function render(array) {
const fragment = document.createDocumentFragment();
array.forEach((item) => {
let username = document.createElement("span");
username.innerHTML = item.fullname;

let user = document.createElement("a");
user.className = "box-item";
user.setAttribute("href", item.username);
user.setAttribute("id", item.id);
user.append(username);

if (item.id <= initialContributorsNumber) {
document.getElementById("contributors").append(user);
let user = document.createElement("a");
user.className = "box-item";
user.setAttribute("href", item.username);
user.setAttribute("id", item.id);
user.innerHTML = `<span>${item.fullname}</span><img loading="lazy" src="https://avatars.githubusercontent.com/${item.username.split("https://github.com/")[1]}">`;
fragment.appendChild(user);
}
});
document.getElementById("contributors").appendChild(fragment);
}

// Load contributors after document loads.
Expand Down Expand Up @@ -216,3 +214,4 @@ $(".tdnn").click(function () {
document.getElementById(
"stats"
).innerHTML = `You guys are awesome, we have again passed the GitHub rate limit this hour. <a href="https://github.com/fineanmol/Hacktoberfest${currentYear}" target="_blank">Here</a> is a link to check out our repo's live stats.`;

Loading