cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <div class="container">
          <div class="row" id="title">
              <h1>Twitch.tv Streams</h1>
          </div>
          <div class="row" id="filters">
              <nav class="navbar navbar-inverse" id="categories">
                  <div class="navbar-static">
                      <ul class="nav navbar-nav">
                          <li class="active"><a id="all" onclick=showAll()>ALL<span class="sr-only">(current)</span></a></li>
                          <li><a id="online" onclick=showOnline()>ONLINE</a></li>
                          <li><a id="offline" onclick=showOffline()>OFFLINE</a></li>
                      </ul>
                  </div>
              </nav>
          </div>
          <div class="row userList" data-role="searchList" data-filter="true" data-input="searchBar">
              <div class="row user" id="user0">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
              <div class="row user" id="user1">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
              <div class="row user" id="user2">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
              <div class="row user" id="user3">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
              <div class="row user" id="user4">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
              <div class="row user" id="user5">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
              <div class="row user" id="user6">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
              <div class="row user" id="user7">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
              <div class="row user" id="user8">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
              <div class="row user" id="user9">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
              <div class="row user" id="user10">
                  <div class="col-xs-2 col-xs-offset-1 avatar">
                      <img src="http://gez.bz/twitchtv/img/avatar.png">
                  </div>
                  <div class="col-xs-6 username">
                      <p><a target="_blank" class="displayName"></a></p>
                  </div>
                  <div class="col-xs-2 status">
                      <p><a target="_blank"><i class="fa fa-eye-slash"></i></a> </p>
                  </div>
              </div>
          </div>
      </div>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Glegoo);

body, a {
  background-color: #222;
  color: #fff;
  font-family: 'Arial', sans-serif;
}
a:hover, i:hover {
  text-decoration: none;
  color: #9D9D9D;
}

.container {
  width: 400px;
}
h1 {
  text-align: center;
  font-family: 'Glegoo','Futura';
}
p {
  margin:0px;
}
.navbar-inverse {
  border: none;
  font-size: 1.5em;
}
.navbar-toggle {
  float: left;
  margin-left: 15px;
}
.navbar-inverse .navbar-nav > .active > a, .navbar-inverse .navbar-nav > .active > a:focus, .navbar-inverse .navbar-nav > .active > a:hover {
  background-color: #222;
}
.navbar ul {
  margin-left: 55px;
}
#searchBar {
  width: 240px;
  margin: 0 80px 30px 80px;
  border: 1px solid black;
  border-radius: 20px;
  padding: 10px 10px 10px 15px;
  color: #222;
}
.search-form input[type="search"] {  /* Doesn't work */
    	-webkit-box-shadow: none;
    	outline: -webkit-focus-ring-color auto 0px;
}
.userList {
  margin-left:5px;
}
.user {
  margin-bottom: 20px;
  display: none;
}
.avatar img, .username a, i {
  cursor: pointer;
}
.avatar img {
  width: 50px;
  height: 50px;
  border-radius: 50%;

}
.username, .status {
  /*color: #222;*/
  font-size: 1em;
  padding: 0 15px 0 15px;
}
.status i {

}
            
          
!
            
              $(document).ready(function() {
  /*
  JSON call fix due to Twitch.tv not supporting Cross-Origin Resource Sharing
  https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Zipline-Use-the-Twitchtv-JSON-API
  */
  var JSONP = (function(){ 'use strict';
    var counter = 0;

    var memoryleakcap = function() {
        if (this.readyState && this.readyState !== "loaded" && this.readyState !== "complete") { return; }

        try {
            this.onload = this.onreadystatechange = null;
            this.parentNode.removeChild(this);
        } catch(ignore) {}
    };

    return function(url, callback) {
        var uniqueName = 'callback_json' + (++counter);

        var script = document.createElement('script');
        script.src = url + (url.toString().indexOf('?') === -1 ? '?' : '&') + 'callback=' + uniqueName;
        script.async = true;

        window[ uniqueName ] = function(data){
            callback(data);
            window[ uniqueName ] = null;
            try { delete window[ uniqueName ]; } catch (ignore) {}
        };

        script.onload = script.onreadystatechange = memoryleakcap;

        document.getElementsByTagName('head')[0].appendChild( script );

        return uniqueName;
    };
  }());

  //// VARIABLE DEFINITION ////
  var userList = ["freecodecamp","medrybw","storbeck","terakilobyte","habathcx","robotcaleb","thomasballinger","noobs2ninjas","beohoff","brunofin","comster404"];
  var channelsBaseUrl = "https://api.twitch.tv/kraken/channels/";
  var streamsBaseUrl = "https://api.twitch.tv/kraken/streams/";
  var userID;
  var userIDList = [];

  //// FUNCTIONS ////  
  function fetchStreamDetails() {
    // Set element IDs to username
    for (i=0;i<userList.length;i++) {
      $('#user'+i).attr('id',userList[i]);
      userIDList[i] = '#'+userList[i];
    };
    
    // Fetch channel stream
    $('.user').each(function(index) {
      var twitchChannelsAPI = channelsBaseUrl+$(this).attr('id');
      
      JSONP( twitchChannelsAPI, function(json) {
          console.log(json);
        //// LOGO ////
        if (typeof(json.logo) === 'string') {
          $('#'+json.name).find('img').attr('src',json.logo).css('background-color','#222');
        } else {
          $('#'+json.name).find('img').attr('src','http://gez.bz/twitchtv/img/avatar-placeholder.png');
        };
        
        //// USER NAME AND URL ////
        $('#'+json.name).find('.username a').attr('href',json.url).html(json.display_name+'<br>Followers: '+json.followers+'<br>Views: '+json.views);
        $('#'+json.name).addClass('offline');
        
        //// CLOSED ACCOUNTS ////
        if (json.status === 422) {
          $('#'+json.name).find('.username a').text(json.message);
        };
      }); //// END CHANNEL JSONP CALL ////
      
      
      //// STREAMS JSONP CALL ////
      var twitchStreamsAPI = streamsBaseUrl+$(this).attr('id');
      var loadDelay = window.setTimeout(function() {
        JSONP( twitchStreamsAPI, function(json) {
          //// STREAM STATUS ////
          if (json.stream != null) {
            $('#'+json.stream.channel.name).find('.status i').removeClass('fa-eye-slash').addClass('fa-youtube-play').attr('alt','Play stream');
            $('#'+json.stream.channel.name).find('.username a').html(json.stream.channel.display_name+'<br>'+json.stream.game+'<br>Current viewers: '+json.stream.viewers);
            $('#'+json.stream.channel.name).find('.status a').attr('href',json.stream.channel.url);
            $('#'+json.stream.channel.name).find('.username').css('padding-top','0px').css('padding-bottom','0px');
            $('#'+json.stream.channel.name).removeClass('offline').addClass('online');
          };

          $('.user').each(function(index) {
            if ($(this).find('.username a').text() === "") {
              $(this).find('.username a').text("Channel '"+$(this).attr('id')+"' is not available on Twitch");
            };
          });

        }); //// END STREAMS JSONP CALL ////
      },1000);
      
    });
  }
      

  //// CALL FUNCTIONS ////
  fetchStreamDetails();
  var loadDelay = window.setTimeout(function() {$('.user').show();},1500);

});

  //// ONLINE OFFLINE FILTER ////
  function showAll() {
    $('.user').show();
  }
  function showOnline() {
    $('.user').hide();
    $('.online').show();
  }
  function showOffline() {
    $('.user').hide();
    $('.offline').show();
  }
            
          
!
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