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.

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

            
              <div class="tabs is-medium is-centered">
  <ul>
    <li id="all" class="is-active"><a onclick="allClicked()">All</a></li>
    <li id="online"><a onclick="onlineClicked()">Online</a></li>
    <li id="offline"><a onclick="offlineClicked()">Offline</a></li>
  </ul>
</div>

<div class="columns is-multiline">
  <div id="notifications" class="container">
  </div>
</div>

<div class="columns is-multiline">
  <div id="channel-list" class="column is-half is-offset-one-quarter">
  </div>
</div>
            
          
!
            
              .card {
  margin-top: 1em;
}

.online {
  background-color: #2ecc71;
}

.offline {
  background-color: #ecf0f1;
}
            
          
!
            
              let twitterEndpoint = 'https://cors-anywhere.herokuapp.com/https://wind-bow.gomix.me/twitch-api';

let list = 'all';
let channels = [
  'ESL_SC2',
  'OgamingSC2',
  'cretetion',
  'freecodecamp',
  'habathcx',
  'RobotCaleb',
  'noobs2ninjas',
  'clickerheroesbot',
];

function createWarning(msg) {
  return $(`<div class="notification is-warning">${msg}</div>`);
}

function createCard(isOnline, data) {
  
  let card = `<div class="card is-fullwidth ${isOnline ? 'online' : 'offline'}">
          <div class="card-content">
            <div class="media">
              <div class="media-left">
                <figure class="image is-32x32">
                  <img src="${data.logo}">
                </figure>
              </div>
              <div class="media-content">
                <p class="title is-5">
                  ${data.display_name}
                </p>
                <p class='subtitle is-6'>
                  <a href="${data.url}">@${data.name}</a>
                </p>
              </div>
            </div>
          <div class="content"></div>
          ${data.status ? data.status : '<em>No status.</em>'} 
      </div>
    </div>`;

  return $(card);
}

function setActive(id) {
  $('#notifications').empty();
  $('#channel-list').empty();

  $('#all').removeClass('is-active');
  $('#online').removeClass('is-active');
  $('#offline').removeClass('is-active');

  $('#' + id).addClass('is-active');
}

function listChannel(isOnline, name) {
  $.getJSON(twitterEndpoint + '/channels/' + name + '/', function(data) {
    if (data.status === 404) {
      var warning = createWarning(data.message);
      $('#notifications').append(warning);
      return;
    }
    var card = createCard(isOnline, data);
    $('#channel-list').append(card);
  });
}

function updateList() {
  channels.forEach(function(channel) {
    $.getJSON(twitterEndpoint + '/streams/' + channel + '/', function(data) {
      if (data.stream) {
        // channel is online
        if (list === 'online' || list === 'all') {
          listChannel(true, channel);
        }
      } else {
        // channel is offline
        if (list === 'offline' || list === 'all') {
          listChannel(false, channel);
        }
      }
    });
  });
}

function allClicked() {
  list = 'all';
  setActive('all');
  updateList();
}

function onlineClicked() {
  list = 'online';
  setActive('online');
  updateList();
}

function offlineClicked() {
  list = 'offline';
  setActive('offline');
  updateList();
}

$(document).ready(function() {
  updateList();
});

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

Console