Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
85 lines (82 loc) · 3.49 KB
/
Copy pathscript.js
File metadata and controls
85 lines (82 loc) · 3.49 KB
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
document.addEventListener("DOMContentLoaded", () => {
console.log("✅ Script loaded");
const links=document.querySelectorAll('.nav-links a');
const path=location.pathname.split('/').pop()||'index.html';
links.forEach(a=>{if(a.getAttribute('href')===path){a.classList.add('active')}});
// Logged in user
const greenChampionData = {
name: "Aarav Sharma",
currentPoints: 175,
nextTierPoints: 200, // threshold for next level
metrics: {
householdsTrained: 50,
sitesReported: 12,
cleanupEvents: 3,
auditsCompleted: 25,
}
};
// Leaderboard data
const leaderboardData = [
{ rank: 1, name: "Priya Singh", points: 250 },
{ rank: 2, name: "Rohit Verma", points: 215 },
{ rank: 3, name: "Anjali Gupta", points: 198 },
{ rank: 4, name: "Aarav Sharma", points: 175 }, // logged-in user
{ rank: 5, name: "Vijay Kumar", points: 160 },
];
// Tier logic
function getTier(points) {
if (points >= 300) return "Platinum";
if (points >= 200) return "Gold";
if (points >= 100) return "Silver";
return "Bronze";
}
// Update profile info
const userTier = getTier(greenChampionData.currentPoints);
document.getElementById("champion-name").textContent = greenChampionData.name;
document.getElementById("champion-tier").textContent = `${userTier} Champion`;
// Progress bar
const progressBar = document.getElementById("tier-progress-bar");
const progressText = document.getElementById("progress-text");
const progressPercentage = (greenChampionData.currentPoints / greenChampionData.nextTierPoints) * 100;
progressBar.style.width = `${progressPercentage}%`;
progressText.textContent = `${greenChampionData.currentPoints}/${greenChampionData.nextTierPoints} points to next tier!`;
// Metrics
document.getElementById("trained-households").textContent = greenChampionData.metrics.householdsTrained;
document.getElementById("sites-reported").textContent = greenChampionData.metrics.sitesReported;
document.getElementById("cleanup-events").textContent = greenChampionData.metrics.cleanupEvents;
document.getElementById("audits-completed").textContent = greenChampionData.metrics.auditsCompleted;
// Leaderboard
const leaderboardBody = document.getElementById("leaderboard-body");
console.log("leaderboardBody:",leaderboardBody);
leaderboardData.forEach(champion => {
console.log("Adding:",champion);
const row = document.createElement("tr");
if (champion.name === greenChampionData.name) {
row.classList.add("highlight-row");
}
row.innerHTML = `<td>${champion.rank}</td><td>${champion.name}</td><td>${champion.points}</td>`;
leaderboardBody.appendChild(row);
});
// Show user’s current rank number
const userRank = leaderboardData.find(c => c.name === greenChampionData.name)?.rank;
if (userRank) {
const rankDiv = document.createElement("p");
rankDiv.textContent = `⭐ Your Current Rank: ${userRank} (${userTier} Champion)`;
rankDiv.classList.add("current-rank");
document.querySelector(".leaderboard-section").prepend(rankDiv);
}
});
// document.addEventListener('DOMContentLoaded', ()=>{
// const links=document.querySelectorAll('.nav-links a');
// const path=location.pathname.split('/').pop()||'index.html';
// links.forEach(a=>{if(a.getAttribute('href')===path){a.classList.add('active')}});
// });
const getStartedBtn = document.getElementById('getStartedBtn');
const targetSection = document.getElementById('features-section');
// getStartedBtn.addEventListener('click', () => {
// targetSection.scrollIntoView({
// behaviour : 'smooth'
// });
// });
// const userTier = "silver";
// document.getElementById('champion-tier').textContent = userTier + "Champion";