A Pen by Maureen Hernandez on CodePen.
Created
November 22, 2016 02:51
-
-
Save MauHernandez/5ccf7a216a644ca30d3804e197fe27f0 to your computer and use it in GitHub Desktop.
FreeCodeCamp TwitchTV ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<h1>Twitch TV API client</h1> | |
<div class="table-responsive"> | |
<table class="table table-striped"> | |
<tr> | |
<th>Channel</th> | |
<th>Status</th> | |
<th>Channel Link</th> | |
</tr> | |
</table> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
var channelStream = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"] | |
var url = 'https://wind-bow.hyperdev.space/twitch-api/streams/'; | |
var htmlStr = ''; | |
function getState(element){ | |
$.getJSON(url+element+'?callback=?', function(data) { | |
htmlStr += '<tr><td>'+element+'</td>'; | |
if (data.stream === null){ | |
htmlStr += '<td class="warning">Offline</td>'; | |
}else if (data.stream === undefined){ | |
htmlStr += '<td class="danger">Account close</td>'; | |
} else{ | |
htmlStr += '<td class="success">Online <br> airing: ' +data.stream.game+'</td>'; | |
} | |
htmlStr += '<td> <a href="'+data._links.channel+'">'+element+'</a></td></tr>'; | |
$("table").append(htmlStr); | |
htmlStr = "" | |
}); | |
} | |
channelStream.forEach(getState); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
td, th{ | |
text-align:center; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment