cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-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">
  <nav> 
<ul class="menu">
  <li id="all">All<div class="dot all"></div></li>
  <li id="online">Online<div class="dot online hidden"></div></li>
  <li id="offline">Offline<div class="dot offline hidden"></div></li>
</ul>
  </nav>
  <section class="row search">
  <form class="form-horizontal" role="form">
    <span id="glass" class="glyphicon glyphicon-search"></span><input type="text" class="form-control input-sm" id="q" 
           placeholder="Search">
    
  </form>  
  </section>
  <section class="streams">
 </section>
</div>
            
          
!
            
              body {
  background-color: #ECFFEC;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
}
.container {
  width: 300px;
  margin: auto;
  background: #fefefe;
  margin-top: 10px;
  padding: 0;
  border: 1px solid #ddd;
}
nav {
  width: 100%;
  margin: 0;
  color: white;
}
nav ul.menu  {
  display: inline-block;
  margin: -1px -1px 15px -1px;
}

nav ul li {
  float: left;
  width: 99px;  
}
nav ul.menu li {
  background-color: #5BB146;
  padding: 15px 0 15px 0;
  text-align: center;
  margin-left: 1px;
  cursor: pointer; 
  cursor: hand;
  width: 99px;
  height: 50px;
}

.dot {
  background-color: #5BB146;
  width: 30px;
  height: 30px;
  margin-top: -6px;
  margin-right: auto;
  margin-left: auto;
  border-radius: 15px;
}
.row {
  margin: 0;
}
.search {
  border-bottom: 1px solid #ddd;
  padding-bottom: 15px;
}
.stream {
  padding: 0 0 5px 0;;
  border-bottom: 1px solid #ddd;
}
.stream div, .stream a {
  padding: 5px 0;
  color: #5BB146;
}
.stream .icon img{
  width: 44px;
  border-radius: 22px;
  margin-left: 4px;
}
.stream .name {
  line-height: 10px;
  padding-left: 5px;
}
.stream .subject {
  font-size: 14px;
  color: #aaa;
  line-height: 10px;
  padding-left: 5px;
}
.stream .online .glyphicon-remove {
  color: #DF425F;
}

#q {
  padding-left: 30px;
  margin-left: 5px;
  margin-right: 5px;
  width: 290px
}
#glass {
  position: relative;
  float: left;
  opacity: 0.4;
  padding-top: 5px;
  padding-left: 14px;
  margin-bottom: -46px;
  display: inline;
}

            
          
!
            
              var myData = [];
var myFilter = 'all';
var myFilterText = '';
var myUrl = 'https://api.twitch.tv/kraken';
var defaultLogo = 'http://www-cdn.jtvnw.net/images/xarth/form/upload_placeholder.png';
var myAccounts = ["freecodecamp", "storbeck", "terakilobyte", "yaraskygaming","RobotCaleb","medrybw","thomasballinger","noobs2ninjas","beohoff"];

$(document).ready(function() {
  
  $('nav ul.menu li').click(function(event) {
     var labelx = event.target.id;
     $(".dot").removeClass("hidden");
    $(".dot").addClass("hidden"); 
    $("."+labelx).removeClass("hidden");    
    setFilter(labelx);
  });
  
  $('#q').on('input',function(e){
     setFilterText(e.target.value);
  });
  
  reload();
  
});

function setFilter(sel) {
  myFilter = sel;
  show();
};
function setFilterText(txt) {
  myFilterText = txt;
  show();
};

function reload() {
  myData = [];
  myAccounts.forEach( function(account) {
    var userdata = {};
    $.ajax({
      type: 'GET',   
      url: myUrl+'/users/'+account,
      crossDomain: true,
   // beforeSend: function(xhr){ xhr.withCredentials = true; },
      contentType: "application/vnd.twitchtv.v3; charset=utf-8",               
      success: function (data) {
          userdata = data;
          if (!userdata.logo) {
            userdata.logo = defaultLogo;
          }
          $.ajax({
            type: 'GET',   
            url: myUrl+'/streams/'+account,
            crossDomain: true,
   // beforeSend: function(xhr){ xhr.withCredentials = true; },
            contentType: "application/vnd.twitchtv.v3; charset=utf-8",               
            success: function (data) {
              if (data.stream == null) {
                userdata.online = false;
              }
              else {
                userdata.online = true;
                userdata.status = data.stream.channel.status.substring(0,28)+(data.stream.channel.status.length > 28? '...':'');
                userdata.url = data.stream.channel.url;
              }
              myData.push(userdata);
            },
            error: function(err) {
               userdata.online = false;
               myData.push(userdata);             
            },
            dataType: 'json'
          });
      },
      dataType: 'json'
    }).then(show());
  });
  setTimeout(reload, 30000); // reload every 30 secs
};

function show() {
  if (myData == null || myData.length < myAccounts.length) {
    setTimeout(show, 300);
  }
  else {
    var myHtml = '';
    myData.filter(function(userdata) {
      return (myFilter === 'all' ||
               (myFilter === 'online' && userdata.online) || 
               (myFilter === 'offline' && !userdata.online)) &&
             (myFilterText.length === 0 ||
                userdata.display_name.toUpperCase().indexOf(myFilterText.toUpperCase()) >= 0 )
      })
    .sort(function(data1, data2) {
      return data1.display_name.toUpperCase() >= data2.display_name.toUpperCase();
    })
    .forEach(function (userdata) {
        var snippet = '<div class="row stream">';
        snippet += '<div class="col-xs-2 icon"><img src="'+userdata.logo+'"></img></div>';
        snippet += '<div class="col-xs-9">';
        if (userdata.url) {
          snippet += '<a href="'+userdata.url+'">';  
        }
        snippet += '<span class="name">'+userdata.display_name+'</span>';
        if (userdata.url) {
          snippet += '</a>';  
        }
        snippet += '<br/>';
        if (userdata.status) {
           snippet += '<span class="subject">'+userdata.status+'</span>';
        }
        snippet += '</div><div class="col-xs-1 online">';
        if (userdata.online) {
            snippet += '<span class="glyphicon glyphicon-ok"></span>';
        }
        else {
            snippet += '<span class="glyphicon glyphicon-remove"></span>';
        }
        snippet +='</div></div></div>';
        myHtml += snippet;
    });
    $('section.streams').html(myHtml);
  }
 
};
            
          
!
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