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.

            
              <html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <!-- Bootstrap says:  The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    
    <title>Twitch Streamers</title>
    <!-- Bootstrap -->
    <link href=
    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
    rel="stylesheet">
    <link href="main.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
   
</head>

<body>
	<div class = "container">
		<h1>Twitch TV Viewer</h1>
		<div id="results">
			<!-- Use this for testing w/o the app.js
			<div class = "row">
				<div class = "col-sm-1 col-xs-3 avatar"><img src = "https://placekitten.com/40/40"></div>
				<div class = "col-sm-3 col-xs-9 screenname">hard coded title</div>
				<div class = "col-sm-8 col-xs-12 description">hard coded to test format -- will put the description here, but it mustn't be too many characters, needs to fit on a mobile phone in 1, maybe two lines</div>
			</div> -->
		</div>
	</div>



    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src=
    "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
    </script> 
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src=
    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">
    </script> 
    <script src="app.js">
    </script>
</body>
</html>
            
          
!
            
              .avatar{

	height: 60px;
	width:60px;
	border-radius: 45%;
	padding: 0px;
	margin: 0px;
	border : 0px;
}
.avatar img{
	height: 60px;
	width:60px;
	border-radius: 45%;
	padding: 10px;
	margin: 0px;
	border : 0px;
}

.screenname{
	padding: 1em 0em 0em 4em;
}
.description{
	margin:  5px 5px 5px 5px;
	padding: 1.3em 0em 0em 4em;
}
body{
	background-color: #cbd6de;
}
div{
	
}
.row{
	border: 3px solid #b4b9bd;
}
.results{
	background-color: #cfd9df;
}

            
          
!
            
              //Thanks http://stackoverflow.com/questions/1093568/scope-problem-with-nested-getjson


var streams = ["OgamingSC2","ESL_SC2","freecodecamp", "storbeck", "terakilobyte", "habathcx","RobotCaleb","thomasballinger","noobs2ninjas","beohoff", "brunofin", "comster404"];
var i = 0;
var gotStream,
	gotChannel,
	streamData,
	channelData;
var twitchRow = {
	image : 'https://placekitten.com/40/40',
	title : 'Title goes here',
	description : 'description goes here',
	online : '"https://api.twitch.tv/"',
};

function getData(stream){

	
	gotStream = false;
	gotChannel = false;
	$.getJSON('https://api.twitch.tv/kraken/streams/'+ streams[i] +'?callback=?', haveStream );
    $.getJSON('https://api.twitch.tv/kraken/channels/'+ streams[i] +'?callback=?', haveChannel);
    
}

function haveStream(data){
	streamData = data;
	gotStream = true;
	console.log('gotStream');
	if (gotChannel){
		makeRowData();
	}
}
function haveChannel(data){
	channelData = data;
	gotChannel = true;
	console.log('gotChannel');
	if (gotStream){
		makeRowData();
	}
}

function makeRowData(){
	
	console.log(streamData + channelData);
	twitchRow.title = streams[i];
	
	if (channelData.error){
		twitchRow.image = '<img src = "https://placekitten.com/140/140">';
		twitchRow.description = 'Not a valid channel';
		console.log(channelData.error + channelData.status + channelData.message);
		
	} else {
		
		if (channelData.logo == null){
						twitchRow.image = '<img src = "https://placekitten.com/140/140">';
					}else {
						twitchRow.image = '<img src = "' + channelData.logo +'">';
					}
		if (streamData.stream === null){
				twitchRow.description = 'Station Offline';
				console.log(' inside null' + ' ' + twitchRow.title +' ' + twitchRow.description);
			}else {
				//if (data.stream.game == true){
					twitchRow.description = streamData.stream.game + ' -- ' + streamData.stream.channel.status;
					console.log(' inside stream' + ' ' + twitchRow.title +' ' + twitchRow.description);
		}
	}
	makeRow(twitchRow.image, twitchRow.title, twitchRow.description);
	
}

function makeRow(image, title, description){
	//function to append rows to results div
	$('#results').append('<div class = "row"><div class = "col-sm-1 col-xs-3 avatar">'+
	image + '</div><div class = "col-sm-3 col-xs-9 screenname"><h4>' + title + '</h4></div><div class = "col-sm-8 col-xs-12 description">'+ description + '</div>');
	i = i + 1;
	console.log('i is incremented' + i);
	if (i < streams.length){
		getData(streams[i]);
		console.log('hereiam')
	}
}
getData(streams[i]);
            
          
!
999px
Loading ..................

Console