Created
May 17, 2021 16:08
-
-
Save raikasdev/f47f5ef325166f7f924805cc64c5911f to your computer and use it in GitHub Desktop.
seppo.io team point calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Made to check team (class) name from player name (<team> <name>) | |
// calculates all points together of teams | |
// Made for event on 19.5.2021. | |
let students = () => $(".single-team-area").map(function() { | |
let name = $(this).find('.team-name')[0].innerHTML; | |
let points = parseInt($(this).find('.team-point')[0].children[0].innerHTML); | |
return { name, points } | |
}).get(); | |
let points = () => { | |
let teams = {}; | |
students().forEach(student => { | |
let parts = student.name.split(' '); | |
let team = (parts.length == 1 || !parts[0].match(/7[A-F]/)) ? 'muu' : parts[0]; | |
if((parts.length != 1 && parts[0].match(/7[A-F]/))) parts.shift(); | |
let name = parts.join(' '); | |
if(!teams[team]) { | |
teams[team] = { points: student.points, players: [{ name, points: student.points }] }; | |
} else { | |
teams[team].points += student.points; | |
teams[team].players.push({ name, points: student.points }); | |
} | |
}) | |
return teams; | |
}; | |
fetch('https://seppo-scoreboard.glitch.me/process', { | |
method: 'post', | |
headers: { | |
'Accept': 'application/json, text/plain, */*', | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify(points()), | |
mode: 'no-cors' | |
}) | |
.then(function (response) { | |
window.open("https://seppo-scoreboard.glitch.me/lb"); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment