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.

Quick-add: + add another resource

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.

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.

            
              <head>
    <link rel="shortcut icon" href="">
    <script src="jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="bootstrap.css">
    <link rel="stylesheet" type="text/css" href="twitch.css"> 
    <link href="https://fonts.googleapis.com/css?family=Passion+One" rel='stylesheet' type='text/css'>
    <script src="twitch.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Twitch Streamers</title>
</head>
<body>
<div class="container">
  <div class="titleBox"><img src="http://www.richardkeightley.com/Images/twitch_logo.png" alt="Twitch logo" style="margin-top: -6px;"> Streamers
    <div id="buttons">
     <span class="btn" onclick="searchTwitch()">All</span>
     <span class="btn" onclick="twitchOn()">Online</span>
     <span class="btn" onclick="twitchOff()">Offline</span>
     <span class="btn" onclick="removeAll()">Clear</span></div>
  </div>
  </div> <!-- end titleBox -->  
</div> <!-- end container -->

  <div id="main"></div>
</body>



            
          
!
            
              html {
  height: 100%;
}
body {
  background: black; /* For browsers that do not support gradients */
  background: -webkit-radial-gradient(#444, black); /* Safari 5.1 to 6.0 */
  background: -o-radial-gradient(#444, black); /* For Opera 11.6 to 12.0 */
  background: -moz-radial-gradient(#444, black); /* For Firefox 3.6 to 15 */
  background: radial-gradient(#DDD, gray);
}

.titleBox {
  z-index: 0;
  margin: 10px;
  font-family: 'Passion One', cursive;
  font-size: 2.75em;
  width: 600px;
  height: 140px;
  border-radius: 10px;
  background-color: #461b7e;
  position: absolute;
left: 50%;
  color: white;
  transform: translate(-50%, 0%);
}

.container {
  text-align: center;
  font-size: 24px;  
  color: blue;
}

#buttons{
  margin-top: -30px;
}

.btn {
  color: lightgray;
  background-color: black;
  width: 80px;
  font-size: 18px;
}

#online, #offline, #nope {
  background-color: lightgreen;
  position: relative;
  left: 50%;
  transform: translate(-50%, 220%);
  height: 68px;
  width: 600px;
  margin: 8px;
  border-radius: 8px;
  padding: 4px;
  line-height: 1.25;
}

#offline {
    background-color: lightgray;
}

#nope {
    background-color: gray;
}

.text_on, .text_off, .text_nope {
  position: relative;
  margin-left: 3.5em;
  font-family: Arial;
  color: black;
  font-size: 20px;
  transform: translate(0,-110%);
  z-index: 1;
  }

.text_off {
  transform: translate(0,50%);
}

.text_nope {
  transform: translate(0,50%);
}

a, a:visited, a:link {
  color: white;
  text-decoration: none;
}

.logo {
  position: relative;
  height: 60px;
  width: 60px;
  bottom: 0px;
  border-radius: 8px;
}
            
          
!
            
               var users = ["lirik", "ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "guesswho2"];
var i=0;
// FOR THE REDESIGN
// 1. call twitch api w/ the user information
// 2. load the retrieved information into 3 arrays:
// ONLINE, OFFLINE, and NOPE
// 3. cycle through the arrays and dynamically create DIVs
// for each element, color coded by class
// 4. to delete content: clear the requisite array
// and call the display function again.

$(document).ready(function(){
   i=0;
  });

function searchTwitch() {
   for (i=users.length-1; i>=0; i--){
      var user =users[i];
      $.ajax({
      type: "GET",
      url: "https://api.twitch.tv/kraken/streams/" + user + "?client_id=MyClientID?callback=?",             
        headers: {"Client-ID": "dkrw6q6rrayh4iqqg0e1vzxzmfr06ak"}
      })
        .done(update)
        .fail(handleError);
      }
}

// user exists
function update(){
  var userData = data;

       // user exists OFFLINE
       var long = userData._links.self;
       var name = long.split("/");
       var userName = name[5];
       
       if(userData.hasOwnProperty("stream")){
                    if(userData.stream === null)
       {

         $('<div id="offline" ></div>').insertAfter('#main');   
         document.getElementById('offline').innerHTML = '<div class="text_off">' + userName + ' is offline.</div>'; 
         }
         
        // user exists ONLINE
        else 
         {   
        $('<div id="online"></div>').insertAfter('#main');
       document.getElementById('online').innerHTML = '<a href="https://www.twitch.tv/' + userData.stream.channel.name + '" target="_blank"><img src=' + userData.stream.channel.logo + ' class="logo"><div class="text_on">Watch ' + userData.stream.channel.display_name + ' play ' + userData.stream.channel.game + '!<br>Viewers: ' +  userData.stream.viewers + '</div></a>'; 
         }
       }
}

// user DOES NOT EXIST
function handleError(){
  $('<div id="nope"></div>').insertAfter('#main');
      document.getElementById('nope').innerHTML = '<div class="text_nope">' + data.responseJSON.message + '.</div>'; 
}

function removeAll(){ 
    var foundOff = document.getElementById("offline");
    var foundOn = document.getElementById("online");
    var foundNope = document.getElementById("nope");
    while(foundOff || foundOn || foundNope)
    {
        document.getElementById("offline").remove();
        document.getElementById("online").remove();
        document.getElementById("nope").remove();
    }
}

function removeOff(){
      var foundOff = document.getElementById("offline");
    var foundNope = document.getElementById("nope");
    while(foundOff ||  foundNope)
    {
        document.getElementById("offline").remove();
        document.getElementById("nope").remove();
    }
}

function removeOn(){
    var foundOn = document.getElementById("online");
    var foundNope = document.getElementById("nope");
    while( foundOn || foundNope)
    {
        document.getElementById("online").remove();
        document.getElementById("nope").remove();
    }
}

function twitchOn(){
  removeAll();
  searchTwitch();
  setTimeout(removeOff, 1000);
}

function twitchOff(){
  removeAll();
  searchTwitch();
  setTimeout(removeOn, 1000);
}
            
          
!
999px
Loading ..................

Console