Skip to content

Instantly share code, notes, and snippets.

@lgarron
Last active August 15, 2023 14:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgarron/7b4f75f0f84131a414c2f571a3463842 to your computer and use it in GitHub Desktop.
Save lgarron/7b4f75f0f84131a414c2f571a3463842 to your computer and use it in GitHub Desktop.
WCA Live WPA/BPA
globalThis.addedElems ??= [];
for (const elem of globalThis.addedElems) {
elem.remove();
}
globalThis.addedElems = [];
function registerElem(elem) {
elem.className = "MuiTableCell-root MuiTableCell-body MuiTableCell-alignRight MuiTableCell-sizeSmall css-wrjkbz";
globalThis.addedElems.push(elem);
return elem;
}
const table = document.querySelector(".MuiTable-root");
const rows = table.querySelectorAll(".MuiTableRow-root");
function parseText(text) {
switch (text) {
case "DNF": return Infinity;
case "DNS": return Infinity;
case "": return null;
}
try {
return parseFloat(text)
} catch {
return Infinity;
}
}
function format(t) {
// Something simple for now.
return Math.round(t * 100) / 100;
}
let firstRow = true;
for (const row of rows) {
const t = (i) => parseText(row.children[i+2].textContent);
let times = [t(0), t(1), t(2), t(3), t(4)];
let bpa = "—";
let wpa = "—"
try {
if (firstRow) {
bpa = "BPA";
wpa = "WPA"
firstRow = false;
} else if (t(4) !== null) {
bpa = wpa = t(5);
} else if (t(3) !== null) {
times = times.slice(0, 4).sort((a, b) => (b === null) ? -1 : a - b);
console.log(times);
bpa = format((times[0] + times[1] + times[2])/3);
wpa = format((times[1] + times[2] + times[3])/3);
} else if (t(2) !== null) {
times = times.slice(0, 3).sort((a, b) => (b === null) ? -1 : a - b);
console.log(times);
bpa = "<" + format((times[0] + times[1] + times[2])/3);
}
} catch (e) { console.warn(e); }
registerElem(row.appendChild(document.createElement("td"))).textContent = bpa;
registerElem(row.appendChild(document.createElement("td"))).textContent = wpa;
}
"Updated BPA & WPA."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment