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>
  <title>Use the Twitchtv JSON API</title>
</head>

<body>
  <div class="container-fluid">
    <div id="navibar">
      <h1>Twitch streamers</h1>
      <div class="buttons">
        <button type="button" id="fahrenheitButton" onclick="showOnline()" class="btn btn-primary">Show just online </button>
        <button type="button" id="fahrenheitButton" onclick="showOffline()" class="btn btn-primary">Show just offline </button>
        <button type="button" id="fahrenheitButton" onclick="showAll()" class="btn btn-primary">Show all </button>
      </div>
    </div>
    <ul id="output">
    </ul>
  </div>
  <footer class="text-center">
    Made by <a href="https://www.freecodecamp.com/radekjohn" target="_blank">Radek John,</a> with use of Twitchtv <a href="https://dev.twitch.tv/docs/v5/guides/using-the-twitch-api/" target="_blank">API</a>.
  </footer>
</body>
            
          
!
            
              body {
  font-size: 120%;
  padding: 5%;
}

#navibar {
  margin: 0px;
  padding: 0px;
}

ul {
  margin: 2%;
  padding: 0;
}

li {
  border-bottom: 5px solid white;
  list-style-type: none;
  padding: 5px;
}

a:hover {
  color: black;
}

#buttons {
  boreder: 1px solid red;
  float: left;
}

.offline {
  width: 100%;
  background-color: yellow;
  color: black;
}

.online {
  width: 100%;
  background-color: green;
  color: black;
}

.userName {
  font-size: 150%;
  width: 300px;
  color: black;
}

.status {
  width: 400px;
}

.content {
  float: right;
}

.invisible {
  display: none;
}
            
          
!
            
              $(document).ready(function() {

 // Array with users
var users = ["freecodecamp", "ESL_SC2", "OgamingSC2", "cretetion", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];

 // Prepared urls 
  var urlPrep = "https://wind-bow.gomix.me/twitch-api/streams/";
  var userLink = "https://www.twitch.tv/";
 
 // Prepared variables for api url and user
  var url = "";
  var user = "";


// Function for adding user to the list
  function addUser(item) {
 // Build API url  
    url = urlPrep + item;
// Call API and
    $.ajax({
      type: "GET",
      url: url,
      success: function(data) {
// Check if user is offline and note it
        if (data.stream === null) {
          $("#output").prepend(
            "<li class='offline row'>" +
            "<a href=" + userLink + item + ">" + "<div class='userName'>" + item + "</div>" + "</a>" +
            "<div class='status'> offline </div>" +
            "</li>");
// Else note him as online 
        } else {
          $("#output").prepend("<li class='online row'>" +
            "<a href=" + userLink + item + ">" + "<div class='userName'>" + item + "</div>" + "</a>" +
            " <div class='status'> online </div>" +
            "<div class='content'>" +
            "Streams " +
            JSON.stringify(data.stream.game).replace(/"/g, '') + " and has " + JSON.stringify(data.stream.viewers) +
            " viewers" +
            "</div>" +
            "</li>")
        }

      }
    })

  }
// Call user function for all users  
  for (var i = users.length - 1; i >= 0; i--) {
    addUser(users[i]);
  }

  // Belongs to  $(document).ready ... 
});

// Make offline users disappear
function showOnline() {
  $(".offline").css("display", "none");
  $(".online").css("display", "");
}
// Make online users disappear
function showOffline() {
  $(".online").css("display", "none");
  $(".offline").css("display", "");
}
// Show all users
function showAll() {
  $(".online").css("display", "");
  $(".offline").css("display", "");
}
            
          
!
999px
Loading ..................

Console