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

            
                <!-- hyperlinks: target="_blank" for codepen.io -->
  <div class="h-100 d-flex justify-content-center align-content-between flex-wrap">
    <!-- top banner -->
    <div class="container text-center p-3 text-white w-100">
      <h1 class="text-orange">Your Twitch.tv</h1>
      <span><em>See all your favorite Twitch channels here!</em></span>
      <div class="row justify-content-center pt-3">
        <div class="col-12 col-sm-5 col-md-4 col-lg-3 text-center">
          <button id="refresh" type="button" class="btn btn-warning">Refresh</button>
        </div>
      </div>
      <p id="message" class="text-red pt-3">Loading...</p>
    </div>

    <!-- middle -->
    <div class="container mx-2">
      <div id="search-results" class="row list-group">
      </div>
    </div>

    <!-- footer -->
    <div class="container p-5 w-100">
      <p class="text-center text-white">Coded by <a class="text-orange" href="http://gregwong.me">Greg Wong</a></p>
    </div>
  </div>
            
          
!
            
              html, body {
  height: 100%;
  background-color: black;
}

.content-entry {
  background-color: #787878;
  padding-top: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgb(223,223,223);
  color: white;
}

.content-entry:focus, .content-entry:hover {
  background-color: lightgray;
  color: black;
}

.text-red {
  color: red;
}

.text-orange {
  color: #FF8C00;
}

            
          
!
            
              var users = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "brunofin", "comster404"];

function getJSONcallback(onSuccess, param){
  // onSuccess should take two parameters, json and param
  // return a function that only takes in one parameter, json
  return (function(json){
    onSuccess(json, param);
  });
}

$(document).ready(function() {
  // initialize page
  getStream();

  // add listeners
  $("button#refresh").click(function(){
    $("div#search-results").empty();
    $("p#message").text("Loading...");
    getStream();
  });
});

function getStream() {
  $.each(users, function(index, user){
    var url = "https://wind-bow.glitch.me/twitch-api/streams/" + user + "?callback=?";

    $.getJSON(url).done(getJSONcallback(getStreamDone, user)).fail(function(){
      $("p#message").text("Failed to make request. Try again later!");
    });
  });
}

function getStreamDone(json, user){
  $("p#message").text("");
  var stream = json.stream;
  if (stream == null){
    // check to see if user is offline, closed their account, or doesn't exist
    getChannel(user);
  }
  else { // found available stream
    var channel = stream.channel;

    var html = '<a href="' + channel.url + '" class="list-group-item content-entry container w-100" target="_blank"><div class="row w-100"><div class="col-3 col-md-2 my-auto text-center"><img class="rounded-circle" height="60" src="' + channel.logo + '" alt="" /><br><span><strong>' + channel.display_name +'</strong></span></div><div class="hidden-sm-down col-md-3 my-auto text-center"><img width="100%" src="' + stream.preview.medium + '" alt="" /> </div><div class="col-9 col-md-7 my-auto text-center text-success"><span>' + channel.status + '</span></div></div></a>';

    $("div#search-results").append(html);
  }
}

function getChannel(user){
  var url = "https://wind-bow.glitch.me/twitch-api/channels/" + user + "?callback=?";
  $.getJSON(url).done(getJSONcallback(getChannelDone, user)).fail(function(){
    $("p#message").text("Failed to make request. Try again later!");
  });
}

function getChannelDone(json, user) {
  var channel_url, channel_logo, display_name, message;
  var text_red = "";
  var outer = "div"; // use div if there is no valid link, i.e., if user has closed account or user not found
  if (json.error == null){
    // user is only offline

    display_name = json.display_name;
    channel_logo = json.logo;
    channel_url = json.url;
    message = "User is offline";
    outer = "a";
  }
  else if (json.error != null && json.status == 422) {
    // user has closed their account
    display_name = user;
    channel_logo = null;
    channel_url = "#";
    message = "User has closed their Twitch account";
    text_red = " text-red";
  }
  else if (json.error != null && json.status == 404) {
    // user not found
    display_name = user;
    channel_logo = null;
    channel_url = "#";
    message = "User doesn't exist!";
    text_red = " text-red";
  }

  if (channel_logo == null){
    channel_logo = "https://placehold.it/60x60";
  }

  var html = '<' + outer +' href="' + channel_url + '" class="list-group-item content-entry container w-100" target="_blank"><div class="row w-100"><div class="col-3 col-md-2 my-auto text-center"><img class="rounded-circle" height="60" src="' + channel_logo + '" alt="" /><br><span><strong>' + display_name +'</strong></span></div><div class="hidden-sm-down col-md-3 my-auto text-center"></div><div class="col-9 col-md-7 my-auto text-center' + text_red + '"><span>' + message + '</span></div></div></' + outer + '>';

  $("div#search-results").append(html);
}

$('div#search-results').on('click', 'a.content-entry',function(){
  // without this, the selected entry stays highlighted
  $(this).blur();
});

            
          
!
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