File size: 13,197 Bytes
8098153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
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 = `
        <div class="user-name">${data.realName || 'Anonymous'}</div>
        <div class="username">@${data.username || 'N/A'}</div>
    `;
    
    // Stats Grid - Expanded to show more stats
    const statsGrid = card.querySelector('.stats-grid');
    statsGrid.innerHTML = `
        <div class="stat-card">
            <div class="stat-value">${data.ranking ?? 'Unranked'}</div>
            <div class="stat-label">Global Rank</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">${data.reputation ?? 0}</div>
            <div class="stat-label">Reputation</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">${data.totalSolved || 0}</div>
            <div class="stat-label">Problems Solved</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">${data.acceptanceRate || 0}%</div>
            <div class="stat-label">Acceptance Rate</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">${data.currentStreak || 0}</div>
            <div class="stat-label">Current Streak</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">${data.totalActiveDays || 0}</div>
            <div class="stat-label">Active Days</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">${data.activeYears?.join(', ') || 'N/A'}</div>
            <div class="stat-label">Active Years</div>
        </div>
        ${data.contestBadge?.name ? `
        <div class="stat-card">
            <div class="stat-value">${data.contestBadge.name}</div>
            <div class="stat-label">Contest Badge</div>
        </div>` : ''}
    `;
    
    // About section
    if (data.aboutMe) {
        const aboutSection = document.createElement('div');
        aboutSection.innerHTML = '<h3 class="section-title">About</h3>';
        aboutSection.innerHTML += `<p style="color: var(--text-light); line-height: 1.5;">${data.aboutMe}</p>`;
        card.querySelector('.profile-body').appendChild(aboutSection);
    }
    
    // Professional info
    if (data.company || data.school || data.countryName || data.jobTitle) {
        const infoSection = document.createElement('div');
        infoSection.innerHTML = '<h3 class="section-title">Professional Info</h3>';
        
        const infoList = document.createElement('ul');
        infoList.className = 'content-list';
        
        if (data.company) {
            infoList.innerHTML += `<li><strong>Company:</strong> ${data.company}${data.jobTitle ? ` (${data.jobTitle})` : ''}</li>`;
        }
        
        if (data.school) {
            infoList.innerHTML += `<li><strong>School:</strong> ${data.school}</li>`;
        }
        
        if (data.countryName) {
            infoList.innerHTML += `<li><strong>Country:</strong> ${data.countryName}</li>`;
        }
        
        infoSection.appendChild(infoList);
        card.querySelector('.profile-body').appendChild(infoSection);
    }
    
    // Social links
    const socialLinks = [];
    if (data.githubUrl) socialLinks.push(`<a href="${data.githubUrl}" target="_blank" style="color: #3B5998;">GitHub</a>`);
    if (data.linkedinUrl) socialLinks.push(`<a href="${data.linkedinUrl}" target="_blank" style="color: #3B5998;">LinkedIn</a>`);
    if (data.twitterUrl) socialLinks.push(`<a href="${data.twitterUrl}" target="_blank" style="color: #3B5998;">Twitter</a>`);
    if (data.websites?.length) {
        data.websites.forEach(site => {
            if (site) socialLinks.push(`<a href="${site.startsWith('http') ? site : 'https://' + site}" target="_blank" style="color: #3B5998;">${site.replace(/^https?:\/\//, '')}</a>`);
        });
    }
    
    if (socialLinks.length > 0) {
        const socialSection = document.createElement('div');
        socialSection.innerHTML = `
            <h3 class="section-title">Social Links</h3>
            <div class="tags-container">
                ${socialLinks.map(link => `<span class="tag">${link}</span>`).join('')}
            </div>
        `;
        card.querySelector('.profile-body').appendChild(socialSection);
    }
    
    // Skill tags
    if (data.skillTags?.length) {
        const tagsSection = document.createElement('div');
        tagsSection.innerHTML = '<h3 class="section-title">Skill Tags</h3>';
        
        const tagsContainer = document.createElement('div');
        tagsContainer.className = 'tags-container';
        
        data.skillTags.forEach(tag => {
            tagsContainer.innerHTML += `<span class="tag">${tag}</span>`;
        });
        
        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 += `
                    <span class="tag">
                        ${difficulty}: ${data.problemsSolvedByDifficulty[difficulty]}
                    </span>
                `;
            }
        });
        
        if (tagsContainer.children.length > 0) {
            const difficultySection = document.createElement('div');
            difficultySection.innerHTML = `
                <h3 class="section-title">Problem Distribution</h3>
            `;
            difficultySection.appendChild(tagsContainer);
            card.querySelector('.profile-body').appendChild(difficultySection);
        }
    }
    
    // Language stats
    if (data.languageStats?.length) {
        const langSection = document.createElement('div');
        langSection.innerHTML = '<h3 class="section-title">Language Proficiency</h3>';
        
        const langList = document.createElement('ul');
        langList.className = 'content-list';
        
        data.languageStats.slice(0, 8).forEach(lang => {
            langList.innerHTML += `
                <li>
                    <strong>${lang.languageName}:</strong> ${lang.problemsSolved} problems solved
                </li>
            `;
        });
        
        if (data.languageStats.length > 8) {
            langList.innerHTML += `<li>And ${data.languageStats.length - 8} more languages...</li>`;
        }
        
        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 = `<h3 class="section-title">${section.title}</h3>`;
            
            const skillsList = document.createElement('ul');
            skillsList.className = 'content-list';
            
            section.skills.slice(0, 5).forEach(skill => {
                skillsList.innerHTML += `
                    <li>
                        <strong>${skill.tagName}:</strong> ${skill.problemsSolved} problems
                    </li>
                `;
            });
            
            if (section.skills.length > 5) {
                skillsList.innerHTML += `<li>And ${section.skills.length - 5} more skills...</li>`;
            }
            
            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 += `
            <h3 class="section-title">Active Badge</h3>
            <div class="tags-container">
                <span class="tag">${data.activeBadge.name}</span>
            </div>
        `;
        hasBadges = true;
    }
    
    // Badges collection
    if (data.badges?.length) {
        const badgesList = document.createElement('div');
        badgesList.innerHTML = '<h3 class="section-title">Badges</h3>';
        
        const badgesContainer = document.createElement('div');
        badgesContainer.className = 'tags-container';
        
        data.badges.slice(0, 5).forEach(badge => {
            badgesContainer.innerHTML += `<span class="tag">${badge.displayName || badge.name}</span>`;
        });
        
        if (data.badges.length > 5) {
            badgesContainer.innerHTML += `<span class="tag">+${data.badges.length - 5} more</span>`;
        }
        
        badgesList.appendChild(badgesContainer);
        badgesSection.appendChild(badgesList);
        hasBadges = true;
    }
    
    // Upcoming badges
    if (data.upcomingBadges?.length) {
        const upcomingSection = document.createElement('div');
        upcomingSection.innerHTML = '<h3 class="section-title">Upcoming Badges</h3>';
        
        const upcomingContainer = document.createElement('div');
        upcomingContainer.className = 'tags-container';
        
        data.upcomingBadges.slice(0, 3).forEach(badge => {
            upcomingContainer.innerHTML += `<span class="tag">${badge.name}</span>`;
        });
        
        if (data.upcomingBadges.length > 3) {
            upcomingContainer.innerHTML += `<span class="tag">+${data.upcomingBadges.length - 3} more</span>`;
        }
        
        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 = '<h3 class="section-title">Recent Submissions</h3>';
        
        const submissionsList = document.createElement('ul');
        submissionsList.className = 'content-list';
        
        data.recentAcSubmissions.slice(0, 5).forEach(sub => {
            submissionsList.innerHTML += `
                <li>
                    <a href="https://leetcode.com/problems/${sub.titleSlug}" target="_blank" style="color: #3B5998;">
                        ${sub.title}
                    </a>
                    <span style="color: #888; margin-left: 5px;">
                        (${new Date(parseInt(sub.timestamp) * 1000).toLocaleDateString()})
                    </span>
                </li>
            `;
        });
        
        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 = `
        <div class="platform-header">
            <div class="platform-icon-large">${title.charAt(0)}</div>
            <h2 class="platform-title">${title} Profile</h2>
        </div>
        <div class="profile-body">
            <div class="profile-meta">
                <img src="" alt="Profile" class="profile-pic">
                <div class="user-info"></div>
            </div>
            <div class="stats-grid"></div>
        </div>
    `;
    
    return card;
}

function createErrorCard(platform, username, message) {
    const card = document.createElement('div');
    card.className = `profile-card ${platform}-card`;
    
    card.innerHTML = `
        <div class="platform-header">
            <div class="platform-icon-large">${platform.charAt(0).toUpperCase()}</div>
            <h2 class="platform-title">${platform.charAt(0).toUpperCase() + platform.slice(1)} Profile</h2>
        </div>
        <div class="profile-body">
            <div class="error-msg">
                <span class="error-icon">⚠️</span>
                <div>
                    <strong>Error loading ${platform} profile for "${username}":</strong>
                    ${message}
                </div>
            </div>
        </div>
    `;
    
    return card;
}