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.

            
              <body>
  <nav class="navbar navbar-default" id="twitch_nav">
    <span class="navbar-brand glyphicon glyphicon-th" id="nav_text">
      <span id="brand_name">Twitch TV</span>
    </span>
  </nav>
  <div class="container">
    <div class="row search">
      <form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input id="search_bar" type="text" class="form-control" placeholder="Ex: Search for 'a'" required="required">
        </div>
        <a id="search_button" type="" class="btn btn-default">Search</a>

      </form>      
    </div>
    <div class="row main">
      <h1 class="text-center" id="default_message">Search your favorite channels....</h1>
    </div>
  </div>
</body>
            
          
!
            
              .body {
  font-family: roboto;
}

#brand_name
{
  font-family:mono;
}
.channel {
  height: 300px;
  margin: 0px;
  border: 1px solid grey;
  margin: 30px;
  padding: 0px;
}

.channel-viewers {
  color: white;
  padding-top: 5px;
  font-weight: 300;
  padding-left: 10px;
  background-color: rgba(1, 1, 1, 0.6)
}

.channel-button {
  border-radius: 100px;
  width: 100px;
  margin-left: 10px;
  background-color: #16a085;
}

.channel-button:hover {
  color: white;
  background-color: #f1c40f;
  border: 2px solid black;
}

.channel-button-div {
  margin-top: 50%;
}

#twitch_nav {
  background-color: #16a085;
}

#nav_text {
  color: white;
}

.channel-title {
  font-size: 24px;
  font-weight: 300;
  width: 100%;
  height: 70px;
  background-color: rgba(1, 1, 1, 0.6);
  padding-left: 15px;
  color: white;
}

#search_button {
  border-radius: 100px;
  border: none;
  background-color: #16a085;
  color: white;
}

#search_bar
{
  border-radius:100px;
  width:200px;
}

#default_message
{
  color:grey;
  font-weight:100;
  padding-top:100px;
}

#tool_tip
{
  background-color:#16a085;
  font-family:roboto;
}
            
          
!
            
              $(document).ready(function() {
  $.getJSON('https://api.twitch.tv/kraken/streams?callback=?', function(data) {
    $("#search_button").click(function() {
      var text = $("#search_bar").val();
      if (text !== "") {
        $(".channel").remove();
        $("#default_message").hide();
        display(data, text);
      }
    });
  });

  // display function
  function display(data, text) {

    var id, id2;
    var heading;
    var viewers;
    var timestamp;
    var video_height;
    var video_banner;
    var video_url;
    var ct = 1;
    for (channel in data.streams) {
      id = "box_" + ct
      id2 = "button_" + ct;
      heading = data.streams[channel].game;
      viewers = data.streams[channel].viewers;
      timestamp = data.streams[channel].created_at;
      video_height = data.streams[channel].video_height;
      video_banner = data.streams[channel].channel.logo;
      video_url = data.streams[channel].channel.url;
      var str1 = heading.toLowerCase();
      var str2 = text.toLowerCase();
      console.log(str1);
      if (str1.indexOf(str2) !== -1) {
        console.log(video_url);
        createBox(id);
        //console.log(id2);
        writeHeadingInfo(id, heading);
        writeViewers(id, viewers);
        boxBG(id, video_banner);
        createButtonBox(id, id2, video_url);
        ct++;
      }
    }
    if (ct===1){
      $("#default_message").text("Sorry no results found...");
      $("#default_message").show();
    }

    // write geek stuff

  }

  // function creating a box
  function createBox(id) {
    html = "<div class='col-lg-3 channel'";
    html += ' id=' + '"' + id + '"';
    html += "></div>"
    $('.main').append(html);
  }

  //Writing basic info
  function writeHeadingInfo(id, heading) {
    html = "<div class='channel-title'>";
    html += heading;
    html += '</div>';
    var id = "#" + id;
    //console.log(id)
    $(id).append(html);
  }

  //Writing viewers
  function writeViewers(id, viewers) {
    var id = "#" + id;
    html = "<div class='channel-viewers'>";
    html += "<span class='glyphicon glyphicon-user'></span>";
    html += viewers;
    html += "</div>";
    $(id).append(html);
  }

  //Box BG
  function boxBG(id, banner) {
    var id = "#" + id;
    var imagePath = "url(";
    imagePath += banner;
    imagePath += ")";
    $(id).css("background-image", imagePath);

  }

  //function buttonbox
  function createButtonBox(id0, id, link) {
    var id0 = "#" + id0;
    var id = "#" + id;
    var html;
    html = '<div class="channel-button-div">'
    html += "<a class='btn btn-primary channel-button' href=";
    html += '"' + link + '"';
    html += ' target="_blank">';
    html += 'Visit</a>';
    html += '</div>'
      //console.log(html);
    $(id0).append(html);

  }

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