-
Notifications
You must be signed in to change notification settings - Fork 0
/
tablemaker.js
106 lines (103 loc) · 2.98 KB
/
tablemaker.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function genWLSpans(p, WL) {
spans = [];
if (WL == 'w') {
opponents = p.wins_names;
scores = p.wins_scores;
} else {
opponents = p.losses_names;
scores = p.losses_scores;
}
for (const [ idx, opp ] of opponents.entries()) {
upset =
(WL == 'w' && playerList[opp].seed > p.seed) ||
(WL == 'l' && playerList[opp].seed < p.seed);
if (upset) {
spans.push(
`<span class="${playerList[opp].id + 'class'}" title="${scores[
idx
]}">${opp}</span>`
);
} else {
spans.push(
`<span class="${playerList[opp].id + 'class'}" title="${scores[
idx
]}"><i>${opp}</i></span>`
);
}
}
return spans.join(', ');
}
function genTable(plist) {
pArray = Object.values(plist);
function compPlacing(a, b) {
if (a.placing >= b.placing) {
return 1;
} else {
return -1;
}
}
pArray = pArray.sort(compPlacing);
tab = `
<div class="standings-container"><table class="table table-striped table-bordered limited_width standings"><thead><tr>
<th>Rank</th>
<th>Participant Name</th>
<th>Losses</th>
<th>Wins</th></tr></thead><tbody>
`;
lastPlacing = -99;
for (const [ idx, p ] of pArray.entries()) {
if (lastPlacing != p.placing) {
firstlines = `<tr><td class="rank" rowspan="${playersPerPlacing[
p.placing
]}"><span class=${'rank' + p.placing}>${p.placing}</spa</td>`;
} else {
firstlines = '<tr>';
}
winSpan = genWLSpans(p, 'w');
lossSpan = genWLSpans(p, 'l');
entryTemplate = `
<td class="left display_name">
<span><strong><span class="${p.id +
'class'}" title="Seeded: ${p.seed}">${p.name}</strong></span>
</td>
<td class="left"><div>${lossSpan}</div></td>
<td class="left"><div>${winSpan}</div></td>
</tr>`;
tab += firstlines + entryTemplate;
lastPlacing = p.placing;
}
tab += '</tbody></table></div>';
return tab;
}
function hoverByClass(classname, colorover, colorout = 'transparent') {
var elms = document.getElementsByClassName(classname);
for (var i = 0; i < elms.length; i++) {
elms[i].onmouseover = function() {
for (var k = 0; k < elms.length; k++) {
if ($(elms[k]).css('font-weight') == 'bold') {
elms[k].style.color = '#FF7324';
}
}
};
elms[i].onmouseout = function() {
for (var k = 0; k < elms.length; k++) {
elms[k].style.color = '#D8D8D8';
}
};
}
}
function replaceResults(plist) {
description = $('.tournament-description.limited_width');
results.empty();
if (description) {
results.append(description);
}
results.append('<h4 title="Made by Kevbot"> (Better) Full Results</h4>');
results.append(genTable(plist));
let button = $(
`<button id='exportButton' class='button'>Export Results</button>`
)
.click(() => exportButton())
.css('color', 'black');
results.append(button);
}