JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
.container
h1 FCC on Twitch.TV
.ui.top.attached.tabular.menu
a(data-tab="first").item.active#all All Users
a(data-tab="second").item#online Online
a(data-tab="third").item#offline Offline
.ui.bottom.attached.active.tab.segment(data-tab="first")#tab-one
.ui.centered.link.cards#all-users
.ui.bottom.attached.tab.segment(data-tab="second")#tab-two
.ui.centered.link.cards#online-users
.ui.bottom.attached.tab.segment(data-tab="third")#tab-three
.ui.centered.link.cards#offline-users
body
color #6441A5
padding 4em
a
text-decoration none
.container
margin 0 auto
width 80%
h1
text-align center
font 300 3em 'Open Sans'
#all,
#online,
#offline
&:hover
cursor pointer
$ ->
## Array of Free Code Camp channels on Twitch.TV
channels = [
"ESL_SC2",
"OgamingSC2",
"cretetion",
"freecodecamp",
"storbeck",
"habathcx",
"RobotCaleb",
"noobs2ninjas"
]
## Call on the Twitch.TV API to retrieve channel information
twitchChannels = ->
baseURL = 'https://wind-bow.gomix.me/twitch-api'
## Twitch.TV API channel call
twitchChannelsURL = baseURL + '/channels/'
## Iterate over each channel
$.each channels, (key, value) ->
## For each channel make an API call
$.ajax
dataType: 'jsonp'
url: twitchChannelsURL + value
crossDomain: true
success: (data) ->
## Channel data
name = data.display_name
description = data.game
logo = data.logo
url = data.url
views = data.views
followers = data.followers
status = data.status
## Set of default values if certain data is not available
if logo == null
logo = 'https://unsplash.it/500?image=0'
if description == null
description = 'Programming'
if status == 422
description = 'No longer a user on Twitch.tv'
name = value
logo = 'https://unsplash.it/500?image=0&blur'
followers = ''
views = ''
url = '#'
## For each channel create a card that includes the data retreived
$('#all-users')
.append '<div class="card" id='+name+'>
<a class="image" href='+url+' target="_blank">
<img src='+logo+' >
</a>
<div class="content">
<div class="header">'+name+'</div>
<div class="description">
'+description+'
</div>
</div>
<div class="extra content">
<i class="unhide icon"></i>
'+views+'
<i class="user icon"></i>
'+followers+'
</div>
</div>'
return
return
return
## Use the Twitch.TV streams API to check whether the channel is live
twitchStreams = ->
## Twitch.TV API streams call
twitchStreamsURL = 'https://api.twitch.tv/kraken/streams/'
## Iterate over each channel
$.each channels, (key, value) ->
## For each channel make an API Call
$.ajax
dataType: 'jsonp'
url: twitchStreamsURL + value
crossDomain: true
success: (data) ->
## Stream data
if data['stream'] == null
$('#'+value).addClass 'red'
$('#'+value).clone().appendTo $('#offline-users')
return
else if data.status == 422
$('#'+value).addClass 'yellow'
return
else
$('#'+value).addClass 'green'
$('#'+value).clone().appendTo $('#online-users')
$('#'+value+' .description')
.replaceWith('<div class="description">' + data.stream.channel.status + '</div>')
return
return
## Tabs
tabs = ->
allTab = ->
$('#all').click ->
$('#all').addClass 'active'
$('#offline').removeClass 'active'
$('#online').removeClass 'active'
$('#tab-one').addClass 'active'
$('#tab-two').removeClass 'active'
$('#tab-three').removeClass 'active'
return
return
onlineTab = ->
$('#online').click ->
$('#online').addClass 'active'
$('#all').removeClass 'active'
$('#offline').removeClass 'active'
$('#tab-one').removeClass 'active'
$('#tab-two').addClass 'active'
$('#tab-three').removeClass 'active'
return
return
offlineTab = ->
$('#offline').click ->
$('#offline').addClass 'active'
$('#all').removeClass 'active'
$('#online').removeClass 'active'
$('#tab-one').removeClass 'active'
$('#tab-two').removeClass 'active'
$('#tab-three').addClass 'active'
return
return
allTab()
onlineTab()
offlineTab()
twitchChannels()
twitchStreams()
tabs()
return
Also see: Tab Triggers