-
Notifications
You must be signed in to change notification settings - Fork 0
/
boxscoreModal.html
213 lines (193 loc) · 5.13 KB
/
boxscoreModal.html
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
<link href="https://cdn.datatables.net/1.10.20/css/dataTables.bootstrap4.min.css" />
<link href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" />
<style>
table {
width: 100%;
}
h3 {
font-size: 30px;
}
h1 {
font-size: 60px;
}
.team{
font-size: 50px;
color: green;
text-align: center;
}
.card-body{
text-align: center;
}
.score{
font-size: 50px;
color: greenyellow;
}
button{
margin-left: 50%;
}
</style>
<div class="table-responsive bg-primary ">
<div class="card border-primary" id="vTeamScore">
<div class="card-body">
<h1><span class="badge badge-primary"></span></h1>
<h3><span class="badge badge-pill badge-secondary"></span></h3>
<div><span class="vteam team"> </span> <span class="vscore score"></span></div>
</div>
</div>
<table class="table table table-dark table-bordered" id="vTeamTable">
</table>
<div class="card border-primary" id="hTeamScore">
<div class="card-body">
<h1><span class="badge badge-primary"></span></h1>
<h3><span class="badge badge-pill badge-secondary"></span></h3>
<div><span class="hteam team"> </span> <span class="hscore score"></span></div>
</div>
</div>
<table class="table table table-dark table-bordered" id="hTeamTable">
</table>
<button onclick="window.close()">CLOSE</button>
</div>
<!-- <a href="javascript:window.close()">Close this Window</a> -->
<script>
const ipc = require('electron').ipcRenderer;
const axios = require('axios');
const moment=require('moment');
var $ = require("jquery");
var dt = require('datatables.net')(window, $);
var vTeamData;
var hTeamData;
var hTeamId;
var vTeamId;
const boxscoreURL = 'http://data.nba.net/prod/v1/{{date}}/{{gameid}}_boxscore.json';
function getGlobalObject() {
let sharedObject = require('electron').remote.getGlobal('sharedObject');
return sharedObject;
}
ipc.on('id', (e, value) => {
console.log(getGlobalObject().Date)
let date = moment(getGlobalObject().Date).format('YYYYMMDD');
let id=value;
console.log(date);
console.log(id);
const url =boxscoreURL.replace('{{date}}',date).replace('{{gameid}}',id);
//console.log(url);
getdata(url);
});
function getdata(url) {
const getScorebox = async () => {
const data = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
});
const jsonData = await data.json();
hTeamId = jsonData.basicGameData.hTeam.teamId;
vTeamId = jsonData.basicGameData.vTeam.teamId;
vTeamData = TeamData(jsonData.stats.activePlayers.filter(x => x.teamId == vTeamId));
hTeamData = TeamData(jsonData.stats.activePlayers.filter(x => x.teamId == hTeamId));
var vTScoreData=[jsonData.basicGameData.vTeam.triCode,jsonData.basicGameData.vTeam.score];
var hTScoreData=[jsonData.basicGameData.hTeam.triCode,jsonData.basicGameData.hTeam.score];
initScoreBar('v',vTScoreData);
initScoreBar('h',hTScoreData);
initTable(($('#vTeamTable')),vTeamData);
initTable(($('#hTeamTable')),hTeamData);
return jsonData;
};
getScorebox();
}
function TeamData(arr) {
return arr.map(x => ([
`${x.firstName} ${x.lastName}`,
x.pos,
x.min,
x.points,
x.totReb,
x.assists,
x.steals,
x.blocks,
`${x.fgm}/${x.fga}`,
x.fgp,
`${x.tpm}/${x.tpa}`,
x.tpp,
`${x.ftm}/${x.fta}`,
x.offReb,
x.defReb,
x.turnovers,
x.pFouls,
x.plusMinus
]));
}
function initScoreBar(target,data){
$(`.${target}score`).text(data[1]);
$(`.${target}team`).text(data[0]);
// target.children().children('h3').children('span').text(data[1]);
// target.children().children('h1').children('span').text(data[0]);
}
function initTable(targetTable,data) {
var tb= targetTable.DataTable({
data: data,
columns: [{
title: "姓名"
},
{
title: "位置"
},
{
title: "上場時間"
},
{
title: "得分"
},
{
title: "籃板"
},
{
title: "助攻"
},
{
title: "抄截"
},
{
title: "阻攻"
},
{
title: "投籃命中/ 投籃出手"
},
{
title: "投籃%"
},
{
title: "三分球命中數/三分球出手數"
},
{
title: "三分球%"
},
{
title: "罰球命中/罰球次數"
},
{
title: "進攻籃板"
},
{
title: "防守籃板"
},
{
title: "失誤"
},
{
title: "犯規"
},
{
title: "+/-"
}
],
"paging": false,
"ordering": false,
"info": false,
"searching": false
});
$(tb.table().header()).addClass('table-info');
}
</script>