Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                


  <content>


    <div class = "container-fluid" id = "twitchbox">

      <div class = "row" id = "header">
        my favorite streams
      </div>


      <div id = "streams">




      </div>

    </div>


  </content>

              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  border: 0;
}

body {
    position: relative;
    overflow-x: hidden;
  font-size: 100%;
}

html, body {
  height: 100%;
  background-color: lightgrey;
}

p {
  display: inline;
  margin: 0px;
  color: black;
  font-size: 1.5em;
}

#header {
  font-size: 2em;
  text-decoration: underline;
}

#twitchbox {

  width: 600px;

  min-height: 100px;

    position: absolute;
    top: 30px;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;

 }


#header {

   font-size: 3em;
   margin:  5px 2px 5px 2px;
   padding:  5px 2px 5px 2px;
   text-align: center;
   height: 50px;
}

#streamon {
  background-color: green;
}

#streamoff {
  background-color: red;
}

#streamna {
  background-color: #3399FF;
}
.stream {

   margin:  5px 2px 5px 2px;
   padding:  5px 2px 5px 2px;
   text-align: center;
   height: 125px;
}

.accountname {
   margin:  2px 2px 2px 2px;
   padding:  2px 2px 2px 2px;

   font-size: 2em;
   text-align: center;

}

.logo {
 margin:  2px 2px 2px 2px;
   padding:  2px 2px 2px 2px;
 

text-align: center;
height: 50px;
  width: 50px;
}

.description {
 margin:  5px 2px 5px 2px;
   padding:  2px 2px 2px 2px;
  font-size: 1.5em;
  text-align: center;
}
              
            
!

JS

              
                function ready(fn) { // ready function equivalent to jQuerys $(document).ready(function()
  if (document.readyState != 'loading'){
    fn();
  } else {
    document.addEventListener('DOMContentLoaded', fn);
  }
} // ready closing

// Other global variables
var channels = ["foxdrop", "imaqtpie", "riotgames", "eulcs1", "eulcs2", "nightblue3", "nalcs1", "nalcs2", "trick2g", "freecodecamp", "brunofin", "comster404"];
var endpoints = ["channels", "streams"];
var url = 'https://api.twitch.tv/kraken/';
var headers = new Headers();
headers.append('Client-ID', 'cs5fm2re94r0f072a11ojljaq5ki05h');

function Stream (name, display_name, status, logo, url, banner) {
    this.name = name;
    this.display_name = display_name;
    this.status = status;
    this.logo = logo;
    this.url = url;
    this.banner = banner;
}

// Code that gets executed when the dom is loaded
ready(function() {

  function getStream(response) {
    if (response.status == 422 || response.status >= 200 && response.status < 300) { //422 ist der Fehlercode für gebannte Twitchstreams
      return Promise.resolve(response) //soweit erfolgreich, dann Rückgabe des versprechens an die fetchchain
    } else {
      return Promise.reject(new Error(response.statusText)) //es gab einen Fehler, überspringen der fetchchain bis zum Ende: catch. Hier dann Ausgabe des Fehlercodes
    }
  }

  function getJson(response) {
    return response.json() //mache aus dem response Objekt ein Json Objekt und gebe es an die fetchchain zur weiteren Bearbeitung zurück
  }

  function getData(data) {
    console.log(data);
    if (data.name)  {
      return new Stream(data.name, data.display_name, data.status, data.logo, data.url, data.profile_banner);
    }
    else {
      return data;
    }
  }

  function getStatus(data) {
    var channelArr = data._links.channel.split('/kraken/channels/');
    channelname = channelArr[1];

    if (data.stream != null)  {
      divselect = document.getElementById(channelname);
      divselect.style.backgroundColor = '#99FF00';
    }
    else  {
      divselect = document.getElementById(channelname);
      divselect.style.backgroundColor = '#FF3333';
    }
  }

  function errorMessage(error)  {
    console.log('Request failed', error);
  }

  function buildHTML(data)  {
    if (data.name)  {
      var html = '<a href=' + data.url + '><div class = "stream row" id=' + data.name + ' ><img src = ' + data.logo + ' class = "logo"></img><p class = "accountname">' + data.display_name + '</p><br><p class = "description">' + data.status + '</p></div></a>';
      var divstreams = document.getElementById('streams');
      divstreams.innerHTML = divstreams.innerHTML + html;
    }
    else if (data.message)  {
      var msgArr = data.message.split("'");
      name = msgArr[1];
      var html = '<div class = "stream row" id = "streamna"><img src = "http://www.trustice.de/images/no-logo.jpg" class = "logo"></img><p class = "accountname">' + name + '</p><br><p class = "description">' + data.message + '</p></div></a>';
      var divstreams = document.getElementById('streams');
      divstreams.innerHTML = divstreams.innerHTML + html;
    }
  }

  function getAvailable() {
    for (var i = 0; i < channels.length; i++) {
      url = 'https://api.twitch.tv/kraken/streams/' + channels[i];
      var request = new Request(url, {
	      headers: new Headers({
		     'Client-ID': 'cs5fm2re94r0f072a11ojljaq5ki05h'
	      })
      });
      fetch(request)
        .then(getStream)
        .then(getJson)
        .then(getStatus)
        .catch(errorMessage)
    }
  }

  function getTwitchdata()  {
    for (var i = 0; i < channels.length; i++) {
      url = 'https://api.twitch.tv/kraken/channels/' + channels[i];
      var request = new Request(url, {
	      headers: new Headers({
		     'Client-ID': 'cs5fm2re94r0f072a11ojljaq5ki05h'
	      })
      });
      fetch(request)
        .then(getStream)
        .then(getJson)
        .then(getData)
        .then(buildHTML)
        .catch(errorMessage)
    }
  }


getTwitchdata();
getAvailable();


}); //ready closing

              
            
!
999px

Console