123

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.

            
              <div class="fixed-width center-block">
    <div class="btn-group btn-group-justified">
      <div class="btn-group">
        <a id="show-all" class="btn btn-header" role="button">All</a>
      </div>
      <div class="btn-group">
        <a id="show-online" class="btn btn-header" role="button">Online</a>
      </div>
      <div class="btn-group">
        <a id="show-offline" class="btn btn-header" role="button">Offline</a>
      </div>
    </div>
    <!-- Adding the filtering search bar-->
    <div class="input-group">
      <span class="input-group-btn">
      <button class="btn" type="button">
       <i class="glyphicon glyphicon-search" aria-hidden="true"></i>
      </button>
    </span>
      <input type="text" class="form-control" placeholder="username" id="searchForm">
    </div>

    <!-- List of people that are streaming to be displayed -->
    <div class="list-items">
      <ul class="list-unstyled" id="people">
        <div id="list-container">
          <li class="person-item" id="item0">
            <a href="#" class="btn btn-list center-element btn-box-shadow" role="button">
              <img class="img-circle" src="">
              <div class="profile-name"></div>
              <div class="stream-info"></div>
            </a>
          </li>
          <li class="person-item" id="item1">
            <a href="#" class="btn btn-list center-element btn-box-shadow" role="button">
              <img class="img-circle" src="">
              <div class="profile-name"></div>
              <div class="stream-info"></div>
            </a>
          </li>
          <li class="person-item" id="item2">
            <a href="#" class="btn btn-list center-element btn-box-shadow" role="button">
              <img class="img-circle" src="">
              <div class="profile-name"></div>
              <div class="stream-info"></div>
            </a>
          </li>
          <li class="person-item" id="item3">
            <a href="#" class="btn btn-list center-element btn-box-shadow" role="button">
              <img class="img-circle" src="">
              <div class="profile-name"></div>
              <div class="stream-info"></div>
            </a>
          </li>
          <li class="person-item" id="item4">
            <a href="#" class="btn btn-list center-element btn-box-shadow" role="button">
              <img class="img-circle" src="">
              <div class="profile-name"></div>
              <div class="stream-info"></div>
            </a>
          </li>
          <li class="person-item" id="item5">
            <a href="#" class="btn btn-list center-element btn-box-shadow" role="button">
              <img class="img-circle" src="">
              <div class="profile-name"></div>
              <div class="stream-info"></div>
            </a>
          </li>
          <li class="person-item" id="item6">
            <a href="#" class="btn btn-list center-element btn-box-shadow" role="button">
              <img class="img-circle" src="">
              <div class="profile-name"></div>
              <div class="stream-info"></div>
            </a>
          </li>
          <li class="person-item" id="item7">
            <a href="#" class="btn btn-list center-element btn-box-shadow" role="button">
              <img class="img-circle" src="">
              <div class="profile-name"></div>
              <div class="stream-info"></div>
            </a>
          </li>
        </div>
      </ul>
    </div>
  </div>
            
          
!
            
              body {
  background-color:#fdd5c0;
}

/* disables link styles */
a:link,
a:visited {
  text-decoration: none;
  color: #000000;
}

.list-items {
  background-color: #f46161;
  padding: 0px 0px 0px 0px;
}

.fixed-width {
  width: 500px;
}

.person-item {
  padding: 5px 0px 5px 0px;
}

.profile-name { 
  font-family: FontAwesome;
  position: absolute;
  color: #FFFFFF;
  top: 30%;
  left: 35%;
  right: 50%;
  text-align: left;
  text-shadow: 1px 1px #000000;
  font-size: 20px;
}

.stream-info {
  font-family: FontAwesome;
  position: absolute;
  color: #FFFFFF;
  left: 35%;
  bottom: 10%;
  text-align: left;
  text-shadow: 1px 1px #000000;
  font-size: 10px;
}

.profile-status {
  margin: 0 5%;
}

.img-circle {
  width: 70px;
  float: left;
}

