Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
<ul class="nav nav-tabs nav-justified ">
  <li class="active"><a href="#tab_a" data-toggle="tab" ><i class="fa fa-home" aria-hidden="true"></i>
All</a></li>
  <li id="#tab_on"><a href="#tab_b" data-toggle="tab"><i class="fa fa-wifi" aria-hidden="true"></i>
Online</a></li>
  <li id="#tab_off"><a href="#tab_c" data-toggle="tab"><i class="fa fa-ban" aria-hidden="true"></i>
Offline</a></li>
</ul>
<div class="tab-content">
        <!--Tab Online and Offline-->
        <div class="tab-pane active" id="tab_a"></div>          
        
        <div class="tab-pane" id="tab_b"></div>           
        
        <div class="tab-pane" id="tab_c"></div>
</div><!-- tab content -->
</div><!-- end of container -->          
       
        

              
            
!

CSS

              
                body {
    background: #e7ecea;
}
h1 {
    font-family: 'Dosis', sans-serif;
    font-weight: 400;
    line-height: 46px;
    font-size: 40px;
    margin: 0 0 23px 0;
    }
h2 {
    font-family: 'Dosis', sans-serif;
    font-weight: 800;
    font-size: 18px;
    line-height: 23px;
    margin: 0 0 23px 0;
    }
p {
    font-family: 'Open Sans', sans-serif;
    font-size: 14px;
    line-height: 23px;
    margin: 0 0 23px 0;
    }
/*Tabs*/

.nav li a{
    font-family: 'Alice', serif;
    font-size: 28px;
    font-weight: normal;
    line-height: 23px;
    margin: 0 0 23px 0;
}

/*Stream Box*/
.row {
    margin: 2px 0px;
    padding: 5px;
    line-height: 50px;
}
.stream-box{
   
   border: 2px solid #666; 
   background:#000;
}
.online{
  background:#8db600;
}
.offline{
  background:#6699cc;
}
.notAccount{
  background:#f55000;
}
.img-circle {
    height:90px;
    border-radius: 50%;
}
.streamName{
    position:relative;
    top:2em;
    font-family: 'Dosis', sans-serif;
    font-weight: 800;
    font-size: 18px;
    line-height: 23px;
    
}
.streamSummary{
    position:relative;
    top:2em;
    font-family: 'Open Sans', sans-serif;
    font-size: 18px;
    line-height: 23px;
}     


              
            
!

JS

              
                //Twitch API Implementation by Mathew Joseph

//profileImage
var profileImage = "https://dummyimage.com/50x50/ecf0e7/5c5457.jpg&text=0x3F";
//streamerName
var steamerName = "Mr.NoOne";
var sname = "Mr.NoOne";
//Summary if offline,no account or a summary of online event
var summary = "Account Deleted";
//StreamBox html
var streamHtml = '<div class="stream-box"><div class="row"><div class="col-md-3">     <img class="img-circle" src="'+profileImage+'" /></div> <div class="col-md-3"><p class="streamName text-center">'+steamerName+'</p></div><div class="col-md-6"><p class="streamSummary text-center">'+summary+'</p></div> </div></div>';
var onlineHtml = "<div class='class'>";
var offlineHtml = "";
//Base Url of twitch
var baseTwitchUrl = "https://www.twitch.tv/";
//Flag variable to knwo if its offline or online
var flag = 0;
var flagOnline = 0;
var flagOffline = 0;
//Summary trimmer function
var max = 40;
function truncateString(str, num) {
  // Clear out that junk in your trunk
  if(str.length<=num){
  return str;
  }
  else if(num<3){
    return str.substr(0,num)+"..."; 
  }
  else{
  return str.substr(0,num-3)+"...";
  }
}
//Object of popular streamers
var popularStreamers = [
  {"name":"ESL_SC2",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/esl_sc2-profile_image-d6db9488cec97125-300x300.jpeg"
  },
  {"name":"OgamingSC2",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/ogamingsc2-profile_image-9021dccf9399929e-300x300.jpeg"
  },
  {"name":"Cretetion",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/cretetion-profile_image-12bae34d9765f222-300x300.jpeg"
  },
  {"name":"FreeCodeCamp",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/freecodecamp-profile_image-d9514f2df0962329-300x300.png"
  },
  {"name":"ESL_CSGO",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/esl_csgo-profile_image-546a0c1883798a41-300x300.jpeg"
  },
  {"name":"RiotGames",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/riotgames-profile_image-4be3ad99629ac9ba-300x300.jpeg"
  },
  {"name":"Syndicate",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/syndicate-profile_image-03bf1d6ad0025f86-300x300.png"
  },
  {"name":"Summit1g",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/summit1g-profile_image-1cf38b42b1545fd7-300x300.jpeg"
  },
  {"name":"nightblue3",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/nightblue3-profile_image-be8a5ea2b11d7f12-300x300.png"
  },
  {"name":"lirik",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/lirik-profile_image-476e7a592cdfed74-300x300.png"
  },
  
  {"name":"captainsparklez",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/captainsparklez-profile_image-fe5ae89fd8b8ed0f-300x300.png"
  },
  {"name":"sodapoppin",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/sodapoppin-profile_image-10049b6200f90c14-300x300.png"
  },
  {"name":"imaqtpie",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/imaqtpie-profile_image-8efb10b7bed60d76-300x300.jpeg"
  },
  {"name":"GamesDoneQuick",
   "image":"https://static-cdn.jtvnw.net/jtv_user_pictures/gamesdonequick-profile_image-c4aa1bb1d9604981-300x300.png"
  }
];
//Loop through player data obj and sent API requests
//Setting Data for All
//Callback
function getData(id) {
    var thisI = i;
    var url = " https://wind-bow.glitch.me/twitch-api/streams/" + id;
    return $.getJSON(url).done(function() {
    console.log( "second success" );
  }).fail(function() {
    return -1;
    });  // this returns a "promise"
  
}

