-
Notifications
You must be signed in to change notification settings - Fork 0
/
value_viewer.js
50 lines (46 loc) · 1.46 KB
/
value_viewer.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
var convert_salary = salary => {
return parseFloat(salary.replace("$", "").replace(",", ""));
};
var convert_score = score => {
return parseFloat(score);
};
var add_value = mouse_event => {
var elts = mouse_event.path[8].querySelectorAll(
"[data-test-id=data-chunk-value]"
);
var scoreElt;
var salaryElt;
for (var i = 0; i < elts.length; i++) {
if (!elts[i].innerText.includes("@") && !elts[i].innerText.includes("$")) {
scoreElt = elts[i];
} else if (elts[i].innerText.includes("$")) {
salaryElt = elts[i];
}
}
if (!scoreElt.innerText.includes("x")) {
var score = convert_salary(scoreElt.innerText);
var salary = convert_salary(salaryElt.innerText);
var value = (score / (salary / 1000)).toPrecision(3);
scoreElt.innerText = `${scoreElt.innerText} (${value}x)`;
}
};
var set_listeners = () => {
var lineups = document.getElementsByClassName("lineup");
for (var i = 0; i < lineups.length; i++) {
var players = lineups[i].getElementsByClassName("lineup__slot--has-player");
for (var j = 0; j < players.length; j++) {
var svgs = players[j].getElementsByTagName("svg");
for (var k = 0; k < svgs.length; k++) {
svgs[k].addEventListener("click", function(mouse_event) {
console.log("calculating value");
setTimeout(() => add_value(mouse_event), 1500);
});
}
}
}
console.log("listeners set");
};
var main = () => {
setTimeout(set_listeners, 4000);
};
main();