Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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-fluid">
  <div id="info-box" class="center-block">
      <div class="row">
    <div class="col-md-10 col-xs-10">
      <h1 id="header"><i class="fa fa-twitch" aria-hidden="true"></i> TWITCH STREAMS</h1>
    </div>
    <div class="col-md-2 col-xs-2">
      <select name="filter-select" id="filter-select">
        <option value="all" selected="selected">Show All</option>
        <option value="online">Show Online</option>
        <option value="offline">Show Offline</option>
      </select>
    </div>
  </div>
  </div>
</div>
              
            
!

CSS

              
                /***
TODO LIST

1.) Relocate/Repurpose Filter Select
2.) Optimize for Mobile
3.) Refactor code, DRY principle.
4.) Add comments.

***/

html,
body {
  background-color: #262626;
}

a,
a:hover,
a:active,
a:link,
a:visited {
  text-decoration: none;
}

#info-box {
  width: 700px;
}

#filter-select {}

.fa-twitch {
  color: #6441A5;
}

#header {
  color: #D9D9D6;
  font-family: 'Oswald', Arial, sans-serif;
  font-weight: bold;
}

.hidden {
  display: hidden;
}

.logo {
  border: 1px solid #000;
  line-height: 1;
}

.name {
  font-family: 'Arimo', Helvetica, Arial, sans-serif;
  text-align: center;
  line-height: 1;
}

.status {
  font-family: 'Arimo', Helvetica, Arial, sans-serif;
  text-align: center;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.online {
  color: #D9D9D6;
  padding: 5px;
  display: flex;
  align-items: center;
  border: 1px solid #262626;
  background-color: #6441A5;
}

.online:hover {
  color: #262626;
  background-color: #B9A3E3;
  font-weight: bold;
}

.offline:hover {
  color: #262626;
  background-color: #B9A3E3;
  font-weight: bold;
}

.offline {
  color: #B9A3E3;
  padding: 5px;
  display: flex;
  align-items: center;
  border: 1px solid #262626;
  background-color: #3B2064;
}
              
            
!

JS

              
                $(document).ready(function() {
  var channels = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "test_channel", "brunofin", "comster404"];
  
  function getChannelInfo(channelUrl) {
    return $.ajax({
      type: 'GET',
      datatype: 'jsonp',
      url: channelUrl,
      headers: {
        'Client-ID': 'ayub1p5dxz1v5x2dfki9n25r47co4ia'
      },
      success: function(data) {
        return data;
      }
    })
  }
  
  function getStreamInfo(channelName) {
    return $.ajax({
      type: 'GET',
      datatype: 'jsonp',
      url: 'https://api.twitch.tv/kraken/streams/' + channelName + '?client_id=ayub1p5dxz1v5x2dfki9n25r47co4ia',
      headers: {
        'Client-ID': 'ayub1p5dxz1v5x2dfki9n25r47co4ia'
      },
      success: function(data) {
        buildList(data, channelName);
      },
      error: function(data) {
        if (data.status == 422 || data.status == 404) {
          var logo = "https://static-cdn.jtvnw.net/jtv_user_pictures/xarth/404_user_50x50.png";
          var $fixture = buildHTML(logo, channelName, "Unavailable", "#", "offline");
          $($fixture).appendTo('#info-box');
        }        
      }
    })    
  }
  
  function buildHTML(logo, name, status, url, css) {
    return $([
        '<a href="' + url + '" target="_blank">',
        '<div class="row '+ css +'">',
        '  <div class="col-md-1 col-xs-1"><img class="logo img-circle" src="' + logo + '" width="50" height="50"></div>',
        '  <div class="col-md-3 col-xs-3"><div class="name">' + name + '</div></div>',
        '  <div class="col-md-8 col-xs-8"><div class="status">' + status + '</div></div>',
        '</div>',
        '</a>'
      ].join("\n"));
  }

  function buildList(data, channelName) {
    if (data.stream) {
      var dsc = data.stream.channel;
      var $fixture = buildHTML(dsc.logo, dsc.display_name, dsc.status, dsc.url, "online");
      $($fixture).appendTo('#info-box');
    } else {
      var result = getChannelInfo(data._links.channel);
      result.done(function(data) {
        var defaultURL = "https://static-cdn.jtvnw.net/jtv_user_pictures/xarth/404_user_50x50.png";
        var logo = data.logo ? data.logo : defaultURL;
        var $fixture = buildHTML(logo, data.display_name, "Offline", data.url, "offline");
        $($fixture).appendTo('#info-box');
      });
    }
  }

  $("#filter-select").change(function(data) {
    switch (data.target.value) {
      case "all":
        $('.offline').removeClass('hidden');
        $('.online').removeClass('hidden');
        break;
      case "online":
        $('.online').removeClass('hidden');
        $('.offline').addClass('hidden');
        break;
      case "offline":
        $('.offline').removeClass('hidden');
        $('.online').addClass('hidden');
        break;
    }
  });

  channels.map(function(index) {
    getStreamInfo(index);
  });

});
              
            
!
999px

Console