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.

            
              <div class="container">
  <header class="page-header">
    <a class="logo" href="https://twitch.tv" target="_blank">
      <img class="full-logo" src="https://www.twitch.tv/p/assets/uploads/twitch_474x356.png" alt="Twitch Logo">
      <img class="mobile-logo" src="https://www.twitch.tv/p/assets/uploads/glitch_474x356.png" alt="Twitch Logo">
    </a>
    <div class="search">
      <label><input type="text" id="searcher" placeholder="Search user list"></label>
    </div>
  </header>
  <div class="filter-options">
    <button class="filter-select selected" id="all">All Users</button>
    <button class="filter-select" id="online">Online</button>
    <button class="filter-select" id="offline">Offline</button>
  </div>
  <div class="switch-container" id="switch-container"></div>
</div>
            
          
!
            
              $twitch-color: #6441a4; /* rgb(100,65,164) */
$text-color-bright: #c7d7ff;
$bg-color-online: $twitch-color;
$bg-color-offline: #aaa;
$text-color-inactive: #5d5d5d;

* {
  box-sizing: border-box;
  position: relative;
}
body {
  font-family: "Fira Sans Extra Condensed", sans-serif;
  letter-spacing: 0.75px;
  margin: 0;
  padding: 0;
  color: $text-color-bright;
  background-color: white;
  overflow-x: hidden;
  min-width: 310px;
}
a {
  color: #c7d7ff;
  text-decoration: none;
}
p {
  margin: 0.5em auto;
}
h3 {
  margin: 0;
  margin-bottom: 0.5em;
}

/*********************/
/*                   */
/*    Page Header    */
/*                   */
/*********************/
.page-header {
  $header-height: 85px;
  width: 100%;
  height: $header-height;
  background-color: $twitch-color;
  .logo {
    .full-logo { display: inline-block; }
    .mobile-logo { display: none; }
    display: inline-block;
    float: left;
    height: $header-height;
    img {
      height: $header-height;
      width: auto;
    }
  }
  /*********************/
  /*    Search Input   */
  /*********************/
  .search {
    $search-padding: 20px;
    padding: $search-padding ($search-padding / 2);
    display: inline-block;
    height: $header-height;
    input {
      width: 320px;
      height: $header-height - ($search-padding * 2);
      font-family: "Fira Sans Extra Condensed", sans-serif;
      font-size: 1.5em;
      color: $text-color-bright;
      background-color: $twitch-color;
      border: none;
      border-bottom: 3px solid $text-color-bright;
      &::placeholder {
        color: darken($text-color-bright, 15%);
      }
    }
  }
}
/*********************/
/*                   */
/*  Filter Buttons   */
/*                   */
/*********************/
.filter-options {
  margin-top: 15px;
  text-align: center;
  .filter-select {
    font-family: "Fira Sans Extra Condensed", sans-serif;
    display: inline-block;
    $button-width: 72px;
    width: $button-width;
    height: $button-width / 2;
    border-radius: $button-width / 2;
    border: none;
    background-color: $bg-color-offline;
    color: $text-color-inactive;
    &.selected {
      background-color: $twitch-color;
      color: $text-color-bright;
    }
    &:hover {
      cursor: pointer;
      opacity: 0.9;
    }
    &:focus {
      outline: none;
    }
  }
}
/*********************/
/*                   */
/*   Switch Styles   */
/*                   */
/*********************/
.switch-container {
  max-width: 580px;
  padding: 5px;
  margin: 15px auto 30px auto;
}
.switch {
  $switch-height: 100px;
  $item-dimension: $switch-height;
  $border-radius: $switch-height / 2;
  
  height: $switch-height;
  border-radius: $border-radius;
  margin-bottom: 5px;
  display: none;
  overflow: hidden;
  &:hover {
    opacity: 0.9;
  }
  /************************/
  /* Switch Pics/Previews */
  /************************/
  .pic, .preview {
    border: 4px solid transparent;
    width: $item-dimension;
    height: $item-dimension;
    border-radius: $item-dimension / 2;
    position: absolute;
    top: 0;
    background-size: cover;
    background-position: center;
  }
  .pic {
    left: 0;
  }
  .preview {
    right: 0;
  }
  /*********************/
  /*  Switch Details   */
  /*********************/
  .details {
    padding: 5px ($item-dimension + 5px);
    .status {
      display: block;
    }
  } 
  &.online {
    background-color: $bg-color-online;
    background-image: linear-gradient(to right, $bg-color-online 20%, lighten($bg-color-online, 15%));
    .pic, .preview {
      border-color: $bg-color-online;
    }
  }
  /**********************/
  /*  Offline Switches  */
  /**********************/
  &.offline {
    background-color: $bg-color-offline;
    background-image: linear-gradient(to right, $bg-color-offline 20%, darken($bg-color-offline, 15%));
    color: $text-color-inactive;
    a {
      color: $text-color-inactive;
    }
    .pic {
      border-color: $bg-color-offline;
      opacity: 0.3;
    }
    .preview {
      display: none;
    }
  }
}

/*********************/
/*                   */
/*   Media Queries   */
/*                   */
/*********************/
@media (max-width: 500px) {  
  body {
    font-size: 14px
  }
  .page-header {
    $header-height: 50px;
    height: $header-height;
    .logo {
      .full-logo { display: none; }
      .mobile-logo { display: inline-block; }
      height: $header-height;
      img {
        height: $header-height;
      }
    }
    .search {
      $search-padding: 10px;
      padding: $search-padding ($search-padding / 2);
      height: $header-height;
      input {
        width: 222px;
        height: $header-height - ($search-padding * 2);
        font-size: 1.1em;
      }
    }
  }
  .switch {
    $switch-height: 70px;
    $item-dimension: $switch-height;
    $border-radius: $switch-height / 2;
    $bg-color-online: $twitch-color;

    height: $switch-height;
    border-radius: $border-radius;
    .pic, .preview {
      width: $item-dimension;
      height: $item-dimension;
      border-radius: $item-dimension / 2;
    }
    .details {
      padding: 5px ($item-dimension + 5px);
      .status {
        display: none;
      }
    }
  }
}
            
          
!
            
              'use strict';

