-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlivescript.js
More file actions
154 lines (120 loc) · 5.63 KB
/
Copy pathlivescript.js
File metadata and controls
154 lines (120 loc) · 5.63 KB
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
var submitEl = document.getElementById('submitbtn');
var leagueInputEl = document.getElementById('leagueInput');
var loadEl = document.getElementById('loading');
var scoreBoardEl = document.getElementById('scoresInfo');
var formEl = document.getElementById('gameSelect');
var leagueBadgeEl = document.getElementById('leagueBadge');
var leagueNameEl = document.getElementById('leagueName');
var restartEl = document.getElementById('restart');
var dateEl = document.getElementById('currentdate');
var idArray = [];
var leagueArray = [];
var league = [
{
league_name: 'england',
league_id: '149'
},
{
league_name: 'ghana',
league_id: '177'
}
]
var formSubmitHandler = function(event){
event.preventDefault();
//get value from the league name
var leagueSelected = leagueInputEl.value.trim().toLowerCase();
for(let i =0; i<league.length; i++) {
if(leagueSelected===league[i].league_name){
submitEl.classList.add('loading');
getScores(league[i].league_id);
}
}
leagueInputEl.value = '';
}
var getScores = function(league_id) {
var apiKey = '157ce318877b28613f3f957ccd28aa5239d122320755f5ddb85085a83b831836';
//User Input;
var dateFrom = 'from=' + moment().format('YYYY-MM-DD') + '&to=' + moment().format('YYYY-MM-DD');
// var league_id = '177';
var apiUrl = 'https://apiv3.apifootball.com/?action=get_events&'+ dateFrom + '&league_id=' + league_id + '&APIkey=' + apiKey;
fetch(apiUrl)
.then(response => response.json())
.then(function(data){
console.log(data);
displayScores(data);
})
.catch(err => noMatch(err));
//console.error(err));
}
var noMatch = function(error){
console.log(error);
window.alert('No game is happening today!');
location.reload();
}
var displayScores = function(scoresInfo){
scoreBoardEl.classList.remove("hide");
formEl.classList.add("hide");
restartEl.classList.remove("hide");
leagueBadgeEl.src = scoresInfo[0].league_logo;
leagueNameEl.textContent = "You are viewing the latest games from a " + scoresInfo[0].league_name;
dateEl.textContent = "You are viewing the games happening today! Current Date: " + moment().format('YYYY-MM-DD');
//scoreBoardEl.innerHTML += `<img src="./images/197598_like_modern_fav_add_favourites_icon.png" class="likeIcon" onclick="likeHandler(this)" id="${scoresInfo[0].league_id}" name="${scoresInfo[0].country_name}">`;
for (i=0; i<scoresInfo.length; i++){
scoreBoardEl.innerHTML +=
`
<div class="grid-x border-x">
<div class="cell small-4">
<h1 class="home">Home Team:</h1>
<img class="homelogo" src="${scoresInfo[scoresInfo.length-1-i].team_home_badge}"></img>
<h1 class="homeName">${scoresInfo[scoresInfo.length-1-i].match_hometeam_name}</h1>
<h2 class="homehtScore">Half Time Score: ${scoresInfo[scoresInfo.length-1-i].match_hometeam_halftime_score}</h2>
<h2 class="homeFtScore">End Score: ${scoresInfo[scoresInfo.length-1-i].match_hometeam_ft_score}</h2>
</div>
<div class="cell small-4">
<h3>Time of the match: ${scoresInfo[scoresInfo.length-1-i].match_time} </h3>
<img class="versus" src="./images/vs-41932.png">
</div>
<div class="cell small-4">
<h2 class="away">Away Team: </h2>
<img class="awaylogo" src="${scoresInfo[scoresInfo.length-1-i].team_away_badge}"></img>
<h1 class="awayName">${scoresInfo[scoresInfo.length-1-i].match_awayteam_name}</h1>
<h2 class="awayhtScore"> Half Time Score: ${scoresInfo[scoresInfo.length-1-i].match_awayteam_halftime_score}</h2>
<h2 class="awayFtScore">End Score: ${scoresInfo[scoresInfo.length-1-i].match_awayteam_ft_score}</h2>
</div>
</div>` ;
var homeEl = document.querySelectorAll('.home');
var awayEl = document.querySelectorAll('.away');
var winner = document.createElement('img');
var even = document.createElement('img');
var even2 = document.createElement('img');
winner.setAttribute('src', "./images/PikPng.com_winner-png_1183198.png");
winner.classList.add('winnersymbol')
even.setAttribute('src', './images/scale-icon-413.png');
even.classList.add('evensymbol')
even2.setAttribute('src', './images/scale-icon-413.png');
even2.classList.add('evensymbol');
if(scoresInfo[scoresInfo.length-1-i].match_hometeam_ft_score > scoresInfo[scoresInfo.length-1-i].match_awayteam_ft_score) {
homeEl[i].append(winner);
} else if (scoresInfo[scoresInfo.length-1-i].match_hometeam_ft_score < scoresInfo[scoresInfo.length-1-i].match_awayteam_ft_score) {
awayEl[i].append(winner);
} else {
homeEl[i].append(even);
awayEl[i].append(even2);
}
}
// var likeHandler
}
/* var likeHandler = function(element) {
var id=element.id;
var name=element.name;
idArray.push(id);
leagueArray.push(name);
console.log(idArray);
console.log(leagueArray);
window.localStorage.setItem("leagueid",JSON.stringify(idArray));
window.localStorage.setItem("leagueName",JSON.stringify(leagueArray));
} */
// var likeEl = document.querySelectorAll('.likeIcon');
// likeEl.addEventListener('click', likeHandler);
submitEl.addEventListener('click', formSubmitHandler);
restartEl.addEventListener('click', function(){location.reload()});