123

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.

            
              

<div class="container text-center">
  <div class="row buttons">
    <div class="col-md-4">
      <button class="allUsers"><h2>All</button>
      
    </div>
    <div class="col-md-4">
      <button class="onlineNow"><h2>Online</h2></button>
      
    </div>
    <div class="col-md-4">
      <button class="offlineNow"><h2>Offline</h2></button>
    </div>
   
  </div>

</div>


<div class="container">
  <div class="text-primary" id="twitch">
    
  </div>
 

</div>
            
          
!
            
              

body {
  width:100%;
  background: #aaa;
  font-size: 22px;
}
  h1 {
  font-size:2em;  
}
.buttons, button {
  padding: 10px;
  margin:40px auto 10px auto;
  width: 80%;
  
}
.streamer p {
  font-size: .5em;
}

#twitch {
  background:#bbb;
  width: 70%;
  margin:auto;
  padding: 10px;
  border-bottom: 40px solid grey;
  transition:all .5s;
}

.game {
  float: right;
  width: 50%;
  display:inline-block;
  font-size: .7em;
}
.streamer {
  font-size:1.2em;
  font-weight:bold;
  padding: 15px;
  margin:0;
  
 
}
.link {
  width:50%;
  margin:0;
  display:inline-block;
  
}

.allUsers {
  background: lightblue;
  height:100%;
  border: 2px solid darkblue;
  transition: all .5s;
}

.onlineNow {
  background: lightgray;
  height:100%;
  border: 2px solid darkblue;
  transition: all .5s;
}

.offlineNow {
  background: lightgray;
  height:100%;
  border: 2px solid darkblue;
  transition: all .5s;
}


            
          
!
            
              var toggleMe;

var users = ["freecodecamp", "storbeck", "terakilobyte", "habathcx", "RobotCaleb", "thomasballinger", "noobs2ninjas", "beohoff", "brunofin", "comster404", "callofduty", "ESL_SC2", "pax", "beyondthesummit", "esl_dota2"];
//defines list of users to pull from
var populate = function(data) { //this is the callback funciton that runs when the getJSON api request is called
  var status = setStatus(data);
  var user = setUser(data);
  var url = "https://twitch.tv/";
  //displayGame(data);

  $("#twitch").append("<div id='" + user + "' class='notstreaming'><div class='streamer'><div class='link'> <a href='" + url + user + "' target='_blank'>" + user + "</a><p>" + status + "</p> </div></div></div>");
  isOnline(data);
  displayGame(data);

}

var setStatus = function(data) { //set the status of the current user
  if (data.hasOwnProperty("_links")) { //checks to see if the account is still active
    if (data.stream) { //checks to see if the user is streaming
      return data.stream.channel.status; //displays current game
    } else {
      return "User Offline";
    }
  } else {
    return "Account Deleted";
  }
}

var setUser = function(data) {
  if (data.hasOwnProperty("_links")) {
    
    return data["_links"]["channel"].match(/[^/]+$/g);
  } else {
    return data.message.match(/\w+(?=')/g);
  }
}

var isOnline = function(data) {
  userID = '#' + setUser(data);
  var targetDiv = userID + " .streamer";
  
 if (data.stream.hasOwnProperty("game")) {
    $(userID).css("background", "lightgreen");
    $(userID).removeClass("notstreaming").addClass("streaming");
    $(targetDiv).append("<div class='game'></div>");
  }
  
//var toggle;     
};

var displayGame = function(data) {
  //console.log("Display Game Goes");
  var targetDiv = userID + " .game"
  try { if (data.stream.hasOwnProperty("game")) {
    $(targetDiv).append(data.stream.game);
  };
      } catch(err) { //console.log("displayGame: " + err);
                   }     
};
$(function() {
  $("#twitch").html("<h1>Twitch Streamers</h1>");
  for (i = 0; i < users.length; i++) {
    var api1 = "https://api.twitch.tv/kraken/streams/";
    var api2 = "?callback=?";
    var api3 = "https://api.twitch.tv/kraken/user/";
    $.getJSON(api1 + users[i] + api2, populate)
  };
});

$(".allUsers").click(function() {
  $(".streaming").css("display", "block");
  $(".notstreaming").css("display", "block");
  $(".offlineNow").css("background","lightgrey");
  $(".allUsers").css("background","lightblue");
  $(".onlineNow").css("background","lightgrey");
});

$(".onlineNow").click(function() {
  $(".streaming").css("display","block");
  $(".onlineNow").css("background", "lightblue");
  $(".allUsers").css("background", "lightgrey");
  $(".notstreaming").css("display", "none");
  $(".offlineNow").css("background","lightgrey");
});

$(".offlineNow").click(function() {
  $(".streaming").css("display","none");
  $(".notstreaming").css("display", "block");
  $(".onlineNow").css("background", "lightgrey");
  $(".allUsers").css("background", "lightgrey");
  $(".offlineNow").css("background","lightblue");
})

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

Console