// set up globals
let __streamerData = {};
let streamerList = ['gamesdonequick','GameJ06','FireDragon','darbian','EnNopp112','Zfg1','raysfire','gymnast86','ESL_SC2','OgamingSC2','cretetion','360Chrism','freecodecamp','storbeck','habathcx','V0oid','RobotCaleb','noobs2ninjas'];

$(document).ready(()=>{
  // iterate through the streamer list and populate switches
  for (let i = 0; i < streamerList.length; i++) {
    populateStreamerData(streamerList[i]);
  }
  
  // handle user searches
  let searchString = $("#searcher").val();
  $("#searcher").keyup(function(){
    let val = $("#searcher").val();
    // if the user input value is blank, show the whole list
    if (val === "") { $(".switch").css("display", "block"); }
    // if the user input value hasn't changed yet, do nothing
    if (val == searchString) { return; }
    // otherwise, set all switch displays to none, then show the matching switches
    $(".switch").css("display", "none");
    
    if ($("#online").hasClass("selected")) {
      $(".switch.online").filter(function(){
        return (this.id.toLowerCase().indexOf(val.toLowerCase()) > -1);
      }).css("display", "block");
    }
    else if ($("#offline").hasClass("selected")) {
      $(".switch.offline").filter(function(){
        return (this.id.toLowerCase().indexOf(val.toLowerCase()) > -1);
      }).css("display", "block");
    }
    else {
      $(".switch").filter(function(){
        return (this.id.toLowerCase().indexOf(val.toLowerCase()) > -1);
      }).css("display", "block");
    }
  });
  
  // if the user filters by all, show all switches and blank out user input
  $("#all").click(()=>{
    buttonClass('#all');
    $(".switch").css("display", "block");
    $("#searcher").val("");
    searchString = "";
  });
  
  // filter to show online streamer switches
  $("#online").click(()=>{
    buttonClass('#online');
    $(".switch.online").css("display", "block");
    $(".switch.offline").css("display", "none");
    $("#searcher").val("");
    searchString = "";
  });
  
  // filter to show offline streamer switches
  $("#offline").click(()=>{
    buttonClass('#offline');
    $(".switch.online").css("display", "none");
    $(".switch.offline").css("display", "block");
    $("#searcher").val("");
    searchString = "";
  });
});

// utility function for adding and removing classes from buttons as they're clicked
function buttonClass(idStr) {
  $("#all, #online, #offline").removeClass("selected");
  $(idStr).addClass("selected");
}

function populateStreamerData(streamer) {
  __streamerData[streamer] = {streams: {}, users: {}};
  getData('streams', streamer).then((data)=>{
    __streamerData[streamer].streams = data;
  }).then(()=>{
    getData('users', streamer).then((data)=>{
      __streamerData[streamer].users = data;
    }).then(()=>{
      let newSwitch = constructSwitch(streamer);
      document.getElementById("switch-container").appendChild(newSwitch);
      $("#" + streamer.toLowerCase()).fadeIn();
    });
  })
}

// get the requested stream or user data from Twitch
function getData(dataRequest, userName) {
  let def = $.Deferred();
  
  $.ajax({
    data: { 'origin': 'https://s.codepen.io/' },
    dataType: 'json',
    method: 'GET',
    url: 'https://wind-bow.glitch.me/twitch-api/' + dataRequest + '/' + userName,
    success: (data) => { def.resolve(data); }
  });
  
  return def;
}

function constructSwitch(streamerName) {
  let streamObj = __streamerData[streamerName];
  let placeholderImg = "url('https://www.twitch.tv/p/assets/uploads/glitch_474x356.png')";
  let newSwitch = document.createElement('div');
  newSwitch.id = streamObj.users.name;
  
  let pic = document.createElement('div');
  pic.className = 'pic';
  pic.style.backgroundImage = streamObj.users.logo != null ? "url(" + streamObj.users.logo + ")" : placeholderImg;
  let details = document.createElement('div');
  details.className = 'details';
  let name = document.createElement('h3');
  name.textContent = streamObj.users.display_name;
  name.className = 'name';
  let game = document.createElement('p');
  game.className = 'game';
  let status = document.createElement('p');
  status.className = 'status';
  let preview = document.createElement('div');
  preview.className = 'preview';
  if (streamObj.streams.stream != null) {
    // online stuff
    newSwitch.className = 'switch online';
    game.textContent = streamObj.streams.stream.channel.game;
    status.textContent = streamObj.streams.stream.channel.status; 
    preview.style.backgroundImage = "url(" + streamObj.streams.stream.preview.medium + ")";
  }
  else {
    // offline stuff
    newSwitch.className = 'switch offline';
    status.textContent = 'Offline';
  }
  
  // append children
  details.appendChild(name);
  details.appendChild(game);
  details.appendChild(status);
  newSwitch.appendChild(pic);
  newSwitch.appendChild(details);
  newSwitch.appendChild(preview);
  
  let link = document.createElement('a');
  link.href = 'https://www.twitch.tv/' + streamObj.users.name;
  link.target = '_blank';
  link.title = 'Watch ' + streamObj.users.display_name + ' on Twitch';
  link.appendChild(newSwitch);
  
  return link;
}
            
          
!
999px
Loading ..................

Console