HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="container">
<div id="pageOne" class="text-center">
<h1>Use the TwitchTV JSON API</h1>
<h2>A FreeCodeCamp Exercise</h2>
</div>
<div class="channelHeaders row text-center">
<div class="col-xs-2">
<h2 class="header">Logo:</h2>
</div>
<div class="col-xs-2">
<h2 class="header">Display Name:</h2>
</div>
<div class="col-xs-2">
<h2 class="header">Status:</h2>
</div>
<div class="col-xs-2">
<h2 class="header">Follower Of:</h2>
</div>
</div>
<div id="followerInfo">
<!--<button id="test">Test Button</button>-->
</div>
</div>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
button{
width: 180px;
}
.header {
font-size: 1.5em;
}
.textCol{
font-size: 1em;
word-wrap: break-word;
}
.logo{
max-width: 70px;
max-height: 70px;
border-radius: 50%;
}
.channelRow{
border: 1px solid #000;
text-align: center;
padding: 20px;
}
.textCol{
padding: 10px;
}
img{
size: 50%;
}
.statusColumn{
color: blue;
}
$(document).ready(function(){
// Set variables used for API calls:
var url1="https://wind-bow.gomix.me/twitch-api/streams/freecodecamp?callback=?";
var twitchApiUrl = "https://api.twitch.tv/kraken"
var clientID = "gdlz2qp4towqgesit6f8qxk2s89ap5";
// Set starting list of streamers:
var streamers = ['freecodecamp', 'bmkibler', 'Savjz', 'WowHobbs']
// Initialize variables used in other functions:
var followersListing = {};
var channelName = "";
var channelStatus = "";
var channelLogo = "";
// function called to create a row for each streamer displayed.
// It first sets placeholder values for Logo and Status values and places two buttons.
function createRow(streamer, following){
$('#followerInfo').append("<div id = '" + streamer + "row' class = 'row channelRow'><div class='col-xs-2 logodiv'>Logo Goes Here</div><div class='col-xs-2 textCol'>" + streamer + "</div><div class='col-xs-2 statusColumn textCol'>Status Goes Here</div><div class='col-xs-2 textCol'>" + following + "</div><div class='col-xs-2 textCol'><button class='addFollowedChannels'>Add 5 Followed Channels</button><button class='hideChannel'>Hide Channel</button></div>");
}
//function called to update status information for each Streamer row. It is called by the checkOnlineStatus function.
function updateStreamerStatus(streamer, status, game, viewers){
if(status==="offline"){
$("#" + streamer + "row div:nth-child(3)").html("<a href='https://www.twitch.tv/"+streamer+"'rel='noopener noreferrer' target='_blank'>"+status+"</a>");
} else {
$("#" + streamer + "row div:nth-child(3)").html("<a href='https://www.twitch.tv/"+streamer+"'rel='noopener noreferrer' target='_blank'>"+status+"</a> <p>game:" +game+" </p><p>viewers: "+viewers+"</p>");
}
}
// function called to add the streamer's logo to the Streamer row. It is called by the getChannelInfo function.
function addStreamerLogo(streamer, logo){
$("#" + streamer + "row div:nth-child(1)").html("<img src='" + logo + "' class='logo'>");
}
// function called to add the streamer's display name to the Streamer row. It is called by the getChannelInfo function.
function addStreamerDisplayName(streamer, displayName){
$("#" + streamer + "row div:nth-child(2)").html(displayName);
}
// function called to add an array of followers to the object that tracks followers needing to be added to the page.
function addFollowersToListing(streamer, followers){
followersListing[streamer] = followers;
}
// function that makes a call to the Twitch API to check a streamer's status. If the streamer is online, the function collects information about the game played and the number of viewers. It then uses this information to call the updateStreamerStatus function. It is called by the addStreamerInfo function.
function checkOnlineStatus(streamer){
var checkOnlineUrl = twitchApiUrl + "/streams/" + streamer;
var status = "";
var game = "";
var viewers = null;
$.ajax({
type:"GET",
url:checkOnlineUrl,
headers:{
'Client-ID': clientID
},
success: function(streamData){
console.log(streamData);
if(streamData.stream===null){
status = "offline";
} else {
status = "online";
game = streamData.stream.game;
viewers = streamData.stream.viewers;
}
updateStreamerStatus(streamer, status, game, viewers);
}
})
}
// function that gets logo and display_name information for each streamer. It is called by the addStreamerInfo function.
function getChannelInfo(streamer) {
var channelInfoUrl = twitchApiUrl + "/channels/" + streamer;
$.ajax({
type:"GET",
url:channelInfoUrl,
headers:{
'Client-ID': clientID
},
success: function(channelData) {
addStreamerLogo(streamer, channelData.logo);
addStreamerDisplayName(streamer, channelData.display_name);
}
})
}
// master function that calls other functions for each streamer to be added - first createRow to create a row for the streamer; then checkOnlineStatus to collect additional information if the stremaer is online; then getChannelInfo to collect logo and display_name information. It is called by the document.ready() function as well as by the addFiveFollowers function.
function addStreamerInfo(streamer, followedBy){
createRow(streamer, followedBy);
checkOnlineStatus(streamer);
getChannelInfo(streamer);
}
// function that adds streamer information for five of the followers in the array of followers associated with a particular streamer. It is called by the getListOfFollowers function.
function addFiveFollowers(streamer){
for(var i=0; i<5; i++){
addStreamerInfo(followersListing[streamer].pop(), streamer);
}
}
// function that makes a call to the Twitch API to get the list of followers for a particular streamer. If the call is successful, it checks to see if the list of followers has already been added to the followersListing object for that streamer. If it has, then it calls addFiveFollowers for that streamer. If it has not, then it adds all followers for that streamer to the followersListing object. It is called by the Add 5 Followed Channels button.
function getListOfFollowers(streamer){
var getFollowersUrl = twitchApiUrl + "/users/" + streamer + "/follows/channels/";
$.ajax({
type:"GET",
url:getFollowersUrl,
headers:{
'Client-ID': clientID
},
success: function(followersData){
if(followersListing.hasOwnProperty(streamer)){
console.log("We already have a list here");
addFiveFollowers(streamer);
} else {
var followersList = [];
for(var i=0;i<followersData.follows.length;i++){
followersList.push(followersData.follows[i].channel.display_name);
}
addFollowersToListing(streamer, followersList);
console.log(followersListing);
addFiveFollowers(streamer);
}
}
})
}
// Initializes the page by calling addStreamerInfo for the starting list of streamers.
for(var i = 0; i<streamers.length; i++){
addStreamerInfo(streamers[i], "N/A");
}
$("body").on("click", ".addFollowedChannels", function(){
var displayName = $(this).parent().prev().prev().prev().text();
getListOfFollowers(displayName);
});
$('body').on("click", ".hideChannel", function(){
$(this).parent().parent().hide();
});
});
Also see: Tab Triggers