-
Notifications
You must be signed in to change notification settings - Fork 21
/
csrating.js
48 lines (41 loc) · 1.29 KB
/
csrating.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
const tables = document.querySelectorAll('table');
let csrTable;
for (const table of tables) {
const tableHeaders = table.querySelectorAll('th');
for (const th of tableHeaders) {
if (th.textContent === 'Updated') {
csrTable = table;
}
}
}
if (csrTable) {
const csrTh = document.createElement('th');
csrTh.textContent = 'CS Rating';
csrTable.querySelector('tr').append(csrTh);
const premierRows = [...csrTable.querySelectorAll('tr')]
.filter(tr => tr.querySelector('td')?.textContent.startsWith('premier'))
.reverse();
let prevScore = 0;
for (const row of premierRows) {
const score = Number(row.querySelector('td:last-of-type').textContent);
const csr = score >> 15;
const csrTd = document.createElement('td');
const csrSpan = document.createElement('span');
csrSpan.textContent = csr;
csrTd.append(csrSpan);
if (prevScore) {
const csrDiffSpan = document.createElement('span');
const diff = csr - prevScore;
csrDiffSpan.textContent = `(${diff > 0 ? '+' : ''}${diff})`;
csrDiffSpan.style.marginLeft = '1em';
if (diff < 0) {
csrDiffSpan.style.color = 'red';
} else {
csrDiffSpan.style.color = 'green';
}
csrTd.append(csrDiffSpan);
}
row.append(csrTd);
prevScore = csr;
}
}