Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

              
                <html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Twitch App</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
</head>

<body>
    <div class="container border rounded">
       <h3 id="main-text">Twitch Streamers</h3>
        <div id="controls">            
            <form id="add-user">
                <input type="text" id="name" name="user" placeholder="Follow Streamer">
                <input type="submit" value="Follow" id="submit-btn">
            </form>
            
            <nav>
                <div class="nav nav-tabs" id="nav-tab" role="tablist">
                    <a class="nav-item nav-link active" id="all-tab" data-toggle="tab" role="tab">All</a>
                    <a class="nav-item nav-link" id="online-tab" data-toggle="tab" role="tab">Online</a>
                    <a class="nav-item nav-link" id="offline-tab" data-toggle="tab" role="tab">Offline</a>
                </div>
            </nav>
        </div>
        <ul id="users" class="list-unstyled">
        </ul>
    </div>
</body>

</html>

              
            
!

CSS

              
                body {
    background-color: #C7BDDE!important;
    min-width: 500px;
}

.container {
    background-color: #4B367C;
    margin: 5% 0;
    padding: 10px 0 !important;
}

#main-text{
    text-align: center;
    color: #D3CAE8;
}

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

.Online h5 {
    color: green;
}

.Offline h5 {
    color: grey;
}

.notFound h5 {
    color: red;
}

.media a {
    text-decoration: none;
    color: inherit;
}

.media a:hover {
    font-weight: bold;
}

.media {
    background: #17141F;
    color: #D3CAE8;
    padding: 10px;
    margin: 10px 10px;
}

.delete-div {
    position: relative;
}

.delete-icon {
    position: absolute;
    top: 2px;
    right: 2px;
    z-index: 100;
    color: grey;
}

.delete-icon:hover {
    color: red;
}

#controls{
    position: relative;
}

#add-user {
    position: absolute;
    right: 25px;
    margin: auto;
}

.nav {
    padding-left: 15px  !important;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.nav-item {
    text-decoration: none;
    color: #D3CAE8!important;
}

.nav-item:hover {
    color: #0E9BD8!important;
}

.active {
    background-color: #4B367C!important;
    color: #0E9BD8!important;
    border-bottom: none!important;
}

#submit-btn{
    background-color: #D3CAE8;
    color: #4B367C;
    border: 1px solid #D3CAE8;
}

#submit-btn:hover{
    background-color: #4B367C;
    color: #D3CAE8;
}
              
            
!

JS

              
                /* jshint browser:true */
/* jshint esnext:true */
/* jshint jquery:true */

"use strict";

const url = "https://wind-bow.glitch.me/twitch-api/";

const base_users = [
    "freecodecamp",
    "ESL_SC2",
    "OgamingSC2",
    "cretetion",
    "noobs2ninjas",
    "Blizzard"
];

$(document).ready(function() {
    var arr = JSON.parse(localStorage.getItem("arr"));

    //checks if the array is empty and gets the data
    if (arr === null) {
        //if array is empty sets the localstorage to the base user array
        localStorage.setItem("arr", JSON.stringify(base_users));
        arr = JSON.parse(localStorage.getItem("arr"));
        getData(arr);
    } else {
        getData(arr);
    }

    //Adds a new user to the array and refreshes the list
    $("#add-user").submit(function(e) {
        arr = JSON.parse(localStorage.getItem("arr"));
        var val = $("input#name")
            .val()
            .toLowerCase();
        $("input#name").val("");
        e.preventDefault();
        if ($.inArray(val, arr) == -1 && val !== "") {
            arr.push(val);
            $("#users").empty();
            getData(arr);
            localStorage.setItem("arr", JSON.stringify(arr));
        } else {
            $("#users").empty();
            getData(arr);
        }
    });

    //Shows or hides users
    $("#offline-tab").click(function() {
        $("#offline-tab").addClass("active");
        $("#online-tab").removeClass("active");
        $("#all-tab").removeClass("active");
        $(".Offline").show(300);
        $(".Online").hide(300);
        $(".notFound").hide(300);
    });
    $("#online-tab").click(function() {
        $("#offline-tab").removeClass("active");
        $("#online-tab").addClass("active");
        $("#all-tab").removeClass("active");
        $(".Offline").hide(300);
        $(".Online").show(300);
        $(".notFound").hide(300);
    });
    $("#all-tab").click(function() {
        $("#offline-tab").removeClass("active");
        $("#online-tab").removeClass("active");
        $("#all-tab").addClass("active");
        $(".Offline").show(300);
        $(".Online").show(300);
        $(".notFound").show(300);
    });
});

function getData(arr) {
    //Gets data from array
    $.each(arr, function(i, user) {
        $.ajax({
            method: "GET",
            url: url + "channels/" + user,
            dataType: "json"
        })
            .fail(function(error) {
                if (error) {
                    $("#users").append(`<li id="${user}" class="media notFound">
                                        <img class="mr-3 logo align-self-center">
                                        <div class="media-body">
                                            <div class="delete-div"><a onclick="deleteUser('${user}');" class="delete"><i class="fa fa-times delete-icon"></i></a></div>
                                            <h5 class="mt-0 mb-1"><a href="https://www.twitch.tv/${user}" target="blank">${user} - <span class="status">User not found!</span></a></h5>
                                            <p>${error.responseJSON.error}</p>
                                        </div>
                                    </li>`);
                    // $("#" + user).hide();
                }
            })
            .done(function(data) {
                if (data) {
                    //If user is found

                    $("#users").append(`<li id="${user}" class="media">
                                        <img class="mr-3 logo align-self-center" src="${
                                            data.logo
                                        }">
                                        <div class="media-body">
                                           <div class="delete-div"><a onclick="deleteUser('${user}');" class="delete"><i class="fa fa-times delete-icon"></i></a></div>
                                           <h5 class="mt-0 mb-1"> <a href="https://www.twitch.tv/${user}" target="blank">${
                        data.display_name
                    } - <span class="status"></span></a></h5>
                                           <p>${data.status}</p>
                                        </div>
                                    </li>`);
                    $("#" + user).hide();

                    if (data.status === null) {
                        //if user has no status
                        $("#" + user + " p").empty();
                    } //gets online and streamed game info
                    $.ajax({
                        method: "GET",
                        url: url + "streams/" + user,
                        dataType: "json"
                    }).done(function(data) {
                        if (data.stream === null) {
                            $("#" + user + " span.status").html("Offline");
                            $("#" + user).addClass("Offline");
                        } else {
                            $("#" + user + " span.status").html(
                                "Streaming: " + data.stream.game
                            );
                            $("#" + user).addClass("Online");
                        }
                    });
                }
                $("#" + user).show(300);
                if (user == "freecodecamp") {
                    //put in front if the user is freecodecamp
                    $("#" + user).prependTo("#users");
                    $("#" + user + " div.delete-div").empty();
                }
                $("#offline-tab").removeClass("active");
                $("#online-tab").removeClass("active");
                $("#all-tab").addClass("active");
            });
    });
}

function deleteUser(user) {
    //deletes user from array and refreshes user list
    var arr = JSON.parse(localStorage.getItem("arr"));
    var index = $.inArray(user, arr);
    if (index > -1) {
        arr.splice(index, 1);
    }
    $("#users").empty();
    getData(arr);
    localStorage.setItem("arr", JSON.stringify(arr));
}

              
            
!
999px

Console