export function renderLeetCode(data, username) { if (!data) { const card = createErrorCard('LeetCode', username, 'Profile data not available'); return card; } const card = createProfileCard('leetcode', 'LeetCode'); // Profile Header card.querySelector('.user-info').innerHTML = `
${data.realName || 'Anonymous'}
@${data.username || 'N/A'}
`; // Stats Grid - Expanded to show more stats const statsGrid = card.querySelector('.stats-grid'); statsGrid.innerHTML = `
${data.ranking ?? 'Unranked'}
Global Rank
${data.reputation ?? 0}
Reputation
${data.totalSolved || 0}
Problems Solved
${data.acceptanceRate || 0}%
Acceptance Rate
${data.currentStreak || 0}
Current Streak
${data.totalActiveDays || 0}
Active Days
${data.activeYears?.join(', ') || 'N/A'}
Active Years
${data.contestBadge?.name ? `
${data.contestBadge.name}
Contest Badge
` : ''} `; // About section if (data.aboutMe) { const aboutSection = document.createElement('div'); aboutSection.innerHTML = '

About

'; aboutSection.innerHTML += `

${data.aboutMe}

`; card.querySelector('.profile-body').appendChild(aboutSection); } // Professional info if (data.company || data.school || data.countryName || data.jobTitle) { const infoSection = document.createElement('div'); infoSection.innerHTML = '

Professional Info

'; const infoList = document.createElement('ul'); infoList.className = 'content-list'; if (data.company) { infoList.innerHTML += `
  • Company: ${data.company}${data.jobTitle ? ` (${data.jobTitle})` : ''}
  • `; } if (data.school) { infoList.innerHTML += `
  • School: ${data.school}
  • `; } if (data.countryName) { infoList.innerHTML += `
  • Country: ${data.countryName}
  • `; } infoSection.appendChild(infoList); card.querySelector('.profile-body').appendChild(infoSection); } // Social links const socialLinks = []; if (data.githubUrl) socialLinks.push(`GitHub`); if (data.linkedinUrl) socialLinks.push(`LinkedIn`); if (data.twitterUrl) socialLinks.push(`Twitter`); if (data.websites?.length) { data.websites.forEach(site => { if (site) socialLinks.push(`${site.replace(/^https?:\/\//, '')}`); }); } if (socialLinks.length > 0) { const socialSection = document.createElement('div'); socialSection.innerHTML = `

    Social Links

    ${socialLinks.map(link => `${link}`).join('')}
    `; card.querySelector('.profile-body').appendChild(socialSection); } // Skill tags if (data.skillTags?.length) { const tagsSection = document.createElement('div'); tagsSection.innerHTML = '

    Skill Tags

    '; const tagsContainer = document.createElement('div'); tagsContainer.className = 'tags-container'; data.skillTags.forEach(tag => { tagsContainer.innerHTML += `${tag}`; }); tagsSection.appendChild(tagsContainer); card.querySelector('.profile-body').appendChild(tagsSection); } // Problems by difficulty if (data.problemsSolvedByDifficulty) { const tagsContainer = document.createElement('div'); tagsContainer.className = 'tags-container'; ["Easy", "Medium", "Hard"].forEach(difficulty => { if (data.problemsSolvedByDifficulty[difficulty]) { tagsContainer.innerHTML += ` ${difficulty}: ${data.problemsSolvedByDifficulty[difficulty]} `; } }); if (tagsContainer.children.length > 0) { const difficultySection = document.createElement('div'); difficultySection.innerHTML = `

    Problem Distribution

    `; difficultySection.appendChild(tagsContainer); card.querySelector('.profile-body').appendChild(difficultySection); } } // Language stats if (data.languageStats?.length) { const langSection = document.createElement('div'); langSection.innerHTML = '

    Language Proficiency

    '; const langList = document.createElement('ul'); langList.className = 'content-list'; data.languageStats.slice(0, 8).forEach(lang => { langList.innerHTML += `
  • ${lang.languageName}: ${lang.problemsSolved} problems solved
  • `; }); if (data.languageStats.length > 8) { langList.innerHTML += `
  • And ${data.languageStats.length - 8} more languages...
  • `; } langSection.appendChild(langList); card.querySelector('.profile-body').appendChild(langSection); } // Skill proficiency sections const skillSections = [ { title: 'Advanced Skills', skills: data.skillsAdvanced }, { title: 'Intermediate Skills', skills: data.skillsIntermediate }, { title: 'Fundamental Skills', skills: data.skillsFundamental } ]; skillSections.forEach(section => { if (section.skills?.length) { const skillsSection = document.createElement('div'); skillsSection.innerHTML = `

    ${section.title}

    `; const skillsList = document.createElement('ul'); skillsList.className = 'content-list'; section.skills.slice(0, 5).forEach(skill => { skillsList.innerHTML += `
  • ${skill.tagName}: ${skill.problemsSolved} problems
  • `; }); if (section.skills.length > 5) { skillsList.innerHTML += `
  • And ${section.skills.length - 5} more skills...
  • `; } skillsSection.appendChild(skillsList); card.querySelector('.profile-body').appendChild(skillsSection); } }); // Badges section const badgesSection = document.createElement('div'); let hasBadges = false; // Active badge if (data.activeBadge?.name) { badgesSection.innerHTML += `

    Active Badge

    ${data.activeBadge.name}
    `; hasBadges = true; } // Badges collection if (data.badges?.length) { const badgesList = document.createElement('div'); badgesList.innerHTML = '

    Badges

    '; const badgesContainer = document.createElement('div'); badgesContainer.className = 'tags-container'; data.badges.slice(0, 5).forEach(badge => { badgesContainer.innerHTML += `${badge.displayName || badge.name}`; }); if (data.badges.length > 5) { badgesContainer.innerHTML += `+${data.badges.length - 5} more`; } badgesList.appendChild(badgesContainer); badgesSection.appendChild(badgesList); hasBadges = true; } // Upcoming badges if (data.upcomingBadges?.length) { const upcomingSection = document.createElement('div'); upcomingSection.innerHTML = '

    Upcoming Badges

    '; const upcomingContainer = document.createElement('div'); upcomingContainer.className = 'tags-container'; data.upcomingBadges.slice(0, 3).forEach(badge => { upcomingContainer.innerHTML += `${badge.name}`; }); if (data.upcomingBadges.length > 3) { upcomingContainer.innerHTML += `+${data.upcomingBadges.length - 3} more`; } upcomingSection.appendChild(upcomingContainer); badgesSection.appendChild(upcomingSection); hasBadges = true; } if (hasBadges) { card.querySelector('.profile-body').appendChild(badgesSection); } // Recent submissions if (data.recentAcSubmissions?.length) { const recentSection = document.createElement('div'); recentSection.innerHTML = '

    Recent Submissions

    '; const submissionsList = document.createElement('ul'); submissionsList.className = 'content-list'; data.recentAcSubmissions.slice(0, 5).forEach(sub => { submissionsList.innerHTML += `
  • ${sub.title} (${new Date(parseInt(sub.timestamp) * 1000).toLocaleDateString()})
  • `; }); recentSection.appendChild(submissionsList); card.querySelector('.profile-body').appendChild(recentSection); } // Set profile picture const profilePic = card.querySelector('.profile-pic'); profilePic.src = data.userAvatar || 'https://leetcode.com/static/images/icons/android-icon-192x192.png'; profilePic.onerror = () => { profilePic.src = 'https://leetcode.com/static/images/icons/android-icon-192x192.png'; }; return card; } function createProfileCard(platform, title) { const card = document.createElement('div'); card.className = `profile-card ${platform}-card`; card.innerHTML = `
    ${title.charAt(0)}

    ${title} Profile

    Profile
    `; return card; } function createErrorCard(platform, username, message) { const card = document.createElement('div'); card.className = `profile-card ${platform}-card`; card.innerHTML = `
    ${platform.charAt(0).toUpperCase()}

    ${platform.charAt(0).toUpperCase() + platform.slice(1)} Profile

    ⚠️
    Error loading ${platform} profile for "${username}": ${message}
    `; return card; }