File size: 7,654 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
export function renderCodeforces(data, username) {
    if (!data || !data.profile) {
        const card = createErrorCard('Codeforces', username, 'Profile data not available');
        return card;
    }

    const card = createProfileCard('codeforces', 'Codeforces');
    const p = data.profile;
    
    // Profile Header
    card.querySelector('.user-info').innerHTML = `
        <div class="user-name">${p.firstName || ''} ${p.lastName || ''}</div>
        <div class="username">@${p.handle || ''}</div>
    `;
    
    // Stats Grid
    const statsGrid = card.querySelector('.stats-grid');
    statsGrid.innerHTML = `
        <div class="stat-card">
            <div class="stat-value">${p.rating || 'N/A'}</div>
            <div class="stat-label">Rating</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">${p.maxRating || 'N/A'}</div>
            <div class="stat-label">Max Rating</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">${p.rank || 'N/A'}</div>
            <div class="stat-label">Current Rank</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">${p.maxRank || 'N/A'}</div>
            <div class="stat-label">Max Rank</div>
        </div>
    `;
    
    // Country and city
    if (p.country || p.city) {
        const locationSection = document.createElement('div');
        locationSection.innerHTML = '<h3 class="section-title">Location</h3>';
        
        const locationList = document.createElement('ul');
        locationList.className = 'content-list';
        
        if (p.country) {
            locationList.innerHTML += `<li><strong>Country:</strong> ${p.country}</li>`;
        }
        
        if (p.city) {
            locationList.innerHTML += `<li><strong>City:</strong> ${p.city}</li>`;
        }
        
        locationSection.appendChild(locationList);
        card.querySelector('.profile-body').appendChild(locationSection);
    }
    
    // Recent contests
    if (data.contests?.length) {
        const contestsSection = document.createElement('div');
        contestsSection.innerHTML = '<h3 class="section-title">Recent Contests</h3>';
        
        const contestsList = document.createElement('ul');
        contestsList.className = 'content-list';
        
        // Get the 5 most recent contests
        const recentContests = [...data.contests]
            .sort((a, b) => b.contestId - a.contestId)
            .slice(0, 5);
        
        recentContests.forEach(contest => {
            const ratingChange = contest.newRating - contest.oldRating;
            const changeColor = ratingChange > 0 ? '#43A047' : (ratingChange < 0 ? '#e53935' : '#757575');
            const changeSign = ratingChange > 0 ? '+' : '';
            
            contestsList.innerHTML += `
                <li>
                    <a href="https://codeforces.com/contest/${contest.contestId}" target="_blank" style="color: #FF9900;">
                        ${contest.contestName}
                    </a>
                    <span style="color: ${changeColor}; margin-left: 5px;">
                        ${changeSign}${ratingChange}
                    </span>
                    <span style="color: #888; margin-left: 5px;">
                        | Rank: ${contest.rank}
                    </span>
                </li>
            `;
        });
        
        contestsSection.appendChild(contestsList);
        card.querySelector('.profile-body').appendChild(contestsSection);
    }
    
    // Top problem tags
    if (data.solved_stats?.top_tags) {
        const tagsSection = document.createElement('div');
        tagsSection.innerHTML = '<h3 class="section-title">Top Problem Tags</h3>';
        
        const tagsContainer = document.createElement('div');
        tagsContainer.className = 'tags-container';
        
        Object.entries(data.solved_stats.top_tags)
            .sort((a, b) => b[1] - a[1])
            .slice(0, 8)
            .forEach(([tag, count]) => {
                tagsContainer.innerHTML += `
                    <span class="tag">
                        ${tag} (${count})
                    </span>
                `;
            });
        
        tagsSection.appendChild(tagsContainer);
        card.querySelector('.profile-body').appendChild(tagsSection);
    }
    
    // Solved stats
    if (data.solved_stats) {
        const solvedSection = document.createElement('div');
        solvedSection.innerHTML = `
            <div class="stats-grid" style="margin-top: 10px;">
                <div class="stat-card">
                    <div class="stat-value">${data.solved_stats.solved_problems || 0}</div>
                    <div class="stat-label">Solved</div>
                </div>
                <div class="stat-card">
                    <div class="stat-value">${data.solved_stats.total_attempts || 0}</div>
                    <div class="stat-label">Attempts</div>
                </div>
            </div>
        `;
        card.querySelector('.profile-body').appendChild(solvedSection);
    }
    
    // Blog posts
    if (data.blogs?.length) {
        const blogSection = document.createElement('div');
        blogSection.innerHTML = '<h3 class="section-title">Recent Blog Posts</h3>';
        
        const blogsList = document.createElement('ul');
        blogsList.className = 'content-list';
        
        data.blogs.slice(0, 3).forEach(blog => {
            blogsList.innerHTML += `
                <li>
                    <a href="https://codeforces.com/blog/entry/${blog.id}" target="_blank" style="color: #FF9900;">
                        ${blog.title}
                    </a>
                </li>
            `;
        });
        
        blogSection.appendChild(blogsList);
        card.querySelector('.profile-body').appendChild(blogSection);
    }
    
    // Set profile picture
    const profilePic = card.querySelector('.profile-pic');
    profilePic.src = p.avatar || 'https://userpic.codeforces.org/no-avatar.jpg';
    profilePic.onerror = () => {
        profilePic.src = 'https://userpic.codeforces.org/no-avatar.jpg';
    };
    
    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;
}