LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Twitch.tv JSON API

All
Online
Offline
CSS
* {
  box-sizing: border-box;
}

body {
  background-color: black;
  font-size: 16px;
  line-height: 1.3;
}

h1 {
  text-align: center;
  margin: .5em 0;
  font-size: 2em;
}

a {
  text-decoration: none;
  transition: all .3s ease-out;
  color: #000;
}
a:hover {
  color: #303A52;
}

p {
  margin: 0;
}

.container {
  width: 80%;
  margin: 0 auto;
  background-color: #303A52;
  color: white;
  padding: 2em 0;
}

header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  text-align: center;
}

.all,
.online,
.offline {
  color: white;
  font-weight: bold;
  background-color: #574B90;
  transition: all .5s ease-out;
  cursor: pointer;
  padding: 1em 0;
}
.all:hover,
.online:hover,
.offline:hover {
  background-color: #433a6e;
}

.offlineUser {
  background-color: #EE2B47;
}

.onlineUser {
  background-color: #38817A;
}

.twitch {
  width: 100%;
  margin: 0 auto;
}
@media (min-width: 1024px) {
  .twitch {
    width: 60%;
  }
}
@media (min-width: 2200px) {
  .twitch {
    width: 40%;
  }
}

.twitchContent {
  padding: 2em;
  width: 100%;
  margin: 0 auto;
}

.search {
  text-align: center;
  margin-bottom: 1em;
}
.search #search {
  width: 70%;
  padding: 1em;
}
.search #submitSearch {
  padding: 1em;
  border: none;
  border-radius: 0;
  background-color: #574B90;
  transition: all .5s ease-out;
  color: white;
  cursor: pointer;
}
.search #submitSearch:hover {
  background-color: #4d427f;
}

.list .userContainer {
  width: 100%;
  color: black;
  padding: 1em 0;
  border-bottom: 5px dashed #303A52;
}
@media (min-width: 540px) {
  .list .userContainer {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 1em 0;
  }
}
.list .userContainer .users {
  width: 100%;
  display: block;
  margin: 0;
  padding: 0 .5em;
  text-align: center;
  list-style: none;
  line-height: 1.5;
}
@media (min-width: 540px) {
  .list .userContainer .users {
    width: 60%;
    text-align: left;
    padding: 0 1em;
  }
}
.list .userContainer .users .username {
  font-size: 1.5rem;
  font-weight: bold;
}
.list .userContainer .users .status {
  padding-bottom: 1em;
  font-weight: bold;
}
.list .userContainer .users .url {
  font-size: .9em;
}
@media (min-width: 540px) {
  .list .userContainer .users .url {
    font-size: .9em;
  }
}
.list .logo {
  width: 70%;
  margin: 0 auto;
  padding: 0 2em;
  list-style: none;
}
@media (min-width: 540px) {
  .list .logo {
    width: 30%;
  }
}
.list .logo a img {
  width: 100%;
  margin: 1em auto;
  display: block;
  transition: all .3s ease-out;
  border-radius: 100%;
}
.list .logo a img:hover {
  opacity: .7;
}
JS
// const fccStreamsUrl = 'https://wind-bow.glitch.me/twitch-api/streams/freecodecamp/?callback=?';
// const fccChannelUrl = 'https://wind-bow.glitch.me/twitch-api/channels/freecodecamp/?callback=?';

// ==== Users
const streamsUrl = 'https://wind-bow.glitch.me/twitch-api/streams/';
const channelUrl = 'https://wind-bow.glitch.me/twitch-api/channels/';


let users = ['ESL_SC2', 'OgamingSC2', 'RobotCaleb', 'cretetion','storbeck', 'habathcx', 'capnjacksparo', 'bdoom', 'callowcreation', 'melanieplaysx', 'FreeCodeCamp', 'darkxangel84'];

// // ===== Checking to see if FreeCodeCamp is Online! ======
//  $.getJSON(fccStreamsUrl, function(data){
// 	let status, game;
// 	if(data.stream === null) {
// 		// ===== Free Code Camp is Offline =====
// 		//console.log('FreeCodeCamp is offline');
// 		status = "Offline";
// 	} else if (data.stream === undefined) {
// 		// ===== Free Code Camp is Offline =====
//        game = "Account Closed";
//        status = "Offline";
//       } else {
// 			// ===== Free Code Camp is Online ======
// 			status = "Online";
//       };
// 	 $.getJSON(fccChannelUrl, function(data2){
		 
// 		   let name = data2.name;
// 		  	status = status;
// 		  	let playingStatus = data2.status;
// 		 	let logo = data2.logo != null ? data2.logo : "https://dummyimage.com/50x50/ecf0e7/5c5457.jpg&text=0x3F";
// 		  	let url = data2.url;
			
// 			$('.list').append(`
//
    //
  • ${name}
  • //
  • Status: ${status}
  • //
  • ${url}
  • //
//
`); // }) // ==== end of JSON call to channel // }) // ==== end of JSON call to Streams // ===== Getting other users streams for(let i = 0; i < users.length; i++) { let streams = `https://wind-bow.glitch.me/twitch-api/streams/${users[i]}/?callback=?`; let channel = `https://wind-bow.glitch.me/twitch-api/channels/${users[i]}/?callback=?`; // you can only use the data inside the done() handler, // when the call has completed and the data is returned $.getJSON(streams, function(data){ let status, game,live; console.log(data) if(data.stream === null) { //console.log('users offline'); status = "Offline"; } else if (data.stream === undefined) { // ==== if Account is closed! ===== game = "Account Closed"; status = "Offline"; } else { // ===== Users Online ==== //console.log('users online'); live = data.stream.stream_type.toUpperCase(); status = "Online"; }; $.getJSON(channel, function(data2){ // console.log(data2) let name = status != 'Offline' ? data2.display_name : data2.display_name; status = status; let playingStatus = data2.status; let game = data2.game; let logo = data2.logo != null ? data2.logo : "https://dummyimage.com/50x50/ecf0e7/5c5457.jpg&text=0x3F"; let url = data2.url; if(status === 'Offline'){ $('.list').append(`
`); } else if (status === 'Online') { $('.list').append(`
  • ${name}
  • Status: ${status} / ${live}
  • Game Playing: ${game}
  • Playing Status: ${playingStatus}
`); } else { console.log('Error'); } }) // end of JSON call to channel }) // end of JSON call to Streams } // end of for loop $('.online').on('click', function(){ $('.onlineUser.userContainer').show(); $('.offlineUser.userContainer').hide(); }); $('.offline').on('click', function(){ $('.onlineUser.userContainer').hide(); $('.offlineUser.userContainer').show(); }); $('.all').on('click', function(){ $('.onlineUser.userContainer').show(); $('.offlineUser.userContainer').show(); });

Description

Free Code Camp Project, using the Twitchtv API, to show who's online, offline from a bunch of selected channels.
Term
Wed, 12/27/2017 - 06:58

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv