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" style="margin-top:25px;margin-bottom:25px;">
  <div id="header" class="col-md-8 col-md-offset-2 text-center"><p>twitch 
    <i class="fa fa-twitch fa-2x"></i>stream</p>
  </div>
  <div class="col-md-8 col-md-offset-2">
    <div role="tabpanel">
      <!-- Nav tabs -->
      <div class="row">
        <div class="col-md-12">
          <ul id="navtabs" class="nav nav-tabs" role="tablist">

            <li id="li-all"role="presentation" class="active"><a href="#all" aria-controls="all" role="tab" data-toggle="tab">All</a></li>
            <li id="li-online"role="presentation"><a href="#online" aria-controls="online" role="tab" data-toggle="tab">Online</a></li>
            <li id="li-offline"role="presentation"><a href="#offline" aria-controls="offline" role="tab" data-toggle="tab">Offline</a></li>
          </ul>
          <div id="searchbar" class="row text-center">
            <div id="icon-container" class="col-xs-1">
              <i class="fa fa-search"></i>
            </div>
            <div id="input-container" class="col-xs-11">
              <input id="input" type="text" style="width:100%" placeholder="search" />
            </div>
          </div>
        </div>
      </div>

      <!-- Tab panes -->
      <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="all"></div>
        <div role="tabpanel" class="tab-pane" id="online"></div>
        <div role="tabpanel" class="tab-pane" id="offline"></div>
      </div>

    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  background-color: #F2F1EF;
}

#header {
  margin-bottom: 20px;
}

#header > p > i {
  color: #6541A5;
  font-weight: bolder;
}

#header > p {
  color: black;
  font-weight: bolder;
  font-size: 3em;
}

/* Tab Styles */

li {
  text-align: center;
  border: 2px solid #674172;
  border-left: 1px solid #674172;
  border-right: 1px solid #674172;
  background-color: #BE90D4;
}

#li-all {
  width: 30%;
  border-left: 2px solid #674172;
}

#li-online,
#li-offline {
  width: 35%;
}

#li-offline {
  border-right: 2px solid #674172;
}

.nav-tabs > li > a {
  color: white;
  background-color: transparent !important;
  border-radius: 0;
}

.nav-tabs>li>a:hover {
  border-color: transparent;
}

.nav-tabs>li.active {
  background-color: #DCC6E0;
}

.nav-tabs>li.active>a,
.nav-tabs>li.active>a:focus,
.nav-tabs>li.active>a:hover {
  border: 1px solid transparent;
  color: #674172;
}

.tab-content {
  border: 2px solid #674172;
  border-top:.5px solid #ccc;
}
/* tab styles END */
/* Searchbar styles */

#searchbar {
  padding: 8px;
  border: 2px solid #674172;
  border-top: 1px solid #ccc;
  width: 100%;
  margin: 0 auto;
  background-color: white;
}

#icon-container,
#input-container {
  padding: 0;
}

#icon-container {
  color: #DADFE1;
}

#searchbar input {
  border: 0;
}

input:focus,
input:active {
  outline: 0;
}
/* searchbar styles END */
/* user status styles */

div.user-status {
  padding: 15px;
  background-color: white;
}

.user-icon {
  float: left;
  border-radius: 50%;
  height: 50px;
}

.fa-check {
  color: #90C695;
}

.fa-exclamation {
  color: #E74C3C;
}

.user-info {
  display: inline-block;
  margin-top: 5px;
  margin-left: 20px;
  font-size: 1.5em;
  height: 3.5em;
  width: 400px;
  overflow: hidden;
}

.online-status {
  float: right;
  margin-top: 0px;
  margin-right: 20px;
}

.hidden {
  display: none !important;
}
/* user status styles END */

@media (max-width: 992px) {
  .user-info {
    width: 300px;
  }
}

@media (max-width: 497px) {
  .desc {
    display: none !important;
  }
  .user-info {
    width: 175px;
    margin-left: 10px;
  }
}

@media (max-width: 359px) {
  .user-info {
    display: none !important;
  }
  .user-icon {
    margin: 0 auto;
    height: 100px;
  }
  .online-status {
    font-size: 6em;
  }
  .user-status {
    height: 123px;
  }
}
              
            
!

JS

              
                // Array of twitch store value objects
var twitchObjs = [];

// Array of viewers loaded to the stream
var loaded = [];

// var client_id = 'p6x7jmjkng0pfbbr0easu8nd9543wx';

// Array of twitch usernames
var usernames = ["freecodecamp",
  "storbeck",
  "knowledge09",
  "terakilobyte",
  "ogamingsc2",
  "LIRIK",
  "RobotCaleb",
  "riotgames",
  "roomonfire",
  "thomasballinger",
  "syndicate",
  "noobs2ninjas"
];

