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.

            
              <head>
  <title></title>
</head>
<body>
  <div class="container">
    <div class="title">
      <h1>Twitch Status</h1>
      <div class="btn-group btn-group-sm" role="group">
        <button type="button" id="all-button" class="btn btn-primary active">All</button>
        <button type="button" id="online-button" class="btn btn-primary">Online</button>
        <button type="button" id="offline-button" class="btn btn-primary">Offline</button>
        <button type="button" id="inactive-user-button" class="btn btn-primary">Invalid Users</button>
      </div>
    </div>
    <table class="table table-hover">
      <tbody id="online-users">
      </tbody>
      <tbody id="offline-users">
      </tbody>
      <tbody id="invalid-users">
      </tbody>
    </table>
  </div> 
</body>

<!-- MODELS

online:
<tr class="success">
  <td class="td-one"><img src="" alt="user profile picture" /></td>
  <td class="td-two">
    <a href="#" class="btn btn-success" target="_blank"></a>
    <p class="visible-xs"><span class="game"></span><span class="description"></span></p>
  </td>
  <td class="hidden-xs"><span class="game"></span><span class="description"></span></td>
</tr>

offline:
<tr class="warning">
  <td class="td-one"><img src="http://learningdevsite.com/images/no-logo.gif" alt="user profile picture" /></td>
  <td class="td-two">
    <a href="#" class="btn btn-warning" target="_blank"></a>
    <p class="visible-xs"><em>User Currently Offline</em></p>
  </td>
  <td class="hidden-xs"><em>User Currently Offline</em></td>
</tr>

inactive:
<tr class="danger">
  <td class="td-one"><img src="http://learningdevsite.com/images/unf.gif" alt="user profile picture" /></td>
  <td class="td-two">
    <a href="#" class="btn btn-danger disabled"></a>
    <p class="visible-xs"><em>User Account Closed</em></p>
  </td>
  <td class="hidden-xs"><em>User Account Closed</em></td>
</tr>
-->
            
          
!
            
              
* {
  box-sizing: border-box;
}

body {
  padding-top: 20px;
  background-color: #e39578;
  /* http://www.transparenttextures.com/ "Carbon Fibre Big" */
  background-image: url("https://djl.azurewebsites.net/external-resources/carbon-fibre-big.png");
}

.title {
  width: 100%;
  background-color: #444;
  color: #bbb;
  padding-top: 10px;
  padding-bottom: 5px;
  padding-left: 10px;
  border-top-left-radius: 3px;
  border-top-right-radius: 3px;
  box-shadow: -5px 5px 10px #111;
}

table {
  box-shadow: -5px 5px 10px #111;
}

tr {
  height: 65px;
}

td {
  vertical-align: middle !important;
}

img {
  max-height: 60px;
  max-width: 60px;
}

.td-one {
  width: 65px;
}

.td-two {
  width: 1%;
}

@media only screen and (max-width : 767px) {
  .td-two {
    width: 100%;
  }
}

.game {
  font-weight: 700;
}

            
          
!
            
              $(document).ready(function() {
  //initialize data
  var streamers = ['freecodecamp', 'rampageishuman', 'esl_sc2', 'ogamingsc2', 'storbeck', 'terakilobyte', 'habathcx', 'robotcaleb', 'thomasballinger', 'noobs2ninjas', 'beohoff', 'brunofin', 'comster404'];
  streamers.sort();

  //online-user html model
  function onlineModel(data) {
    var imageURL;
    if (data.stream.channel.logo === null) {
      imageURL = 'http://learningdevsite.com/images/no-logo.gif';
    } else {
      imageURL = data.stream.channel.logo;
    }
    var htmlModel =
      '<tr class="success">' +
      '<td class="td-one"><img src="' + imageURL + '" alt="user profile picture" /></td>' +
      '<td class"td-two">' +
        '<a href="' + data.stream.channel.url + '" class="btn btn-success" target="_blank">' + data.stream.channel.display_name + '</a>' +
        '<p class="visible-xs"><span class="game">' + data.stream.game + ': </span>' + data.stream.channel.status + '</p>' +
      '</td>' +
      '<td class="hidden-xs"><span class="game">' + data.stream.game + ': </span>' + data.stream.channel.status + '</td>' +
      '</tr>';
    
    $('#online-users').append(htmlModel);
  }

  //offline-user html model
  function offlineModel(userName) {
    var channelURL = 'https://api.twitch.tv/kraken/channels/' + userName + '?client_id=vky7144q4nqk9lctq3gjebz8gq91yl';
    $.getJSON(channelURL, function(response) {
      var imageURL;
        if (response.logo === null) {
          imageURL = 'http://learningdevsite.com/images/no-logo.gif';
        } else {
          imageURL = response.logo;
      }
      var htmlModel =
        '<tr class="warning">' +
          '<td class="td-one"><img src="' + imageURL + '" alt="user profile picture" /></td>' +
          '<td class="td-two">' +
            '<a href="' + response.url + '" class="btn btn-warning" target="_blank">' + response.display_name + '</a>' +
            '<p class="visible-xs"><em>User Currently Offline</em></p>' +
          '</td>' +
          '<td class="hidden-xs"><em>User Currently Offline</em></p>' +
          '</tr>';
      
      $('#offline-users').append(htmlModel);
    });
  }

  //inactive user html model
  function inactiveModel(userName) {
    var htmlModel =
      '<tr class="danger">' +
      '<td class="td-one"><img src="http://learningdevsite.com/images/unf.gif" alt="user profile picture" /></td>' +
      '<td class="td-two">' +
      '<a href="#" class="btn btn-danger disabled">' +
      userName +
      '</a>' +
      '<p class="visible-xs"><em>User Account Closed</em></p>' +
      '</td>' +
      '<td class="hidden-xs"><em>User Account Closed</em></td>' +
      '</tr>';

    $('#invalid-users').append(htmlModel);
  }

  //convert each streamer to url
  for (var i = 0; i < streamers.length; i++) {
    var currentStreamer = streamers[i];
    var eachURL = 'https://api.twitch.tv/kraken/streams/' + streamers[i] + '?client_id=vky7144q4nqk9lctq3gjebz8gq91yl&callback=?';
    (function(i, eachURL, currentStreamer) {
      $.getJSON(eachURL, function(response) {
        if (response.status === 404) {
          inactiveModel(currentStreamer);
        } else if (response.stream !== null) {
          onlineModel(response);
        } else if (response.stream === null) {
          offlineModel(currentStreamer);
        }
      });
    })(i, eachURL, currentStreamer);
  }
  
  $('#all-button').click(function() {
    $('button.active').removeClass('active');
    $(this).addClass('active');
    $('#online-users, #offline-users, #invalid-users').show();
  });
  
  $('#online-button').click(function() {
    $('button.active').removeClass('active');
    $(this).addClass('active');
    $('#offline-users, #invalid-users').hide();
    $('#online-users').show();
  });
  
  $('#offline-button').click(function() {
    $('button.active').removeClass('active');
    $(this).addClass('active');
    $('#online-users, #invalid-users').hide();
    $('#offline-users').show();
  });
  
  $('#inactive-user-button').click(function() {
    $('button.active').removeClass('active');
    $(this).addClass('active');
    $('#online-users, #offline-users').hide();
    $('#invalid-users').show();
  });

});
            
          
!
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