-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
80 lines (78 loc) · 2.2 KB
/
script.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
const channels = [
"ESL_SC2",
"OgamingSC2",
"cretetion",
"freecodecamp",
"storbeck",
"habathcx",
"RobotCaleb",
"noobs2ninjas",
];
const getChannelInfo = () => {
channels.forEach(channel => {
const makeURL = (type, name) => {
return (
"https://twitch-proxy.freecodecamp.rocks/twitch-api/" +
type +
"/" +
name +
"?callback=?"
);
};
$.getJSON(makeURL("streams", channel), data => {
let game, status;
if (data.stream === null) {
game = "Offline";
status = "offline";
} else if (data.stream === undefined) {
game = "Account Closed";
status = "offline";
} else {
game = data.stream.game;
status = "online";
}
$.getJSON(makeURL("channels", channel), data => {
const logo =
data.logo !== null
? data.logo
: "https://dummyimage.com/50x50/ecf0e7/5c5457.jpg&text=0x3F",
name = data.display_name !== null ? data.display_name : channel,
description = status === "online" ? ": " + data.status : "";
html =
'<div class="row ' +
status +
'"><div class="col-xs-2 col-sm-1" id="icon"><img src="' +
logo +
'" class="logo"></div><div class="col-xs-10 col-sm-3" id="name"><a href="' +
data.url +
'" target="_blank">' +
name +
'</a></div><div class="col-xs-10 col-sm-8" id="streaming">' +
game +
'<span class="hidden-xs">' +
description +
"</span></div></div>";
status === "online"
? $("#display").prepend(html)
: $("#display").append(html);
});
});
});
};
$(document).ready(() => {
getChannelInfo();
$(".selector").click(() => {
$(".selector").removeClass("active");
$(this).addClass("active");
const status = $(this).attr("id");
if (status === "all") {
$(".online, .offline").removeClass("hidden");
} else if (status === "online") {
$(".online").removeClass("hidden");
$(".offline").addClass("hidden");
} else {
$(".offline").removeClass("hidden");
$(".online").addClass("hidden");
}
});
});