// Twitch urls
var userUrl = 'https://wind-bow.glitch.me/twitch-api/users/';
var streamUrl = 'https://wind-bow.glitch.me/twitch-api/streams/';

// Array of twitch username ajax calls
var tViewers = usernames.map(function(username){
    return new Promise((resolve, reject) => {
      $.getJSON(userUrl + username, (data) => resolve(data)); 
    });
});

// Array of twitch stream ajax calls
var tStreams = usernames.map(function(username){
  return new Promise((resolve, reject) => {
      $.getJSON(streamUrl + username, (data) => resolve(data));
  });
});

// Activates bootstrap tabs
$('#navtabs a').click(function(e) {
  e.preventDefault();
  $(this).tab('show');
});

function clearUserData() {
  $("#all").empty();
  $("#online").empty();
  $("#offline").empty();
};

function clearLoadedArray() {
  loaded = [];
};

// Search feature
function search() {
  clearLoadedArray();
  clearUserData();
  var searchMatch = [];
  var matchedObjs = [];
  // Will only run if there is input
  if ($('#input').val) {
    var str = $('#input').val();

    if (str.length === 0) {
      twitchObjs.forEach(function(obj) {
        loaded.push(obj.template);
      });
      filterUserObjs('all', twitchObjs);
      filterUserObjs('online', twitchObjs);
      filterUserObjs('offline', twitchObjs);
    } else {
      usernames.forEach(function(name) {
        var rex = RegExp(str, "g");
        if (name.match(rex) !== null) searchMatch.push(name);
      })

      searchMatch.forEach(function(name) {
        twitchObjs.forEach(function(obj) {
          if (name === obj.name) matchedObjs.push(obj);
        });
      });
      filterUserObjs('all', matchedObjs);
      filterUserObjs('online', matchedObjs);
      filterUserObjs('offline', matchedObjs);
    }
  };
};

// Cue search feature on keyup
$("input").keyup(function(e) {
  search();
});

// Agregate user data
function createUserObjs(view, stream, usernames) {
  var objArray = [];
  usernames.forEach((user, i) => {
    var objStore = {
      logo: '',
      bio: '',
      name: '',
      displayname: '',
      icon: '',
      template: ""
    };

    // Fill logo with placeholder if not available
    objStore.logo = view[i].logo === null ?
      'http://placehold.it/50x50' :
      view[i].logo;

    // Fill bio with nothing iv not available
    objStore.bio = view[i].bio === null ?
      '' : view[i].bio;

    objStore.name = view[i].name;
    objStore.displayname = view[i].display_name;
    // Replace status icon with check if streaming
    objStore.icon = stream[i].stream === null ?
      'exclamation' : 'check';

    objStore.template =
      "<div class='user-status'><img class='user-icon'src='" +
      objStore.logo + "'/><h3 class='user-info'>" +
      objStore.displayname + "<br><small class='desc'>" + objStore.bio +
      "</small></h3><i class='fa fa-" +
      objStore.icon + " fa-2x online-status'></div>";

    // Push to twitch objs
    twitchObjs.push(objStore);
  });
};

// Filter user objects then load
function filterUserObjs(filter, arr) {
  clearLoadedArray();
  switch (filter) {
    case 'all':
      arr.forEach(function(obj) {
        loaded.push(obj.template);
      });
      loaded.forEach(function(template) {
        $('div#all').append(template);
      });
      break;

    case 'online':
      arr.forEach(function(obj) {
        if (obj.icon === 'check') loaded.push(obj.template);
      });
      loaded.forEach(function(template) {
        $('div#online').append(template);
      });

      break;

    case 'offline':
      arr.forEach(function(obj) {
        if (obj.icon === 'exclamation') {
          loaded.push(obj.template);
        }
      });
      loaded.forEach(function(template) {
        $('div#offline').append(template);
      });

      break;
    default:
      arr.forEach(function(obj) {
        loaded.push(obj.template);
      });
      loaded.forEach(function(template) {
        $('div#all').append(template);
      });
      break;
  }
};

function getUserData() {
  Promise.all(tViewers)
    .then(users => {
      var userObj = [];
      users.forEach(user => { userObj.push(user) });
      Promise.all(tStreams)
        .then(streams => {
          var streamsObj = []
          streams.forEach(stream => { streamsObj.push(stream) });
          createUserObjs(userObj, streamsObj, usernames);
          filterUserObjs('all', twitchObjs);
          filterUserObjs('online', twitchObjs);
          filterUserObjs('offline', twitchObjs);
        })
    })
}

getUserData();
              
            
!
999px

Console