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.

            
              <html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Twitch TV API</title>
    <link rel="stylesheet" href="twitchCSS.css">
    <link href="https://fonts.googleapis.com/css?family=Barlow+Condensed" rel="stylesheet">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div><!--whole box-->

    <div class="container jumbotron" id="topPart">
        <h1>
            <img id="twitchIcon" src="https://cdn1.iconfinder.com/data/icons/simple-icons/4096/twitch-4096-black.png">
            Twitch Streamers
        </h1>
    </div>

    <div class="container">
        <div id="status" class="row"> <!--filters all, online, or offline?-->
            <button id="all" class="col-xs-4 btn btn-default">ALL
            </button>
            <button id="online" class="col-xs-4 btn btn-default">ONLINE
            </button>
            <button id="offline" class="col-xs-4 btn btn-default">OFFLINE
            </button>
        </div>
    </div>


    <div class="container">
        <div id="userInfo2"> <!-- user info from left to right including icon, username, and title of stream -->


        </div>
    </div>
    <div class="container">
        <div id="userInfo"> <!-- user info from left to right including icon, username, and title of stream -->


        </div>
    </div>


</div>


<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="twitchJS2.js"></script>
</body>
</html>
            
          
!
            
              html{
    height: 100%;
}

body{
    text-align: center;
    background: linear-gradient(#9e70ff, #9e70ff);
}
#twitchIcon{
    height: 35%;
    width: 35%;
}

#status{

}

#topPart{
    padding-left: 15%;
    padding-right: 15%;
    margin-bottom: 0;
    background: #b067e0;
    color: white;
    font-family: 'Barlow Condensed', sans-serif;
}

#online,
#all,
#offline
{
    background: #9b18f2;
    color: white;
    border: none;
    font-family: 'Barlow Condensed', sans-serif;
}
#online:hover,
#all:hover,
#offline:hover{
    background: #cd82ff;
}

#status{
    background: #9b18f2;
}

#userInfo{
    background: #fcdcff;
    font-family: 'Barlow Condensed', sans-serif;
}
#userInfo2{
    background: #fcdcff;
    font-family: 'Barlow Condensed', sans-serif;
}

.userInfoBackground{
    background: #fcdcff;
    border: .5px solid #a418ff;

}

.userName{
    height: 50px;
    padding-top: 5px;
    font-weight: bold;
    font-size: 25px;
}

.image{
    width: 50px;

}

.image{
    width: 50px;
    height: 50px;
}

.title{
    height: 50px;
    padding-top: 5px;
    font-weight: bold;
    font-size: 25px;
}

            
          
!
            
              //this link gives us the list of people who freecodecamp is following
var urlFollows = "https://api.twitch.tv/kraken/channels/freecodecamp/follows?client_id=epbr8ttvcdj3ox68n97j6q4u20jqyd";


//this array will hold the json object of the users freecodecamp is following
//it will hold information like display name and logo link
var followingsObjectArray = [];
//this array will get the display names from the followingsObjectArray
var userNames = [];
//this array will get the icon links from the followingsObjectArray
var userIcons = [];
//this array will get us the title of their stream if they're online,
//if offline, we display "offline"
var userStatus = [];


//===========================================================================================//
/*
These following methods will fill the userNames, userIcons, linkArray and userStatus arrays
We use the getFollowsInfo() method to get the usernames and links to the icons of the users whom freecodecamp is following
in that same mathod, we will call the getFollowsStatusURL() method, which will get the streamURL of each user in the userNames array
That method will call getFollowingsStatus() method which will give us the array that will tell us whether user is online or offline
 */

function getFollowsInfo() {
    $.getJSON(urlFollows, function (result) {
        //console.log(result + "test");
        //console.log(result.follows[1].user + "test");

        for (var i = 0; i < result.follows.length; i++) {
            followingsObjectArray[i] = result.follows[i].user;
            userNames[i] = followingsObjectArray[i].display_name;
            userIcons[i] = followingsObjectArray[i].logo;
            userStatus[i] = getFollowsStatusURL(userNames[i]);
            //console.log(userNames[i] + " " + userIcons[i]);
            placeInfo(userNames[i], userStatus[i], userIcons[i]);
        }


    });

}


//this function gets the array of urls to each followings with their status, whether offline or online
function getFollowsStatusURL(nameList) {
    //create array of links for each user that freecodecamp is following
    //then get the json to using streams url in order to get whether they're online or offline
    //then get the title of the stream if they're online
    var link1 = "https://api.twitch.tv/kraken/streams/";
    var link2 = "?client_id=epbr8ttvcdj3ox68n97j6q4u20jqyd";


    var url = link1 + nameList + link2;

    $.getJSON(url, function (result) {

        if(result.stream === null || result.stream === undefined){
            return "FALSE";
        }
        else{
            return result.stream;
        }

    });
}


function placeInfo(name, status, icon) {

    //for(var i = 0; i < userNames.length; i++){

    $("#userInfo").append(
        "<div class='row userInfoBackground'>"+
        "<span class='col-xs-4 userName'>"+
        name+
        "</span>"+
        "<span class='col-xs-4 title'>"+
        status+
        "</span>"+
        "<span class='col-xs-4'>"+
        "<img class='image' src='" + icon + "'>"+
        "</span>"+
        "</div>"
    );
    //}
}

getFollowsInfo();

            
          
!
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