Guest User

Untitled

a guest
Feb 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. $(document).ready(function(){
  2. var channels = ['ESL_SC2', 'OgamingSC2', 'cretetion', 'freecodecamp', 'storbeck', 'habathcx', 'RobotCaleb', 'noobs2ninjas'];
  3. getChannelsNames();
  4.  
  5. function getChannelsNames(){
  6. var myHtml = '', status = 'Offline';
  7.  
  8. channels.forEach(function(channel, callback){
  9. $.getJSON('https://wind-bow.glitch.me/twitch-api/streams/' + channel, function(json){
  10. status = onlineStatus(json);
  11. myHtml += infoChannels(channel, status);
  12. }).fail(function(){
  13. console.log('Error');
  14. myHtml += infoChannels(channel, status);
  15. });
  16. });
  17. $('.channels').html(myHtml);
  18. }
  19.  
  20. function onlineStatus(json){
  21. if(json.stream){
  22. return json.stream.game;
  23. } else {
  24. return 'Offline';
  25. }
  26. }
  27.  
  28. function infoChannels(channel, status){
  29. return "<div class='row'><div class='col-12 col-md-4 bg-info'>" + channel + "</div><div class='col-12 col-md-8 bg-primary text-center'>" + status + "</div></div>";
  30. }
  31. });
Add Comment
Please, Sign In to add comment