css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <link href="https://fonts.googleapis.com/css?family=Londrina+Outline" rel="stylesheet">
<div class="header">
  <div class="container">
    <h1>TWITCH STREAMERS</h1>
  </div>
</div>

<div class="container">
  <button id="all" class="btn active">ALL</button>
  <button id="live" class="btn">ONLINE</button>
</div>

<div class="container" id="content-all">
  <!--<div class="channel-box"> this is a sample item
    <img src="saas" alt="">
    <div class="text">
      <a href="#">name <span class="red">[ONLINE]</span></a>
      <p>name</p>
    </div>
  </div>-->
</div>

<div class="container" id="content-live">
  <!--<div class="video-box"> this is a sample item
    <img src="sas" alt="" class="thumbnail-image">
    <img src="as" alt="" class="logo-image">
    <div class="text">
      <a href="">title</a>
      <p>name</p>
    </div>
  </div>-->
</div>

<div class="container">
  <div style="width:100%">
    <hr>
    <p style="text-align:center">Coded by Sahan</p>
  </div>
</div>
            
          
!
            
              div{
  /*border: 1px red solid;*/
}

body{
  font-family: sans-serif;
  margin: 0;
}

.container{
  width: 890px;
  margin-left: auto;
  margin-right: auto;
  padding: 5px;
  display: flex;
  flex-wrap: wrap;
}

.header{
  background-color: #6441A4;
  color: #ffffff;
}
.header h1{
  font-size: 2.5em;
  font-family: 'Londrina Outline', cursive;
  margin: 0.1em 0;
}

.btn{
  background-color: #fff;
  color: #333;
  padding: 7px;
  border: 2px #6441A4 solid; 
  font-size: 1em;
  margin-right: 3px;
}
.btn:hover{
  background-color: #6441A4;
  color: #fff;
}
.active{
  background-color: #6441A4;
  color: #fff;
}

.channel-box{
  display: flex;
  padding: 7px 20px;
  margin-bottom: 6px;
  background-color: #c3a2ff;
  width: 100%;
}
.channel-box img{
  width: 70px;
  height: 70px;
}
.channel-box .text{
  padding: 7px 20px;
}
.channel-box .text a{
  color: #333;
  text-decoration: none;
  font-size: 1em;
}
.channel-box .text a .red{
  color: red;
}
.channel-box .text p{
  font-size: 0.8em;
  margin: 0.1em 0;
}

.video-box{
  display: flex;
  flex-wrap: wrap;
  padding: 7px;
  background-color: #c3a2ff;
  width: 290px;
  margin-bottom: 6px;
  margin-right: 10px;
}
.video-box .thumbnail-image{
  width: 100%;
  height: 180px;
  margin-bottom: 7px;
}
.video-box .logo-image{
  width: 70px;
  height: 70px;
}
.video-box .text{
  padding: 7px;
  width: 200px;
}
.video-box .text a{
  text-decoration: none;
  color: #333;
  font-size: 1em;
}
.video-box .text p{
  font-size: 0.8em;
  margin: 0.1em 0;
}

@media only screen and (max-width: 900px){
  .container{
    width: 95%;
  }
}
            
          
!
            
              $(document).ready(function(){
  var channels = ["OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "ESL_SC2"]; 
  var channelObjs = [];  
  var loopItem = 0;
  
  channels.forEach(function(channel, index, array){
    $.getJSON("https://wind-bow.glitch.me/twitch-api/streams/" + channel + "?format=json", function(onlineChannel){
      
      if(onlineChannel.stream == null){ //get channel details for offline channels
        
        $.getJSON("https://wind-bow.glitch.me/twitch-api/channels/" + channel + "?format=json", function(offlineChannel){
          
          var channelDetails = {                    
            "live" : false,
            "name" : offlineChannel.display_name,
            "secondName" : offlineChannel.name,
            "logo" : offlineChannel.logo,
            "link" : offlineChannel.url,
            "status" : offlineChannel.status
          };
          
          channelObjs.push(channelDetails);         
          loopItem++;
          
          if(loopItem == array.length){
            appendData();
          }
          
        });
      }
      else{ //online channels
        
        var channelDetails = {
          "live" : true,
          "name" : onlineChannel.stream.channel.display_name,
          "secondName" : onlineChannel.stream.channel.name,
          "logo" : onlineChannel.stream.channel.logo,
          "link" : onlineChannel.stream.channel.url,
          "description" : onlineChannel.stream.game,
          "thumbnail" : onlineChannel.stream.preview.large,     
          "status" : onlineChannel.stream.channel.status
        };
        
        channelObjs.push(channelDetails);  
        loopItem++;
        if(loopItem == array.length - 1){
          appendData();
        }
        
      }
    });
  });
 
  function appendData(){
    //console.log(channelObjs); //works !!
    //console.log(channelObjs[0]); // undefined
    //console.log(channelObjs["0"]); // undefined
    //console.log(channelObjs.length); // 0  
    //console.log(typeof(channelObjs)); // object
    
    channelObjs.forEach(function(channelObj){ 
    if(channelObj.live){
      var html1;
      var html2;
      var logoURL = channelObj.logo;
      var name = channelObj.name;
      var secondName = channelObj.secondName;
      var url = channelObj.link;
      var description = channelObj.description;
      var thumbnailImage = channelObj.thumbnail;
      var status = channelObj.status;
      
      html1 = '<div class="channel-box"><img src="';
      html1 += logoURL + '"><div class="text"><a href="' + url + '" target="_blank">' + name + '<span class="red"> [LIVE]</span></a>';
      html1 += '<p> ' + status + '</p></div></div>';
      
      html2 = '<div class="video-box"><img src="' + thumbnailImage + '" class="thumbnail-image"><img src="' + logoURL + '" class="logo-image"><div class="text"><a href="' + url + '" target="_blank">' + status + '</a><p>' + name + '</p></div></div>';
      $("#content-all").append(html1);
      $("#content-live").append(html2);
    }
    else{
      var html;
      var logoURL = channelObj.logo;
      var name = channelObj.name;
      var secondName = channelObj.secondName;
      var url = channelObj.link;
      var status = channelObj.status ? channelObj.status : "[No description]";
      
      html = '<div class="channel-box"><img src="';
      html += logoURL + '"><div class="text"><a href="' + url + '" target="_blank">' + name + '</a>';
      html += '<p> ' + status + '</p></div></div>';
      
      $("#content-all").append(html);
    }
  }); 
  }
  
  $("#content-live").hide();
  
  $("#all").click(function(){
    $("#content-all").show();
    $("#content-live").hide();
    $("#all").addClass("active");
    $("#live").removeClass("active");
  });
  $("#live").click(function(){
    $("#content-all").hide();
    $("#content-live").show();
    $("#live").addClass("active");
    $("#all").removeClass("active");
  });
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console