mirror of
https://github.com/System-End/YSWS-Catalog.git
synced 2026-04-19 23:23:02 +00:00
added participants from api
This commit is contained in:
parent
f76e45d71f
commit
903c44feb9
2 changed files with 45 additions and 4 deletions
48
script.js
48
script.js
|
|
@ -1,4 +1,44 @@
|
|||
let programs = {};
|
||||
const apiUrl = "https://api2.hackclub.com/v0.1/Unified%20YSWS%20Projects%20DB/YSWS%20Programs?cache=true";
|
||||
var participants = []
|
||||
|
||||
function loadParticipants() {
|
||||
fetch(apiUrl).then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to Fetch Participants Data! ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
}).then(data => {
|
||||
participants = data.map(item => ({
|
||||
name: item.fields.Name,
|
||||
total: item.fields["Unweighted–Total"]
|
||||
}));
|
||||
|
||||
console.log(participants);
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error fetching data:", error);
|
||||
});
|
||||
}
|
||||
loadParticipants()
|
||||
|
||||
function getParticipantsByName(programName) {
|
||||
if (!participants.length) {
|
||||
console.error("Data has not been fetched yet. Please wait...");
|
||||
return;
|
||||
}
|
||||
|
||||
const program = participants.find(item => item.name.toLowerCase() === programName.toLowerCase());
|
||||
|
||||
if (program) {
|
||||
console.log(`Program: ${program.name}, Participants: ${program.total}`);
|
||||
return program.total;
|
||||
} else {
|
||||
console.log(`Program "${programName}" not found.`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function isEventEnded(deadline) {
|
||||
if (!deadline) return false;
|
||||
|
|
@ -91,9 +131,9 @@ function getDeadlineClass(deadlineStr) {
|
|||
return '';
|
||||
}
|
||||
|
||||
function formatParticipants(count) {
|
||||
if (count === undefined) return '';
|
||||
return `${count.toLocaleString()} participant${count === 1 ? '' : 's'}`;
|
||||
function formatParticipants(name) {
|
||||
if (name === undefined) return '';
|
||||
return getParticipantsByName(name)
|
||||
}
|
||||
|
||||
function createProgramCard(program) {
|
||||
|
|
@ -105,7 +145,7 @@ function createProgramCard(program) {
|
|||
const encodedProgram = encodeURIComponent(JSON.stringify(program));
|
||||
|
||||
const participantsText = program.participants !== undefined ?
|
||||
`<div class="program-participants">${formatParticipants(program.participants)}</div>` : '';
|
||||
`<div class="program-participants">${formatParticipants(program.name)}</div>` : '';
|
||||
|
||||
return `
|
||||
<div class="card program-card ${opensClass}" data-program="${encodedProgram}">
|
||||
|
|
|
|||
1
ysws.json
Normal file
1
ysws.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
[{"id":"rec0cAdSi6dFsnr1y","fields":{"Name":"The Bin","Unweighted–Total":277}},{"id":"rec0qFHAlOpZPuMFV","fields":{"Name":"Boba Drops","Unweighted–Total":1301}},{"id":"rec2Up8DfXy4esByb","fields":{"Name":"Dessert","Unweighted–Total":0}},{"id":"rec3OcvkmrET87msY","fields":{"Name":"Riceathon","Unweighted–Total":1}},{"id":"rec8eH7KozQJlIDQV","fields":{"Name":"Blot","Unweighted–Total":192}},{"id":"rec939NW8NA9MIr2L","fields":{"Name":"Power Hour","Unweighted–Total":51}},{"id":"rec9owxuHdujjnHgG","fields":{"Name":"BrowserBuddy","Unweighted–Total":36}},{"id":"recE2drMuGXUWJi3L","fields":{"Name":"Hackcraft Mod Edition","Unweighted–Total":8}},{"id":"recHnd1ttjwPlgVIt","fields":{"Name":"Arcade","Unweighted–Total":1229}},{"id":"recLh2KxoyLbqiuAi","fields":{"Name":"Easel","Unweighted–Total":11}},{"id":"recPEpsGS8SYCV8pg","fields":{"Name":"Hackaccino","Unweighted–Total":362}},{"id":"recRznjWVg7ctL0Ld","fields":{"Name":"Hackpad","Unweighted–Total":35}},{"id":"recSODGhknuccVVfj","fields":{"Name":"Wizard Orpheus","Unweighted–Total":13}},{"id":"recWh4JY75X2GQOoU","fields":{"Name":"10 Hours in Public","Unweighted–Total":24}},{"id":"recaFoqCU8OckbUXZ","fields":{"Name":"Say Cheese","Unweighted–Total":0}},{"id":"recepBUx0dFRyJXNj","fields":{"Name":"Anchor","Unweighted–Total":26}},{"id":"recfEBqFDf4NGjY4y","fields":{"Name":"Sprig","Unweighted–Total":667}},{"id":"recjHqZ0sBpdt4RCA","fields":{"Name":"Cargo Cult v2","Unweighted–Total":22}},{"id":"recjl0cmSpepVLwQC","fields":{"Name":"Low Skies","Unweighted–Total":68}},{"id":"reck8PI9qm56lEOOQ","fields":{"Name":"BakeBuild","Unweighted–Total":0}},{"id":"recogPY9YwTFHFBjT","fields":{"Name":"Build Your Own LLM","Unweighted–Total":20}},{"id":"reconHxKzWI8Zp43M","fields":{"Name":"Cargo Cult","Unweighted–Total":18}},{"id":"recqYkMrUxNn5v6X0","fields":{"Name":"10 Days In Public","Unweighted–Total":7}},{"id":"rectvQ49dMZdaKHQP","fields":{"Name":"Ham Club","Unweighted–Total":14}},{"id":"recurPoPKtmlCrqOJ","fields":{"Name":"GameGuilds","Unweighted–Total":0}},{"id":"recv6jYRpf5inVI6C","fields":{"Name":"OnBoard","Unweighted–Total":623}},{"id":"recvaPCCKn7v50aDd","fields":{"Name":"OnBoard Live","Unweighted–Total":0}},{"id":"reczTBJrxy80ONaK6","fields":{"Name":"High Seas","Unweighted–Total":1480}},{"id":"reczXRU25w9yusmvp","fields":{"Name":"Cider","Unweighted–Total":43}},{"id":"reczfiitatKeQSr3S","fields":{"Name":"Cascade","Unweighted–Total":55}}]
|
||||
Loading…
Add table
Reference in a new issue