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.

            
              <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

<link href='https://fonts.googleapis.com/css?family=Questrial' rel='stylesheet' type='text/css'>


<div class="container">
  <div class="col-md-6 content col-md-offset-3">
    <h1 class="text-center title">The Amazing Twitch</h1>
    <ul class="nav nav-tabs" role="tablist">
      <li role="presentation" class="active col-md-4 text-center"><a id="allButton" href="#all" aria-controls="all" role="tab" data-toggle="tab">All</a></li>
      <li role="presentation" class="col-md-4 text-center"><a id="onlineButton" href="#online" aria-controls="online" role="tab" data-toggle="tab">Online</a></li>
      <li role="presentation" class="col-md-4 text-center"><a id="offlineButton" href="#offline" aria-controls="messages" role="tab" data-toggle="tab">Offline</a></li>
    </ul>

   


    <!-- Tab panes -->
    <div class="tab-content">
      <div role="tabpanel" class="tab-pane active" id="all">
        <!-- All content here -->
        <div class="allStreamers">
        </div>
      </div>
      <div role="tabpanel" class="tab-pane" id="online">
        <!-- Online only -->
        <div class="allStreamers">
        </div>
      </div>
      <div role="tabpanel" class="tab-pane" id="offline">
        <!-- Offline only -->
        <div class="allStreamers">
        </div>
      </div>
    </div>
  </div>
</div>
            
          
!
            
              body {
  font-family: Questrial, San-serif; 
  background-image: url("http://www.dardandemiri.com/projects/twitch/images/bg.jpg");
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}

.container {
  margin-top: 70px;
}

.content {
  background-color: rgba(255, 255, 255, 0.8);
}


.channel {
  padding: 20px 5px 20px 5px;
  border-bottom: 1px solid grey;
}

.channel:hover {
  background-color: rgba(255, 255, 255, 0.9);
}

.channel img {
  height: 90px;
}

.channel h3 {
  margin-top: 0px;
}

.channel p {
  font-size: 19px;
}

.info {
  padding-left: 40px;
}

.status img {
  width: 37px;
  height: 37px;
  margin-top: 30%;
}

#allStreamers {
  margin-top: 20px;
  border-top: 1px solid #DDD;
}

.styleSpinner {
  margin-top: 50px;
  margin-bottom: 50px;
}

.title {
  padding-bottom: 30px;
  padding-top: 30px;
}



a {
  text-decoration: none;
  color: inherit;
}
            
          
!
            
              var channelURL = "https://api.twitch.tv/kraken/channels/";

$(function() {
  var twitchUsers = [
    "freecodecamp",
    "storbeck",
    "habathcx",
    "RobotCaleb",
    "noobs2ninjas",
    "medrybw",
    "ogamingsc2",
    "esl_sc2",
    "cretetion"
  ];
  var $container = $(".allStreamers");
  var $allButtons = $("#buttons");
  getData();

  function createView($object, number) {
    if ($object.logo === null) $object.logo = "images/noProfil.png";

    var html =
      '<a href="' + $object.url + '">' +
      '<div class="row channel channel' + number + " " + $object.statusClass + '  ">' +
      '<div class="img-responsive col-xs-2 col-sm-2 col-md-2 col-lg-2 profilIMG">' +
      '<img src="' + $object.logo + '" alt="">' +
      '</div>' +
      '<div class="col-xs-8 col-sm-8 col-md-8 col-lg-8 info">' +
      '<h3 id="' + number + '">' + $object.display_name + '</h3>' +
      '<p>' + $object.status + '</p>' +
      '</div>' +
      '<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 status text-center">' +
      '<img src="http://www.dardandemiri.com/projects/twitch/images/' + $object.statusClass + '.png" alt="">' +
      '</div>' +
      '</div>' +
      '</a>';

    $container.append(html);
  }



  function getData() {
    $container.html('<div class="styleSpinner text-center"><i class=" fa fa-spinner fa-pulse fa-3x fa-fw margin-bottom"></i><span class="sr-only">Loading...</span></div>');
    $.ajax({
      url: "https://api.twitch.tv/kraken/streams?channel=" + twitchUsers.join(),
      success: function(data) {
        $container.html("");
        var onlineStreamers = [];

        var number = 0;
        data.streams.forEach(function(stream) {
          onlineStreamers.push(stream.channel.name);
          stream.channel.statusClass = "online";
          createView(stream.channel, number);
          number++;
        });

        var offlineChannels = twitchUsers.filter(function(i) {
          return onlineStreamers.indexOf(i);
        });

        offlineChannels.forEach(function(channel) {
          $.ajax({
            url: channelURL + channel,
            dataType: "json",
            success: function(success) {
              success.status = "Offline";
              success.statusClass = "offline";
              createView(success, number);
              number++;

            },
            error: function(xhr, ajaxOptions, thrownError) {

              var errorObj = {
                statusClass: "closed",
                name: channel,
                display_name: channel,
                logo: null,
                url: "https://www.twitch.tv/" + channel,
                status: "Account Closed",
              };
              createView(errorObj, number);
              number++;
            }
          });
        });
      }
    });
  }
});

$("#onlineButton").on("click", function() {
  $(".online").css("display", "block");
  $(".offline").css("display", "none");
});

$("#offlineButton").on("click", function() {
  $(".offline").css("display", "block");
  $(".online").css("display", "none");
});

$("#allButton").on("click", function() {
  $(".offline").css("display", "block");
  $(".online").css("display", "block");
});

$("#refresh").on("click", function() {
  getData();
});
            
          
!
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