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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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.

            
              <head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>Twitch.tv JSON API - Free Code Camp, Intermediate Front End Development Projects</title>
</head>
<body>
<div class="container-fluid row marge-20">
	<div id="twitchHeader" class="container-fluid col-md-6 col-md-offset-3 col-sm-10 col-sm-offset-1 col-xs-12 bg-primary">
     	<div>
     		<h1>Twitch.tv Streamers</h1>
     	</div>
     <div class="pull-right">
     	<span id="allOf">All</span> | 
     	<span id="onlineOnly">Online Only</span> | 
     	<span id="offlineOnly">Offline Only</span></div>
     </div>
	<div id="twitchBody" class="container-fluid col-md-6 col-md-offset-3 col-sm-10 col-sm-offset-1 col-xs-12"></div>
	<div id="twitchFooter" class="container-fluid col-md-6 col-md-offset-3 col-sm-10 col-sm-offset-1 col-xs-12 bg-primary text-center"><a href="http://raymondrizzo.com/Portfolio" target="_blank">Raymond Rizzo</a></div>
</div>
<div id="invisibleDiv"></div>
</body>
</html>
            
          
!
            
              body {
  background-color: #333333;
  font-family: "Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif !important;
  font-size: 20px;
  font-style: normal;
  font-variant: small-caps;
  font-weight: 500;
}

#twitchHeader {}

#twitchBody {
  background-color: #ffffff;
  padding: 2%;
}

#twitchFooter {
  padding: 1%;
}

.marge-20 {
  margin-top: 20px;
}

.eachStreamer {
  border-width: 1px 0px 0px 0px;
  border-style: solid;
  border-color: #dddddd;
}

#invisibleDiv {
  visibility: hidden;
}

#twitchFooter a, #twitchFooter a:hover, #twitchFooter a:active, #twitchFooter a:visited, #twitchFooter a:link{
  color: #ffffff;
}
            
          
!
            
              // JavaScript Document

var twitchStreamers = ['esl_sc2', 'ogamingsc2', 'cretetion', 'freecodecamp', 'storbeck', 'habathcx', 'robotcaleb', 'noobs2ninjas', 'comster404'];
var twitchUserArray = [];
var twitchStreamArray = [];

$(document).ready(function() {
	'use strict';
	$('#allOf').on('click', function() {
		window.setTimeout(appendThing, 600, '.bg-success', '#twitchBody');
		window.setTimeout(appendThing, 600, '.bg-danger', '#twitchBody');
	}); 

	$('#onlineOnly').on('click', function() {
		$('.bg-danger').addClass('animated bounceOut');
		window.setTimeout(appendThing, 600, '.bg-danger', '#invisibleDiv');
		window.setTimeout(appendThing, 600, '.bg-success', '#twitchBody');
	});

	$('#offlineOnly').on('click', function() {
		$('.bg-success').addClass('animated bounceOut');
		window.setTimeout(appendThing, 600, '.bg-success', '#invisibleDiv');
		window.setTimeout(appendThing, 600, '.bg-danger', '#twitchBody');
	});

  twitchStreamers.forEach(function(streamer) {
    loadList('users/', streamer);
  });

});

function loadList(type, element) {
		'use strict';
		$.ajax({
			url: 'https://api.twitch.tv/kraken/' + type + element,
			type: 'GET',
			headers: {
				'Client-ID': 'os6gq0a35dfnvg9h5cceuw5zhoj115z',
				'Accept': 'application/vnd.twitchtv.v3+json'
				},
			success: function(data){
				twitchUserArray.push(data);
				$.ajax({
					url: 'https://api.twitch.tv/kraken/streams/' + element,
					type: 'GET',
					headers: {
						'Client-ID': 'os6gq0a35dfnvg9h5cceuw5zhoj115z',
						'Accept': 'application/vnd.twitchtv.v3+json'
					},
					success: function(dataTwo){
						twitchStreamArray.push(dataTwo);
						if(twitchStreamArray.length === 8){
							//console.log(twitchUserArray[0]['name']);
							//console.log(twitchStreamArray[0]['stream']['channel']['display_name'].toLowerCase());
							populateScreen();
						}
					}
					
				});
			}
		});
}
	
function populateScreen() {
	'use strict';
    var userDivID = '';
	twitchUserArray.forEach(function(userObject){
		userDivID = '#' + userObject.name;
		$('#twitchBody').append('<div id="' + userObject.name + '" class="container-fluid row"><div class="container-fluid col-md-2 col-sm-2 col-xs-2"><img class="img-responsive container-fluid" src="' + userObject.logo + '" />' + '</div><div id="' + userObject.name + 'State' + '" class="container-fluid col-md-10 col-sm-10 col-xs-10"><p><a href="https://twitch.tv/' + userObject.name + '" target="_blank">' + userObject.name + '</a></p>');
		$('#' + userObject.name + 'State').append('No active stream</div>');
		$(userDivID).addClass('bg-danger');	
		twitchStreamArray.forEach(function(streamObject){
			if(streamObject.stream !== null){
				if(streamObject.stream.channel.name === userObject.name){
					$(userDivID).remove();
					console.log('Online user: ' + userObject.name);
					$('#twitchBody').append('<div id="' + userObject.name + '" class="container-fluid row"><div class="container-fluid col-md-2 col-sm-2 col-xs-2"><img class="img-responsive container-fluid" src="' + userObject.logo + '" />' + '</div><div id="' + userObject.name + 'State' + '"class="container-fluid col-md-10 col-sm-10 col-xs-10"><p><a href="https://twitch.tv/' + userObject.name + '" target="_blank">' + userObject.name + '</a></p>');
					$('#' + userObject.name + 'State').append(streamObject.stream.game + '</div>');
					$(userDivID).addClass('bg-success');
					twitchStreamers[twitchStreamers.indexOf(userObject.name)] = '';
				}
			} else {
					twitchStreamers[twitchStreamers.indexOf(userObject.name)] = '';
			}		
		});
	});
	twitchStreamers.forEach(function(streamer){
		if(streamer !== ''){
			//alert(streamer);
			$('#twitchBody').append('<div id="' + streamer + '" class="container-fluid row"><div class="container-fluid col-md-2 col-sm-2 col-xs-2">' + '</div><div id="' + streamer + 'State' + '"class="container-fluid col-md-10 col-sm-10 col-xs-10"><p><a href="https://twitch.tv/' + streamer + '" target="_blank">' + streamer + '</a></p>');
			$('#' + streamer + 'State').append('Twitch.tv user does not exist</div>');
			$('#' + streamer).addClass('btn-warning');	
		}
		
	});
	console.log(twitchStreamers);
}


function appendThing(what, where) {
		'use strict';
  $(what).appendTo(where);
  $(what).removeClass('animated bounceOut');

  $(what).removeClass('animated bounceInUp');
}


            
          
!
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