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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

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.

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

              
                           <div class="header">
            <h1>TWITCH STREAM-FEED</h1>
            <div class="sortDashWrapper">
                <div class="sortDash">
                   <button class="sort online">Online</button>
                   <button class="sort offline">Offline</button>
                   <button class="sort all">All</button>
               </div>
                
            </div>
     
       
        </div>
        
            
       
    <div class="container">
        <div class="main">
              <div class="title title-user">Username</div>
              <div class="title title-status">Status</div>
              <div class="title title-game">Game</div>
              <div class="title title-viewers">Viewers</div>


        </div>
    </div>
    
              
            
!

CSS

              
                /* purple: #483978 
    light gray: #F7F7F7
    white, black
*/

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%
}

body {
    font-family: 'Staatliches', cursive;
    height: 100%;
    width: 100%;
    background-color: #F2F0F4;
    min-width: 200px;

}

.header {
    width: 100%;
    background-color: #483978;
    color: white;
    padding: 1rem;
    text-align: center;
    font-size: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 1px black solid
}

.sortDashWrapper {
    display: flex;
    justify-content: center;
}

.sortDash {
    padding: 1rem 0;
    display: flex;
    justify-content: center;
    border-radius: 2rem;
    width: 50%
}

.sort {
    min-width: 80px;
    margin: 0 .5rem;
    padding: .5rem;
    width: 5rem;
    border: 3px #F0EBFD solid;
    border-radius: 1rem;
    font-weight: bold;
    cursor: pointer;
}

.sort:hover {
    transform: scale(1.1);
    background-color: #483978;
    color: white;
}

.container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 5rem;
    /*min-width: 28.75rem*/
}

.main {
    background-color: #F7F7F7;
    display: grid;
    grid-template-columns: auto auto auto auto;
    grid-template-rows: repeat(9, auto);
    grid-template-areas: "title-user title-status title-game title-viewers "
                         "user-name user-status user-game user-viewers"
                         "user-name user-status user-game user-viewers"
                         "user-name user-status user-game user-viewers"
                         "user-name user-status user-game user-viewers"
                         "user-name user-status user-game user-viewers"
                         "user-name user-status user-game user-viewers"
                         "user-name user-status user-game user-viewers"
                         "user-name user-status user-game user-viewers";
    grid-row-gap: .5rem;
    grid-column-gap: 1rem;
    width: 95%;
    padding: 1rem;
    border: black .5px solid;
    font-size: 1.5rem
}


.title {
    border-bottom: .1px black solid
}

.title-user{
    grid-area: title-user
}

.title-status {
    grid-area: title-status
}

.title-game {
    grid-area: title-game
}

.title-viewers {
    grid-area: title-viewers
    
}


.user-name {
    display: flex;
    flex-direction: column;
    
}

.user-status {
    display: flex;
    flex-direction: column;
}

.user-game {
    display: flex;
    flex-direction: column;
}

.user-viewers {
    display: flex;
    flex-direction: column
}

@media (max-width: 460px){
    .main {
        font-size: 1.3rem;
    }
}

@media (max-width: 405px){
    .main {
        font-size: 1.1rem;
    }
}

@media (max-width: 360px){
    .main {
        font-size: .9rem;
    }
}

@media (max-width: 300px){
    .main {
        font-size: .7rem;
    }
}

              
            
!

JS

              
                // VARIABLES
let userIcon = document.querySelector('.user-icon')
let userName = document.querySelector('.user-name')
let userStatus = document.querySelector('.user-status')
let userGame = document.querySelector('.user-game')
let userViewers = document.querySelector('.user-viewers')

let sortOnline = document.querySelector('.online')
let sortOffline = document.querySelector('.offline')
let sortAll = document.querySelector('.all')
let main = document.querySelector('.main')

let user_name, user_status, user_game, user_viewers;
        
let twitchUsers = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"]

let user;

async function getTwitchStreams(){
    const response = await fetch(`https://wind-bow.glitch.me/twitch-api/streams/${user}`)
    const data = await response.json()
    return data
}

function renderAllUserData(){
    
    for (let i = 0 ; i < twitchUsers.length; i++){
        user = twitchUsers[i]

        getTwitchStreams().then((data)=>{
            console.log(data)

            user_name = data._links.channel.substring(38)

            if (data.stream === null){
                user_status = 'Offline'
                user_game = '---'
                user_viewers = '---'

            } else {
                user_status = 'Online'
                user_game = data.stream.game
                user_viewers = data.stream.viewers
            }

            main.insertAdjacentHTML('beforeend', `<a href="https://www.twitch.tv/${data._links.channel.substring(38)}" target="blank"> <div class="user-name">${user_name}</div></a><div class="user-status">${user_status}</div><div class="user-game">${user_game}</div><div class="user-viewers">${user_viewers}</div>`)

            
            let userData = [...main.children]
            
            for (let i = 0 ; i < userData.length; i++){
                if (userData[i].className === 'user-status' && userData[i].textContent === 'Online'){
                    userData[i].style.color = 'Green'
                } else if (userData[i].className === 'user-status' && userData[i].textContent === 'Offline'){
                    userData[i].style.color = 'Red'
                }
            }
        })
    }   
}

renderAllUserData()

sortOnline.addEventListener('click', (e)=>{
    main.textContent = ''
    
    for (let i = 0 ; i < twitchUsers.length; i++){
    user = twitchUsers[i]
    
        getTwitchStreams().then((data)=>{
            if (data.stream !== null){
                user_name = data._links.channel.substring(38)

                user_status = 'Online'
                user_game = data.stream.game
                user_viewers = data.stream.viewers

                main.insertAdjacentHTML('beforeend', `<a href="https://www.twitch.tv/${data._links.channel.substring(38)}" target="blank"> <div class="user-name">${user_name}</div></a><div class="user-status">${user_status}</div><div class="user-game">${user_game}</div><div class="user-viewers">${user_viewers}</div>`)
                
                let userData = [...main.children]
            
                for (let i = 0 ; i < userData.length; i++){
                    if (userData[i].className === 'user-status' && userData[i].textContent === 'Online'){
                        userData[i].style.color = 'Green'
                    } else if (userData[i].className === 'user-status' && userData[i].textContent === 'Offline'){
                        userData[i].style.color = 'Red'
                    }
                }
            }
        })
    }
})

sortOffline.addEventListener('click', (e)=>{
    main.textContent = ''
    
    for (let i = 0 ; i < twitchUsers.length; i++){
    user = twitchUsers[i]
    
        getTwitchStreams().then((data)=>{
            if (data.stream === null){
                user_name = data._links.channel.substring(38)

                user_status = 'Offline'
                user_game = '---'
                user_viewers = '---'

                main.insertAdjacentHTML('beforeend', `<a href="https://www.twitch.tv/${data._links.channel.substring(38)}" target="blank"> <div class="user-name">${user_name}</div></a><div class="user-status">${user_status}</div><div class="user-game">${user_game}</div><div class="user-viewers">${user_viewers}</div>`)
                
                let userData = [...main.children]
            
                for (let i = 0 ; i < userData.length; i++){
                    if (userData[i].className === 'user-status' && userData[i].textContent === 'Online'){
                        userData[i].style.color = 'Green'
                    } else if (userData[i].className === 'user-status' && userData[i].textContent === 'Offline'){
                        userData[i].style.color = 'Red'
                    }
                }
            }
        })
    }
})

sortAll.addEventListener('click', (e)=>{
    main.textContent = ''
    renderAllUserData()
})


              
            
!
999px

Console