css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <body>
  <div class="container">
    <div class="banner row">
      <div class="col-md-10">
        <h1>Twitch Streamers</h1>
      </div>
      <div class="button-group col-md-2">
        <button class="slide all" onclick="showAll()"><i class="fa fa-circle" aria-hidden="true"></i><span class="rollout">&nbsp;&nbsp;All</span></button>

        <button class="slidein online" onclick="showOnlyOnline()"><i class="fa fa-circle" aria-hidden="true"></i><span class="rollout">&nbsp;&nbsp;Online</span></button>

        <button class="slidein offline" onclick="showOnlyOffline()"><i class="fa fa-circle" aria-hidden="true"></i><span class="rollout">&nbsp;&nbsp;Offline</span></button>
      </div>
    </div>
    <div class="row main">
      <!--rows with twitch user information inserts here -->
    </div>
    <div class="foot"></div>

  </div>
</body>
            
          
!
            
              a,
a:focus,
a:active {
  color: inherit;
  text-decoration: none;
}

a:hover {color: inherit;}

button:focus {outline:0 !important;}

.all {
  color: #FFF;
  background-color: #BABABA;
}

.banner {
  border-top-left-radius: 1em;
  border-top-right-radius: 1em;
  background: #223843;
  padding: 10px 0px;
}

body {margin: 10px auto 10px auto;}

button > i {text-align: left;}

.button-group {
  margin: 0 0;
  padding: 0;
}

.button-group button {
  border: none;
  clear: both;
  height: 24px;
  float: right;
  margin: 3px 0;
  overflow: hidden;
  white-space: nowrap;
  width: 25px;
  -webkit-transition: width 2s;
  transition: width .5s;
}

.button-group button:hover {width: 75px;}

.container {width: 65%;}

.fa {font-size: 14px !important;}

.foot {
  border-bottom-right-radius: 1em;
  border-bottom-left-radius: 1em;
  background-color: #223843;
  height: 20px;
}

h1 {
  color: #FFF;
  font-family: 'Anton', sans-serif;
  padding: 40px 0 0 40px;
  letter-spacing: 1px;
  margin: 0 0 -10px -10px;
  font-size: 50px;
  font-weight: 700;
}

.offline {
  color: #458DA8;
  background-color: #BABABA;
}

.online {
  color: #F9E354;
  background-color: #BABABA;
  -webkit-transition: width 2s;
  transition: width .5s;
}

.rollout {
  color: #223843;
  font-weight: 700;
}

.row {margin: auto;}

.userimg {
  border: 1px solid #003247;
  height: 50px;
  width: 50px;
}

.user-log {
  align-items: center;
  background-color: #458DA8;
  display: flex;
  margin: 2px auto;
  padding: 3px;
  text-align: center;
}

.user-log p {
  color: #223843;
  font-size: 16px;
  margin: auto 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


            
          
!
            
              /** 
When designing this I quickly realized midway through that I really should have used arrays to hold data and then used the arrays to create the new rows of content.  By producing divs one at a time, it made the code less flexible, and forced me to use many workarounds. 
**/

var names = [
  "ogamingsc2",
  "brunofin",
  "freecodecamp",
  "dreamhackcs",
  "terakilobyte",
  "habathcx",
  "robotcaleb",
  "oh_snaaap",
  "noobs2ninjas",
  "cretetion",
  "dreamhack"
];

names.sort();

function getUserInfo() {
  for (var i = 0; i < names.length; i++) {
    (function(i) {
      var url1 = $.getJSON(
        "https://api.twitch.tv/kraken/users/" +
          names[i] +
          "?client_id=sljb4hq5al8yqbux7bgwgxndkxhog6&callback=?"
      );
      var url2 = $.getJSON(
        "https://api.twitch.tv/kraken/streams/" +
          names[i] +
          "?client_id=sljb4hq5al8yqbux7bgwgxndkxhog6&callback=?"
      );
      var url3 = $.getJSON(
        "https://api.twitch.tv/kraken/channels/" +
          names[i] +
          "?client_id=sljb4hq5al8yqbux7bgwgxndkxhog6&callback=?"
      );

      $.when(url1, url2, url3)
        .done(function(data, data2, data3) {
          tempname = data[0]["name"];
          tempdisplayname = data[0]["display_name"];
          tempimg = data[0]["logo"];
          temponline = data2[0]["stream"];
          channelURL = data3[0]["url"];

          //checks and assigns a logo if missing
          if (tempimg == null) {
            tempimg =
              "https://res.cloudinary.com/burns/image/upload/v1488303396/no-logo_ih7tqk.gif";
          }

          //checks to see if user is online and grabs status or assigns offline text
          if (temponline) {
            tempgame = data2[0]["stream"]["channel"]["game"];
            tempstatus = data2[0]["stream"]["channel"]["status"];
            tempfinalstatus = tempgame + " - " + tempstatus;
          } else {
            tempfinalstatus = "Offline";
          }

          //adds new HTML to page
          addContentRows();
        })
        .fail(function(jqxhr, textStatus, error) {
          //Assigns values when JSON fails due to account being closed
          tempname = names[i].toLowerCase();
          tempdisplayname = names[i];
          tempimg =
            "https://res.cloudinary.com/burns/image/upload/v1488303396/no-logo_ih7tqk.gif";
          tempfinalstatus = "Account Closed";
          addContentRows();
        }); //endJSON
    })(i);
  } //end of for loop
} //end function

function addContentRows() {
  //updates divs with information - PS This is the ugliest code I've ever seen.  I apologize.
  $(".main").append(
    '<div id="' +
      tempname +
      '" class="user-log"><div class="col-md-2 userAvatar"><img class="userimg imgcircle" src="' +
      tempimg +
      '"></div><div class="col-md-4"><p>' +
      tempdisplayname +
      '</p></div><div class="col-md-6"><p class="final-status"><a class="' +
      tempname +
      '" target="_blank" href=' +
      channelURL +
      ">" +
      tempfinalstatus +
      "</a></p></div></div>"
  );

  if (tempfinalstatus != "Offline") {
    if (tempfinalstatus != "Account Closed") {
      $("#" + tempname).css("background", "#F9E354");
    }
  }
} //end of addContentRows

// *** Button Functions ***

function showAll() {
  for (var x = 0; x < names.length; x++) {
    var name1 = names[x];
    $("#" + name1).css("display", "");
  }
} //end of showAll

function showOnlyOnline() {
  showAll();
  for (var x = 0; x < names.length; x++) {
    var name1 = names[x];
    var text = $("." + name1).html();

    if (text == "Offline" || text == "Account Closed") {
      $("#" + name1).css("display", "none");
    }
  }
} //end of showOnlyOnline

function showOnlyOffline() {
  showAll();
  for (var x = 0; x < names.length; x++) {
    var name1 = names[x];
    var text = $("." + name1).html();

    if (text != "Offline") {
      $("#" + name1).css("display", "none");
    }
  }
}

// *** End of Button functions ***

$(function() {
  getUserInfo();
});

            
          
!
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.
Loading ..................

Console