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

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.

            
              <div class="stream">
	<h2 class="channel"></h2>
	<div class="viewers"><span class="count"></span></div>
	<h1 class="title"></h1>
	<img class="thumb" />
</div>
            
          
!
            
              html {
	height: 100%;
}
body {
	min-height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #6441A4;
	font-family: 'Open Sans', sans-serif;
	font-weight: 300;
	background-image: url('data:image/svg+xml,%3Csvg width="64" height="64" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg"%3E%3Cpath d="M8 16c4.418 0 8-3.582 8-8s-3.582-8-8-8-8 3.582-8 8 3.582 8 8 8zm0-2c3.314 0 6-2.686 6-6s-2.686-6-6-6-6 2.686-6 6 2.686 6 6 6zm33.414-6l5.95-5.95L45.95.636 40 6.586 34.05.636 32.636 2.05 38.586 8l-5.95 5.95 1.414 1.414L40 9.414l5.95 5.95 1.414-1.414L41.414 8zM40 48c4.418 0 8-3.582 8-8s-3.582-8-8-8-8 3.582-8 8 3.582 8 8 8zm0-2c3.314 0 6-2.686 6-6s-2.686-6-6-6-6 2.686-6 6 2.686 6 6 6zM9.414 40l5.95-5.95-1.414-1.414L8 38.586l-5.95-5.95L.636 34.05 6.586 40l-5.95 5.95 1.414 1.414L8 41.414l5.95 5.95 1.414-1.414L9.414 40z" fill="%239C92AC" fill-opacity="0.4" fill-rule="evenodd"/%3E%3C/svg%3E');
}

.stream {
	display: grid;
	grid-template-areas: 
		"channel viewers"
		"title title"
		"image image";
	grid-template-columns: auto auto;
	grid-template-rows: auto auto auto;
	position: relative;
	overflow: hidden;
	width: 100%;
	min-width: 360px;
	max-width: 480px;
	height: auto;
	background: white;
	box-shadow: 0 2px 5px rgba(0,0,0,0.5);
	border-radius: 5px;
	margin: 1rem;
	.channel, .title, .viewers {
		position: relative;
		z-index: 1;
		margin: 1rem;
	}
	.thumb {
		grid-area: image;
		width: 100%;
	}
	.channel {
		display: flex;
		justify-content: flex-start;
		align-content: center;
		grid-area: channel;
		font-size: 0.75rem;
		margin-bottom: 0;
		&::before {
			content: '\f007';
			font-family: "FontAwesome";
			display: block;
			height: 0.75rem;
			width: 0.75rem;
			margin-right: 0.35rem;
		}
	}
	.viewers {
		display: flex;
		grid-area: viewers;
		align-content: center;
		justify-content: flex-end;
		font-size: 0.75rem;
		margin-bottom: 0;
		z-index: 1;
		&::before {
			content: '';
			display: block;
			background: #e84c3d;
			height: 0.75rem;
			width: 0.75rem;
			border-radius: 50%;
			margin-right: 0.35rem;
			box-shadow: 0 0 0 0 rgba(232, 76, 61, 0.7);
			animation: pulse 1.25s infinite cubic-bezier(0.66, 0, 0, 1);
			z-index: 0;
		}
		.count {
			font-weight: bold;
		}
	}
	.title {
		font-family: 'Open Sans', cursive;
		font-size: 2rem;
		font-weight: bold;
		max-width: 100%;
		grid-area: title;
		border-top: 1px solid rgba(0,0,0,0.25);
		padding-top: 0.5rem
	}
}

@keyframes pulse {to {box-shadow: 0 0 0 5px rgba(232, 76, 61, 0);}}
            
          
!
            
              // I'm still in the process of learning how to use API's and the Async/Await syntax, so any tips/criticism is appreciated! If there is something I could have done better, or another way feel free to inform me. I'm always open to learning more.

// if response is an empty data arry change to a live streamer. The empty data arry is a response to be able to tell if a streamer is online or offline currently

const userLogin = 'imaqtpie'; // twitch username

// Obtain a unique ClientID at: https://dev.twitch.tv/dashboard
// Register a new app to get your own as response limits are ~120/minute
const clientID = 'ublgcyvjt61jbopxzjerg1k6uh730o';

// reference here for more information: https://dev.twitch.tv/docs/api/reference#get-streams
const endpoint = 'https://api.twitch.tv/helix/streams?user_login=' + userLogin;

// create a function that utilizes async
const request = async () => {
	// start the resposne
	// client-id header is required in order to receive a response from the api
	const response = await fetch(endpoint, { headers: { 'Client-ID': clientID } });
	// take response and convert to json
	const json = await response.json();
	// store json in a variable
	const streamData = await json.data;

	// 	loop through data
	for (const streamInfo of streamData) {
		// add viewerCount to variable
		let viewerCount = streamInfo.viewer_count;
		// use toLocalString to convert viewerCount int to string with commas
		viewerCount = viewerCount.toLocaleString();
		
		// add thumbnail url to let variable
		let thumb = streamInfo.thumbnail_url;
		// replace thumb {width} and {height} to values
		thumb = thumb.replace('{width}', 1920).replace('{height}', 1080);
		
		// add data to DOM
		document.querySelector('.title').innerHTML = streamInfo.title;
		document.querySelector('.count').innerHTML = viewerCount;
		document.querySelector('.channel').innerHTML = userLogin;
		document.querySelector('.thumb').setAttribute('src', thumb);
	}
}

// run the request function
request();
            
          
!
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