var AJAX = [];
var temp = "";
for (i=0; i < popularStreamers.length; i++) {
    temp = popularStreamers[i].name.toLowerCase();
    //console.log(getData(temp));
    AJAX.push(getData(temp));
    //console.log(AJAX.length);
    
}


$.when.apply($, AJAX).done(function(){
    // This callback will be called with multiple arguments,
    // one for each AJAX call
    // Each argument is an array with the following structure: [data, statusText, jqXHR]

    // Let's map the arguments into an object, for ease of use
    
    var obj = [];
    for(var i = 0, len = arguments.length; i < len; i++){
        
        obj.push(arguments[i][0]);
    }
    for(var i = 0, len = obj.length; i < len; i++){
     console.log(obj[i]["stream"]);
      //Checkif offline or online
        
        if(obj[i]["stream"]===null){
          //Hes offline so put summary to offline
          steamerName = popularStreamers[i].name;
          profileImage = popularStreamers[i].image;
          summary = "Offline";
         
        }
        else{
          //Hes online
          flag=1;
          steamerName = popularStreamers[i].name;
          profileImage = popularStreamers[i].image;
          summary = obj[i]["stream"]["channel"]["status"];
         
        }
      streamHtml = '<div class="stream-box"><div class="row"><div class="col-md-3">     <img class="img-circle" src="'+profileImage+'" /></div> <div class="col-md-3"><a class="streamName text-center" href="'+baseTwitchUrl+steamerName+'" target="_blank">'+steamerName+'</a></div><div class="col-md-6"><p class="streamSummary text-center">'+summary+'</p></div> </div></div>';
      var markup = $('<div class="stream-box"></div>').html(streamHtml);
      if(flag==1){
        onlineHtml+=markup.html();
        onlineHtml = onlineHtml.replace(/stream-box/gi, 'stream-box online');
        //console.log(t);
      }
      else{
        offlineHtml+=markup.html();
        offlineHtml = offlineHtml.replace(/stream-box/gi, 'stream-box offline');
        //alert(offlineHtml);
      }
      //Reset flag
       flag = 0;
    }
 //Append the data 
 $("#tab_a").append(onlineHtml+offlineHtml);   
});






//Tabs
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  // got val of href
  var title = $(e.target).attr("href");
  //
  if(title === "#tab_b" && flagOnline!=1){
    console.log("Online");
    $(title).append(onlineHtml);
    flagOnline = 1;
  }
  else if(title === "#tab_c" && flagOffline!=1)
  {
     console.log("Offline");
     $(title).html(offlineHtml); 
     //$(title).append("<h1>Offline</h1>");
     flagOffline = 1;
  }
  
})
              
            
!
999px

Console