.center-block {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.center-element {
  width: 100%;
  position: relative;
}

.btn {
  background-color: #FFFFFF;
  overflow:hidden;
}

.btn-header {
  background-color: #f46161;
  font-family: FontAwesome;
  color: white;
  text-shadow: 1px 1px #000000;
}

.btn-header:hover,
.btn-header:active {
  background-color: #ffcf62;
  color: white;
}

.btn-list {
  background-color: #f89d5b;
  margin: 0px 0px 10px 0px;
  border: none;
}

.btn-list:hover {
  background-color: #ffcf62;
}

.btn-box-shadow {
  -webkit-box-shadow: 2px 3px 0px rgba(4, 4, 4, 0.3);
  -moz-box-shadow: 2px 3px 0px rgba(4, 4, 4, 0.3);
  box-shadow: 2px 3px 0px rgba(4, 4, 4, 0.3);
}

.fa-ban {
  position: absolute;
  top: 30%;
  right: 5%;
  color: #fd1c15;
}

.fa-check-circle-o {
  position: absolute;
  top: 30%;
  right: 5%;
  color: #00b800;
}

#list-container {
  padding-top: 10px;
  padding-left: 30px;
  padding-right: 30px;
}

            
          
!
            
              var channels = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
var online = [];
var offline = [];
var defaultImgUrl = "http://placepu.gs/200/200";
var notFoundInfo = "Account Closed";
var showAllBtn, showOnlineBtn, showOfflineBtn, searchForm;

function getChannelInfo(channelName) {
  return $.getJSON('https://wind-bow.gomix.me/twitch-api/channels/' + channelName + "?callback=?");
}

function onRequestFail(jqXHR, textStatus, errorThrown) {
  console.log("There was an error with the request." + textStatus + errorThrown);
}

function onStreamCallback(data, index) {
  if(typeof(data) === "undefined") {
    console.log("Caught undefined data here");
  } else {
    if(data.stream === null) {
      var selector = '#item' + index;
      var listItem = $(selector);
      listItem.find('a').append("<i class='fa fa-ban fa-align-right fa-2x'></i>");
      offline.push(selector);
    } else if(data.stream === 'undefined') {
      // account cancelled
      listItem.find('.stream-info').html('Account closed');
    }
  }
}

function onChannelCallback(data, index) {
    var imgUrl = data.logo;
    if (!imgUrl) {
      imgUrl = defaultImgUrl;
    }
    var name = data.display_name;
    var url = data.url;
    var selector = '#item' + index;
    var listItem = $(selector);
    listItem.find('.profile-name').html(channels[index]);
    listItem.find('a').prop('href', url).attr('target', '_blank');
    listItem.find('img').prop('src', imgUrl);
    listItem.find('.profile-name').html(name);
    if(offline.indexOf(selector) < 0) {
        listItem.find('a').append("<i class='fa fa-check-circle-o fa-2x'></i>");
        online.push(selector);
        var extraInfo = data.status;
        if(extraInfo.length > 45) {
          extraInfo = extraInfo.substr(0, 45);
          extraInfo += " ...";
        }
        listItem.find('.stream-info').html(extraInfo);
    }
}

function retrieveStream(streamName) {
  return $.getJSON('https://wind-bow.gomix.me/twitch-api/streams/' + streamName + "?callback=?");
}

function onShowAllClicked() {
  $('.person-item').show();
}

function onShowOnlineClicked() {
  offline.forEach(function(element) {
    $(element).hide();
  });
  online.forEach(function(element) {
    $(element).show();
  });
}

function onShowOfflineClicked() {
  online.forEach(function(element) {
    $(element).hide();
  });
  offline.forEach(function(element) {
    $(element).show();
  });
}

function onSearchInputChange(event) {
  if (typeof(event) === "undefined")
    return;
  var searchValue = (event.target.value).toLowerCase();
  if (searchValue === "") {
    onShowAllClicked();
  } else {
    $('.person-item').each(function(index) {
      var profileName = $(this).find('.profile-name').text().toLowerCase();
      var indexOfEvent = profileName.indexOf(event);
      if (profileName.indexOf(searchValue) < 0)
        $(this).hide();
      else
        $(this).show();
    });
  }
}

function prepareUI() {
  showAllBtn = $('#show-all');
  showAllBtn.click(onShowAllClicked);
  showOnlineBtn = $('#show-online');
  showOnlineBtn.click(onShowOnlineClicked);
  showOfflineBtn = $('#show-offline');
  showOfflineBtn.click(onShowOfflineClicked);
  searchForm = $('#searchForm');
  searchForm.on('input', onSearchInputChange);
}

$(document).ready(function() {
  online = [];
  offline = [];
  prepareUI();
  // Retrieving info about list of usernames.
  channels.forEach(function(channelName, index) {
    retrieveStream(channelName)
      .done(function(data) { 
        onStreamCallback(data, index);
        getChannelInfo(channelName)
          .done(function(data) {
            onChannelCallback(data, index);
          })
          .fail(onRequestFail);
      })
      .fail(onRequestFail);
  });
});
            
          
!
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.

Console