forked from Staycold/EsportsDashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitch.js
468 lines (338 loc) · 13.5 KB
/
twitch.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
let clientId = "fti2cm1zr0bb6tuoqhmv9xjqa76e4s";
let client_secret = "aj2ra5encuwosbtj8xa3yxxoq7dl3y";
let token = "2nqlf1wjlmxxpcwluk90a1yd6a3xqv";
// let url = 'https://api.twitch.tv/helix/search/channels?query=callofduty&live_only=true';
let url;
let baseurl = "https://api.twitch.tv/helix/search/channels?query=";
let listOfGames = document.getElementById('gameItems');
let displayInfo = document.getElementById('placeInfo');
// let currentGame = 'COD';
let getGames = "";
let initalMoveChosen = false;
// localStorage.clear();
//let auth="https://id.twitch.tv/oauth2/token?client_id=fti2cm1zr0bb6tuoqhmv9xjqa76e4s&client_secret=aj2ra5encuwosbtj8xa3yxxoq7dl3y&grant_type=client_credentials"
//listOfTeamMembetrs = ["DallasEmpire","FloridaMutineers","LondonRoyalRavens","LosAngelesGuerrillas","New York Subliners","TorontoUltra"]
// listOfChannels = ['Call of Duty: Warzone','Call of Duty: Black Ops Cold War','Call Of Duty: Modern Warfare','Call of Duty: Black Ops III'];
var codTournaments = "https://cors-anywhere.herokuapp.com/https://api.pandascore.co/codmw/tournaments/running?token=_Sb6lpEcpdk-URomVTPLYWMJg3OTz9gQvy8sWyM3NcEhLMuyFyo"
var valorantTournaments = "https://cors-anywhere.herokuapp.com/https://api.pandascore.co/valorant/tournaments/running?token=_Sb6lpEcpdk-URomVTPLYWMJg3OTz9gQvy8sWyM3NcEhLMuyFyo"
// console.log("cod tourn data " + codTournaments);
// console.log("valor tourn data " + valorantTournaments)
console.log("this");
console.log(valorantTournaments);
let pandaScoreURl = "";
var parentList = document.getElementById("match-list");
var teamList = document.getElementById("team-list")
// localStorage.clear();
let url1 = "";
let twitchURL = "https://api.twitch.tv/helix/streams?user_id="
let volarantID = "516575"
let codID = "512710";
let chosenGame = "callofduty";
let originalOpen = false;
let titleOfTournoments = document.getElementById('currentTournos');
let positionChosen = 0;
let currentData;
function displayData(allData){
while(displayInfo.hasChildNodes()){
displayInfo.removeChild((displayInfo.childNodes[0]));
}
for(let i=0;i<5;i++){
let nameDisplayed = document.createElement('a');
let brodcasterId = allData["data"][i]['broadcaster_login'];
console.log("yeeeeeeeer");
nameDisplayed.innerHTML = allData["data"][i]["display_name"];
let blank = " target='_blank'";
nameDisplayed.setAttribute('href',"https://www.twitch.tv/" + brodcasterId);
nameDisplayed.setAttribute("target", "_blank");
let title = document.createElement('p');
title.textContent = allData["data"][i]["title"];
displayInfo.append(nameDisplayed);
displayInfo.append(title);
}
DetermineStatus();
PlaceImage()
}
function GetInfo(){
console.log("url " + url);
fetch(url,{
method:"GET",
headers:{
'client-id':clientId,
'Authorization':`Bearer ${token}`
}
})
.then(function(response){
return response.json();
})
.then(function(data){
console.log(data);
displayData(data);
})
}
// localStorage.clear();
function PlaceImage(){
if(chosenGame === "callofduty"){
document.getElementById('gameImg').src = "assets/callofduty.jpg";
}
else if(chosenGame === "valorant"){
console.log("in hereeeeeeee");
document.getElementById('gameImg').src = "assets/Valorant2.png";
}
}
function GetPandaData(){
console.log("pandascroeurl");
console.log(pandaScoreURl);
fetch(pandaScoreURl)
.then(function (response) {
return response.json();
})
.then(function (data) {
console.log("data in getpandadata");
console.log(data);
currentData = data;
console.log(currentData);
});
}
document.addEventListener("DOMContentLoaded", function(){
if(localStorage.getItem('games') === null){
originalOpen = true;
}
else{
getGames = localStorage.getItem('games');
console.log("getallitems " + getGames);
}
if(getGames === "COD"){
url = baseurl + "callofduty&live_only=true";
pandaScoreURl = codTournaments
url1 = twitchURL + codID;
chosenGame = "callofduty"
}
else if(getGames === "Volarant"){
url = baseurl + "valorant&live_only=true";
pandaScoreURl = valorantTournaments;
url1 = twitchURL + volarantID;
chosenGame = "valorant"
}
if(!originalOpen){
console.log("move madeee");
GetPandaData();
GetInfo();
console.log("Currentdate");
console.log(currentData);
setTimeout(SendInfo, 800)
}
});
function SendInfo(){
TypesOfTournoments();
setTimeout(DetermineStatus,1200);
PlaceImage()
}
function TypesOfTournoments(){
pandaScoreURl = localStorage.getItem('pandaScoreURL');
fetch(pandaScoreURl)
.then(function (response) {
return response.json();
})
.then(function (data) {
// console.log("length" + data.length);
let options = document.getElementById("currentTournos");
while (options.childNodes.length > 2) {
console.log("lastchild " + options.lastChild);
options.removeChild(options.lastChild);
}
for(let i=0;i<data.length;i++){
let newOptions = document.createElement("option");
newOptions.text = data[i]["slug"];
options.append(newOptions);
}
DisplayTeams(data);
DisplayDates(data);
});
}
titleOfTournoments.addEventListener('click', (e) => {
console.log( "thissss " + e.target.value);
fetch(pandaScoreURl)
.then(function (response) {
return response.json();
})
.then(function (data) {
// console.log("length" + data.length);
for(let i=0;i<data.length;i++){
console.log(e.target.value);
console.log(data[i]["slug"]);
if(e.target.value == data[i]["slug"]){
console.log("sdbjliudj");
break;
}
positionChosen+=1;
console.log("positionchosen " + positionChosen);
}
if(e.target.value !== "select"){
localStorage.setItem('positionChoses',positionChosen);
DisplayTeams(data);
DisplayDates(data)
}
positionChosen = 0;
})
})
listOfGames.addEventListener('click', (e) => {
// if(e.target.value } === )
console.log( "val2" + e.target.value);
if(e.target.value === "COD"){
console.log("weeee hereeee");
getGames = e.target.value;
localStorage.setItem('games',getGames);
url = baseurl + "callofduty&live_only=true";
pandaScoreURl = codTournaments;
chosenGame = "callofduty"
url1 = twitchURL + codID;
document.getElementById("main").classList.remove("main");
document.getElementById("main").classList.remove("main-valorant");
document.getElementById("main").classList.add("main-cod");
}
else if(e.target.value === "Volarant"){
getGames = e.target.value;
localStorage.setItem('games',getGames);
url = baseurl + "valorant&live_only=true"
pandaScoreURl = valorantTournaments;
chosenGame = "valorant";
url1 = twitchURL + volarantID;
document.getElementById("main").classList.remove("main");
document.getElementById("main").classList.remove("main-cod");
document.getElementById("main").classList.add("main-valorant");
}
console.log("ewbkudildflnxbc");
if(e.target.value !== "Select"){
GetInfo();
}
})
function DisplayTeams(data){
positionChosen = localStorage.getItem('positionChoses');
let numpositionChosen = parseInt(positionChosen);
console.log(data);
teamList.textContent = "Teams in Tournament";
console.log(teamList);
console.log("ahmasddddd");
console.log(data);
console.log("positionchosen " + positionChosen);
let lengths = data[numpositionChosen]["teams"].length;
console.log(lengths);
for (let j = 0; j < lengths; j++) {
var li = document.createElement("p");
li.textContent= data[numpositionChosen].teams[j].name;
teamList.appendChild(li);
}
}
function DisplayDates(data){
positionChosen = localStorage.getItem('positionChoses');
let numpositionChosen = parseInt(positionChosen);
console.log(data);
console.log(data[0].matches);
console.log(data[0].matches[0].begin_at);
// var matchList = document.createElement("p"); //change append lines to whatever we're using to append to the main file
// parentList.appendChild(matchList);
parentList.textContent = "Tournaments:";
for (let j = 0; j < data[numpositionChosen]["matches"].length; j++) {
var li = document.createElement("li");
li.textContent= data[numpositionChosen].matches[j].begin_at;
parentList.appendChild(li);
console.log("thihfodfsldfshilfdsdifslsdids");
}
}
/// moredfknlsdfkldsfikjlmfdddfsjofdhuisdzuiseanooaidpiaSOsalk;APOlsdkjldsjndskjl
function DetermineStatus(){
console.log("weeeeeeewrgfgg");
console.log("url1 " + url1);
fetch(url1,{
method:"GET",
headers:{
'client-id':clientId,
'Authorization':`Bearer ${token}`
}
})
.then(function(response){
return response.json();
})
.then(function(data){
console.log("we are hereeeeeeee");
console.log(data);
let displayUser = document.getElementById('fourthColumn');
displayUser.removeChild(displayUser.childNodes[0]);
console.log(data["data"].length)
if (data["data"].length > 0) {
let displayOn = document.createElement('p')
// document.getElementById("onlineOffline").href="https://www.twitch.tv/";
displayOn.innerText = 'Online';
displayUser.append(displayOn);
}
else {
let displayOff = document.createElement('p')
displayOff.innerText = 'Offline';
displayUser.append(displayOff);
}
document.getElementById("twiLink").href = "https://www.twitch.tv/" + chosenGame;
})
}
let timePeriod = document.getElementById('timeperiod');
timePeriod.addEventListener('click',(e) =>{
if(e.target.value === "Past"){
if(getGames === "COD"){
pandaScoreURl = "https://cors-anywhere.herokuapp.com/https://api.pandascore.co/codmw/tournaments/past?token=_Sb6lpEcpdk-URomVTPLYWMJg3OTz9gQvy8sWyM3NcEhLMuyFyo"
}
else if(getGames === "Volarant"){
pandaScoreURl = "https://cors-anywhere.herokuapp.com/https://api.pandascore.co/valorant/tournaments/past?token=_Sb6lpEcpdk-URomVTPLYWMJg3OTz9gQvy8sWyM3NcEhLMuyFyo"
}
}
else if(e.target.value === "Present"){
if(getGames === "COD"){
pandaScoreURl = "https://cors-anywhere.herokuapp.com/https://api.pandascore.co/codmw/tournaments/running?token=_Sb6lpEcpdk-URomVTPLYWMJg3OTz9gQvy8sWyM3NcEhLMuyFyo"
}
else if(getGames === "Volarant"){
pandaScoreURl = "https://cors-anywhere.herokuapp.com/https://api.pandascore.co/valorant/tournaments/running?token=_Sb6lpEcpdk-URomVTPLYWMJg3OTz9gQvy8sWyM3NcEhLMuyFyo"
}
}
else if(e.target.value === "Future"){
if(getGames === "COD"){
pandaScoreURl = "https://cors-anywhere.herokuapp.com/https://api.pandascore.co/codmw/tournaments/upcoming?token=_Sb6lpEcpdk-URomVTPLYWMJg3OTz9gQvy8sWyM3NcEhLMuyFyo"
}
else if(getGames === "Volarant"){
pandaScoreURl = "https://cors-anywhere.herokuapp.com/https://api.pandascore.co/valorant/tournaments/upcoming?token=_Sb6lpEcpdk-URomVTPLYWMJg3OTz9gQvy8sWyM3NcEhLMuyFyo"
}
}
localStorage.setItem('pandaScoreURL',pandaScoreURl);
TypesOfTournoments();
})
// //fetch timestamps for COD tournament
// fetch (codTournaments)
// .then(function (response) {
// return response.json();
// })
// .then (function (data) {
// console.log(data);
// var matchList = document.createElement("ul");
// matchList.textContent = "Tournament Matches";
// parentList.appendChild(matchList)
// let matches = data[1]["matches"].length;
// console.log(matches);
// for (let j = 0; j < data[1]["matches"].length; j++) {
// var li = document.createElement("li");
// matchList.appendChild(li);
// li.textContent= data[1].matches[j].begin_at;
// }
// })
// fetch(valorantTournaments)
// .then(function (response) {
// return response.json();
// })
// .then(function (data) {
// console.log(data);
// parentList.textContent = "Teams in Tournament 2";
// console.log(parentList)
// let lengths = data[0]["teams"].length;
// console.log(lengths);
// for (let j = 0; j < data[0]["teams"].length; j++) {
// var li = document.createElement("p");
// li.textContent= data[0].teams[j].name;
// parentList.append(li);
// }
// });