-
Notifications
You must be signed in to change notification settings - Fork 0
/
analytics.js
84 lines (80 loc) · 2.48 KB
/
analytics.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
function onError(error) {
console.error(`Error: ${error}`);
console.error("Error:", error);
}
const parser = new DOMParser();
function get_fwds (url, is_home, cell) {
fetch(url).then(response => response.text()).then(function (text) {
console.log("AAAA", url, is_home);
page = parser.parseFromString(text, "text/html");
tbls = page.getElementsByClassName("tbl");
var tbl = is_home ? tbls[0] : tbls[1];
var rows = tbl.getElementsByTagName("tr");
if (rows.length < 16) {
cell.appendChild(document.createTextNode("N/A"));
return;
}
var fwds = 0;
for (var i = 1; i <= 16; i++) {
var columns = rows[i].getElementsByTagName("td");
var span = columns[0].getElementsByTagName("span");
if (span.length == 0) {
continue;
}
var position = span[0].innerText;
switch (position) {
case "LW":
case "LF":
case "CF":
case "ST":
case "RW":
case "RF":
case "AM":
fwds += 1;
break;
default:
break;
}
}
cell.appendChild(document.createTextNode("" + fwds));
if (fwds > 3) {
cell.style.backgroundColor = "#ffe0e0";
} else {
cell.style.backgroundColor = "#e0ffe0";
}
}).catch(onError);
}
ads = document.createElement('div');
ads.style.backgroundColor = "white"
ads.sandbox="allow-popups allow-scripts"
season_table = document.getElementsByClassName("tbl")[0];
pre_ads_row = season_table.getElementsByTagName("tbody")[0].insertRow(-1);
pre_ads_cell = pre_ads_row.insertCell(0);
pre_ads_cell.colSpan = 8;
pre_ads_cell.appendChild(document.createTextNode(" s "));
pre_ads_row.style.backgroundColor = "#B45618"
pre_ads_row.style.color = "#B45618"
ads_row = season_table.getElementsByTagName("tbody")[0].insertRow(-1);
ads_row.style.backgroundColor = "#F4F8F2"
ads_cell = ads_row.insertCell(0);
ads_cell.colSpan = 8;
ads_cell.appendChild(ads);
game_table = document.getElementsByClassName("tbl")[1];
hdr_row = game_table.rows[0];
hdr_td = hdr_row.insertCell(-1)
hdr_td.innerHTML = "<b>Нпд</b>";
hdr_td.className = "lh18 txtw";
hdr_td.style.backgroundColor = "#B45618";
for (var i = 1; i < game_table.rows.length; i++) {
row = game_table.rows[i];
columns = row.getElementsByTagName("td");
is_home_side = columns[5].innerText == "Д";
game_td = columns[10];
a_ = game_td.getElementsByTagName("a")[0]
if (!a_) {
break;
}
game_href = a_.href;
cell = row.insertCell(-1);
get_fwds(game_href, is_home_side, cell);
}