-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
189 lines (183 loc) · 7.62 KB
/
scripts.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
// have to have freecodecamp, brunofin, comster404 (get this from streams)
// click on status output and go to the stream directly.
// can see additional details about what the streamer is streaming.(get this from channel)
// JSON request to get freecodecamp channel:
//
// check streams https://wind-bow.gomix.me/twitch-api/streams/freecodecamp?callback=?
// check users https://wind-bow.gomix.me/twitch-api/users/freecodecamp?callback=?
// check channel https://wind-bow.gomix.me/twitch-api/channels/freecodecamp?callback=?
// from users get display_name, bio, logo, profile url (https://www.twitch.tv/summit1g)
// from streams get stream (null is offline), status.
// to see the stream just use plain old url like https://www.twitch.tv/summit1g
$(document).ready(function() {
var profiles = ["ESL_SC2","brunofin", "comster404", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "dota2ruhub"];
for (var i = 0; i < profiles.length; i++){
var usersPromise = $.getJSON('https://wind-bow.gomix.me/twitch-api/users/' + profiles[i] + '?callback=?');
var streamsPromise = $.getJSON('https://wind-bow.gomix.me/twitch-api/streams/' + profiles[i] + '?callback=?');
var channelsPromise = $.getJSON('https://wind-bow.gomix.me/twitch-api/channels/' + profiles[i] + '?callback=?');
var noProfile = [];
var online = [];
var offline =[];
$.when(usersPromise, streamsPromise, channelsPromise).then(function(userData, streamData, channelData) {
if (userData[0].hasOwnProperty("error")) {
noProfile.push(userData[0]);
var result = '<div class="panel user profile-not-found">';
result += '<div class="panel-body row">';
result += '<div class="col-md-1">';
result += '<img class="img-circle user-logo" src="undefined" />';
result += '</div>';
result += '<div>';
result += '<div class="col-md-9 text-container">';
result += '<h4>' + userData[0].message + '</h4>';
result += '</div>';
result += '</div>';
result += '</div>';
result += '</div>';
$(".users").append(result);
return true;
}
else if (streamData[0].stream == null){
offline.push(channelData[0]);
var result = '<div class="panel user offline">';
result += '<div class="panel-body row">';
result += '<div class="col-md-1">';
result += '<img class="img-circle user-logo" src="' + channelData[0].logo + '" />';
result += '</div>';
result += '<div>';
result += '<div class="col-md-9 text-container">';
result += '<h4>' + channelData[0].name + '</h4>';
result += '</div>';
result += '</div>';
result += '</div>';
result += '</div>';
$(".users").append(result);
return true;
}
else {
online.push(streamData[0]);
var result = '<div class="panel user online">';
result += '<div class="panel-body row">';
result += '<div class="col-md-1">';
result += '<img class="img-circle user-logo" src="' + streamData[0].stream.channel.logo + '" />';
result += '</div>';
result += '<div>';
result += '<div class="col-md-9 text-container">';
result += '<h4>' + streamData[0].stream.channel.name + '</h4>';
result += '<p>' + streamData[0].stream.channel.status + '</p>';
result += '<a href="' + streamData[0].stream.channel.url + '" target="_blank" class="btn btn-info str-btn" role="button">Go to Stream</a>';
result += '</div>';
result += '</div>';
result += '</div>';
result += '</div>';
$(".users").append(result);
}
}); // $.when
} // for loop
$("#all").click(function(event){
$(".users").empty();
for (var i = 0; i < online.length; i++){
var result = '<div class="panel user online">';
result += '<div class="panel-body row">';
result += '<div class="col-md-1">';
result += '<img class="img-circle user-logo" src="' + online[i].stream.channel.logo + '" />';
result += '</div>';
result += '<div>';
result += '<div class="col-md-9 text-container">';
result += '<h4>' + online[i].stream.channel.name + '</h4>';
result += '<p>' + online[i].stream.channel.status + '</p>';
result += '<a href="' + online[i].stream.channel.url + '" target="_blank" class="btn btn-info str-btn" role="button">Go to Stream</a>';
result += '</div>';
result += '</div>';
result += '</div>';
result += '</div>';
$(".users").append(result);
}
for (var i = 0; i < offline.length; i++){
var result = '<div class="panel user offline">';
result += '<div class="panel-body row">';
result += '<div class="col-md-1">';
result += '<img class="img-circle user-logo" src="' + offline[i].logo + '" />';
result += '</div>';
result += '<div>';
result += '<div class="col-md-9 text-container">';
result += '<h4>' + offline[i].name + '</h4>';
result += '</div>';
result += '</div>';
result += '</div>';
result += '</div>';
$(".users").append(result);
}
for (var i = 0; i < noProfile.length; i++){
var result = '<div class="panel user profile-not-found">';
result += '<div class="panel-body row">';
result += '<div class="col-md-1">';
result += '<img class="img-circle user-logo" src="undefined" />';
result += '</div>';
result += '<div>';
result += '<div class="col-md-9 text-container">';
result += '<h4>' + noProfile[i].message + '</h4>';
result += '</div>';
result += '</div>';
result += '</div>';
result += '</div>';
$(".users").append(result);
}
}); // all button
$("#online").click(function(event){
$(".users").empty();
for (var i = 0; i < online.length; i++){
var result = '<div class="panel user online">';
result += '<div class="panel-body row">';
result += '<div class="col-md-1">';
result += '<img class="img-circle user-logo" src="' + online[i].stream.channel.logo + '" />';
result += '</div>';
result += '<div>';
result += '<div class="col-md-9 text-container">';
result += '<h4>' + online[i].stream.channel.name + '</h4>';
result += '<p>' + online[i].stream.channel.status + '</p>';
result += '<a href="' + online[i].stream.channel.url + '" target="_blank" class="btn btn-info str-btn" role="button">Go to Stream</a>';
result += '</div>';
result += '</div>';
result += '</div>';
result += '</div>';
$(".users").append(result);
}
}); // online button
$("#offline").click(function(event){
$(".users").empty();
for (var i = 0; i < offline.length; i++){
var result = '<div class="panel user offline">';
result += '<div class="panel-body row">';
result += '<div class="col-md-1">';
result += '<img class="img-circle user-logo" src="' + offline[i].logo + '" />';
result += '</div>';
result += '<div>';
result += '<div class="col-md-9 text-container">';
result += '<h4>' + offline[i].name + '</h4>';
result += '<h4>This User is Offline</h4>';
result += '</div>';
result += '</div>';
result += '</div>';
result += '</div>';
$(".users").append(result);
}
}); // offline button
$("#not-found").click(function(event){
$(".users").empty();
for (var i = 0; i < noProfile.length; i++){
var result = '<div class="panel user profile-not-found">';
result += '<div class="panel-body row">';
result += '<div class="col-md-1">';
result += '<img class="img-circle user-logo" src="undefined" />';
result += '</div>';
result += '<div>';
result += '<div class="col-md-9 text-container">';
result += '<h4>' + noProfile[i].message + '</h4>';
result += '</div>';
result += '</div>';
result += '</div>';
result += '</div>';
$(".users").append(result);
}
}); // offline button
}); // $.(document).ready