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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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-fluid">
<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand purple" href="#">TwitchTV API</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="navbar-collapse">
      
      <form class="navbar-form navbar-right">
        <div class="input-group text-center">
      <input type="text" id="searchbox" class="form-control" placeholder="Search user...">
      <span class="input-group-btn">
        <button id="searchbutton" class="btn btn-default" type="button"><span class="glyphicon glyphicon-search"></span></button>
      </span>
    </div>    
      </form> 
      
      
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
<div class="row">  
  <div class=" col-md-3 col-xs-4">
  </div>
  <div class=" col-md-3 col-xs-4 select active showAll">
                        <a href="#" class="select active showAll"><button class="btn btn-default active"><i class="fa fa-caret-square-o-right fa-2x">All </i></button></a>
                        </div>
                   
					<div class=" col-md-3 col-xs-4">
                        <a href="#" class=" showOnline"><button class="btn btn-success"><span><i class="fa fa-bullseye fa-2x"> Online</i></span></button></a>
                        </div>
						
                    <div class="col-md-3 col-xs-4">
                        <a href="#" class=" showOffline"><button class="btn  btn-danger"><span><i class="fa fa-close fa-2x"> Offline</i></span></button></a>
                        </div>
                    
                  
			
  </div>
 
  <div class="results col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
  </div>
</div>
  <footer>
    <div class="row">
      <div class="col-xs-12 text-center copyright">
        <p>&copy 2017 Alexandru Marian  Inspired from <a href="https://www.freecodecamp.com/forkerino"target="_blank">Pieter Stokkink</a></p>
        </div>
      
</footer>
    
</div>
            
          
!
            
              body {
  padding-top: 60px;
  background-image: url("http://www.tothenew.com/blog/wp-content/uploads/2015/05/online-streaming.jpg");
  font-family: Verdana, Geneva, sans-serif; 
}
.purple {
  color: #565859 !important;
  text-shadow: 0 0 1px #6441A4; 
  font-size: 24px;
}

ul.nav>li:hover, ul.nav>li.active {
  background-color: #F8F8F8 !important;
  height: 50px;
  border-bottom: 3px solid #565859;
  margin-bottom: 0px;
  box-sizing: border-box;
}

.navbar-nav>.active>a {
  background-color: transparent !important;
  color: #6441A4;
  font-weight: 600;
}

.item {
  margin: 10px;
  padding: 5px;
  background-color: white;
  border-radius: 5px;
  min-width: 200px;
}

.item p {
  padding-top: 5px;
  margin: 0;
  
}

.user {
  font-weight: bold;
  font-size: 16px;
}

.game {
  font-size: 14px;
  font-style: italic;
  font-weight: 500;
}


.item a{
  text-decoration: none;
  color: black;
}

.item img {
  height: 100px;
  width: 100px;
}

.status.offline {
  color: red;
  font-weight: 600;
  background-color: white;
  padding: 5px;
  border-radius: 3px;
  border: 2px solid #6441A4;
}

.status.online {
  color: green;
  font-weight: 600;
  background-color: white;
  padding: 5px;
  border-radius: 3px;
  border: 2px solid #6441A4;
}

footer {
  background-color:black;
  color:white;
  text-align:center;
  position: relative;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 1rem;
}
            
          
!
            
              function getData(users, endpoint, state) {
  users.forEach(function(user){
    $.getJSON(endpoint + "streams/" + user + "?callback=?", function(json){
      var online=0;
      var exist=0;
      var url="https://www.twitch.tv/";
      var game="";
      var userIcon = "https://upload.wikimedia.org/wikipedia/en/b/b1/Portrait_placeholder.png"; 

      if (json.stream !== null) { // user online
        exist=1;
        online=1;
        game= json.stream.game;
        url += user;
      }
      $.getJSON(endpoint + "channels/" + user + "?callback=?", function(json){
        if (json.status === 404) {
          exist=0;
          url = "#";
        } else {
          exist = 1;
          url+= user;
          userIcon = json.logo !== undefined ? json.logo : userIcon;
        }
        
        showData(exist, online, user, game, url, userIcon, state);
      });
  });
});
}

function showData(exist, online, user, game, url, userIcon, state) {
  var html="";
  if (exist === 0) {
    console.log(userIcon);
    html += '<div class="row item offline"><img class="img-rounded" src="' + userIcon + '"><p><span class="user">' + user + '</span> doesn\'t exist</p></div>';
  } else if (online===0) {
    html += '<div class="row item offline"><span class="status pull-right offline">Offline</span><a href="' + url + '" target="_blank"><img class="img-rounded" src="' + userIcon + '"><p class="user">' + user + '</p></a></div>';
  } else {
    html += '<div class="row item online"><span class="status pull-right online">Online</span><a href="' + url + '" target="_blank"><img class="img-rounded" src="' + userIcon + '"><p class="user">' + user + '<span class="game"> is currently playing: ' + game + '<span></p></a></div>';
  }
  online === 1 ? $(".results").prepend(html) : $(".results").append(html);
   
  if (state === "All") {
    $(".online, .offline").removeClass("hidden");
  } else if (state === "Online") {
    $(".online").removeClass("hidden");
    $(".offline").addClass("hidden");
  } else {
    $(".offline").removeClass("hidden");
    $(".online").addClass("hidden");
  }

};

$(document).ready(function(){
  var users = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "habathcx", "RobotCaleb", "noobs2ninjas","dreamhackhs","netherrealm","comster404 ","brunofin"];
  var endpoint = "https://wind-bow.gomix.me/twitch-api/"; 
  var state="All";
  
  getData(users, endpoint, state);
  
  $(".select").click(function(){
    var self= this;
    $(".select").parent().removeClass("active");
    $(this).parent().addClass("active");
    if (state === "search"){ // if returning from a search to other page/selection. 
      $(".results").html("");
      $("#searchbox").val("");
      state = $(self).text();
      console.log(state);
      getData(users, endpoint, state);
    } else {
      state = $(self).text();
      console.log(state);
       if (state === "All") {
          $(".online, .offline").removeClass("hidden");
        } else if (state === "Online") {
          $(".online").removeClass("hidden");
          $(".offline").addClass("hidden");
        } else {
          $(".offline").removeClass("hidden");
          $(".online").addClass("hidden");
        }
    }

    
    
  });
  
  $('.select').click(function(){ $('.navbar-collapse').collapse('hide')});

  $("#searchbox").keypress(function (e) {
    if (e.which == 13) {
      $(".results").html("");
      getData([$("#searchbox").val()], endpoint);
      state = "search";
      $(".select").parent().removeClass("active");
    }
  });
  
  $("#searchbutton").on("click",  function(){
    $(".results").html("");
    getData([$("#searchbox").val()], endpoint);
    state = "search";
    $(".select").parent().removeClass("active");
  });
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console