Skip to content

Commit bf4e7bc

Browse files
NssGouravgemini-code-assist[bot]BaseMax
authored
feat: Add "I'm Feeling Lucky" Random User Button (#104)
* feat: imple Random User Button * Update docs/script.js Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update docs/script.js Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Max Base <[email protected]>
1 parent ee986ae commit bf4e7bc

File tree

3 files changed

+299
-223
lines changed

3 files changed

+299
-223
lines changed

docs/script.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function parseUserCard(card) {
6161
const name = card.querySelector('strong').textContent.toLowerCase();
6262
const login = card.querySelector('span:nth-of-type(2)').textContent.toLowerCase();
6363
const location = extractLocation(card);
64+
const languages = (card.querySelector('.languages')?.textContent || '').toLowerCase();
6465
const followers = parseInt(card.getAttribute('data-followers') || '0');
6566
const following = parseInt(card.getAttribute('data-following') || '0');
6667
const repos = parseInt(card.getAttribute('data-repos') || '0');
@@ -76,6 +77,7 @@ function parseUserCard(card) {
7677
name,
7778
login,
7879
location,
80+
languages,
7981
followers,
8082
following,
8183
repos,
@@ -148,8 +150,31 @@ function setupEventListeners() {
148150
element.addEventListener(eventType, onFilterChange);
149151
}
150152
});
153+
154+
const randomUserBtn = document.getElementById('randomUserBtn');
155+
if (randomUserBtn) {
156+
randomUserBtn.addEventListener('click', pickRandomUser);
157+
}
151158
}
159+
function pickRandomUser() {
160+
const usersToPickFrom = filteredUsers.length > 0 ? filteredUsers : allUsers;
152161

162+
if (usersToPickFrom.length === 0) {
163+
alert('No users found to pick from!');
164+
return;
165+
}
166+
167+
const randomIndex = Math.floor(Math.random() * usersToPickFrom.length);
168+
const randomUser = usersToPickFrom[randomIndex];
169+
randomUser.card.classList.add('visible');
170+
randomUser.card.scrollIntoView({ behavior: 'smooth', block: 'center' });
171+
randomUser.card.classList.remove('highlight');
172+
void randomUser.card.offsetWidth; // Force reflow to re-trigger CSS animation
173+
randomUser.card.classList.add('highlight');
174+
setTimeout(() => {
175+
randomUser.card.classList.remove('highlight');
176+
}, 2000);
177+
}
153178
/**
154179
* Handle any filter change event
155180
*/
@@ -266,7 +291,8 @@ function matchesSearch(user, searchTerm) {
266291
if (!searchTerm) return true;
267292
return user.name.includes(searchTerm) ||
268293
user.login.includes(searchTerm) ||
269-
user.location.includes(searchTerm);
294+
user.location.includes(searchTerm) ||
295+
user.languages.includes(searchTerm);
270296
}
271297

272298
/**

docs/styles.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,30 @@ h1 {
248248
color: #667eea;
249249
}
250250

251+
.btn-random {
252+
width: 100%;
253+
padding: 12px;
254+
background: #ff9f43; /* bright orange for distinctiveness */
255+
border: 2px solid rgba(255,255,255,0.5);
256+
color: white;
257+
border-radius: 6px;
258+
cursor: pointer;
259+
font-weight: 600;
260+
transition: all 0.3s;
261+
margin-bottom: 20px;
262+
display: flex;
263+
align-items: center;
264+
justify-content: center;
265+
gap: 8px;
266+
font-size: 1rem;
267+
}
268+
269+
.btn-random:hover {
270+
background: #ffb168;
271+
transform: translateY(-2px);
272+
box-shadow: 0 4px 12px rgba(255, 159, 67, 0.4);
273+
}
274+
251275
.results-info {
252276
text-align: center;
253277
color: white;
@@ -338,6 +362,18 @@ h1 {
338362
box-shadow: 0 10px 20px rgba(0,0,0,0.25);
339363
}
340364

365+
.card.highlight {
366+
animation: pulse-highlight 2s ease-in-out;
367+
box-shadow: 0 0 0 4px #ff9f43, 0 10px 20px rgba(0,0,0,0.25);
368+
z-index: 10;
369+
}
370+
371+
@keyframes pulse-highlight {
372+
0% { transform: scale(1); }
373+
50% { transform: scale(1.05); }
374+
100% { transform: scale(1); }
375+
}
376+
341377
.card img {
342378
width: 100%;
343379
display: block;

0 commit comments

Comments
 (0)