FreeCodeCamp : Use the Twitchtv JSON API

What is a freecodecamp : use the twitchtv json api How do you make a freecodecamp : use the twitchtv json api? This script and codes were developed by Markku Lehmonen on 03 February 2022, Thursday.

How do I make an freecodecamp : use the twitchtv json api?
  1. FreeCodeCamp : Use the Twitchtv JSON API Previews
  2. FreeCodeCamp : Use the Twitchtv JSON API HTML Codes
  3. FreeCodeCamp : Use the Twitchtv JSON API CSS Codes
  4. FreeCodeCamp : Use the Twitchtv JSON API JS Codes
FreeCodeCamp : Use the Twitchtv JSON API Previews

FreeCodeCamp : Use the Twitchtv JSON API HTML Codes

<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>FreeCodeCamp : Use the Twitchtv JSON API</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>
  <h1>Twitch Stream Magic</h1>
<div id="streamContainerOnline">
</div>
<div id="streamContainer">
  <div id="streamItemPrefab" class="streamItem">
    <a href="" class="streamLink"><img class="streamAvatar" src="https://tinyurl.com/jf9uu7d" alt="Image Placeholder" width="100" height="100"/></a>
    <div class="streamInfo">
      <a href="" class="streamLink"><h2><span class="streamName"></span></a> <small class="streamStatus"></small></h2>
      <h3 class="streamTopic"></h3>
      <h3 class="streamActivity"><small class="label"></small> <span class="streamCategory"></span></h3>
    </div>
  </div>
</div>
<div id="streamContainerDeleted">  
</div>
<!--<div id="testOutput">testOutput</div>-->
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>

    <script src="js/index.js"></script>

</body>
</html>

FreeCodeCamp : Use the Twitchtv JSON API CSS Codes

body {font-family:Calibri; text-align:center;}
h1 {text-transform:uppercase;}
h2, h3 {margin:0px;}
/* unvisited link */
img {border:4px solid white; border-radius:4px;}
img:hover {border:4px solid orange;}
.streamContainer:hover, .streamContainerOnline:hover {opacity:1.0;}
a:link {color:black; text-decoration:none;}
a:visited {color:black; text-decoration:none;}
a:hover {color:orange; text-decoration:none;}
a:active {color:black; text-decoration:none;}
#streamContainer, #streamContainerOnline, #streamContainerDeleted {text-align:left; padding:15px; padding-bottom:0px; width:700px; margin:0 auto;}
.streamItem { padding:15px; margin-bottom:15px; overflow:auto;}
.streamItem img {float:left;}
.streamItem .streamInfo { padding-top:8px; margin-left:15px; float:left;}
.streamItem .streamInfo .streamName { /*text-transform:uppercase;*/ }
.streamItem .streamInfo .streamStatus {color:#999999;}
.streamItem .streamInfo .streamTopic {color:#666666;}
.streamItem .streamInfo .streamActivity {font-weight:normal;}
.streamItem .streamInfo .streamCategory {color:#888888;}
#streamItemPrefab { display:none; }
/*#testID_0 {color:red;}
#testID_1 {color:green;}
#testID_2 {color:blue;}*/

FreeCodeCamp : Use the Twitchtv JSON API JS Codes

var channels = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "brunofin",  "comster404"];

$(document).ready(function() {
  
  for(var i = 0; i < channels.length; i++) {
   $.getJSON("https://wind-bow.hyperdev.space/twitch-api/channels/" + channels[i] + "?callback=?", function(data) {
     
     if(data.error !== "Not Found") {
       var streamItem = $("#streamItemPrefab").clone().appendTo("#streamContainer").css("display","block");
       streamItem.find(".streamLink").prop("href", "https://www.twitch.tv/"+data.name);
       streamItem.find(".streamName").html(data.name); 
       streamItem.prop("id", data.name);
       streamItem.find(".streamStatus").html("offline");
       streamItem.find(".streamAvatar").prop("src", data.logo);
       streamItem.css("opacity", "0.3");
       
       $.getJSON("https://wind-bow.hyperdev.space/twitch-api/streams/" + data.name + "?callback=?", function(data) {
         var streamItem = $(document).find("#"+data.stream.channel.name);
         streamItem.find(".streamStatus").html("<span style='color:green'>online</span>");
         streamItem.find(".streamTopic").html(stringCutter(data.stream.channel.status, 70));
         streamItem.find(".label").html("Streaming");
         streamItem.find(".streamCategory").html(data.stream.game);
         streamItem.css("opacity", "1.0");
         // Switch to Online Container
         streamItem.clone().appendTo("#streamContainerOnline");
         streamItem.remove();
      });
       
     } else {
       //alert("error");
       var streamItem = $("#streamItemPrefab").clone().appendTo("#streamContainerDeleted").css("display","block");
       streamItem.css("opacity", "0.5");
       streamItem.find(".streamTopic").html(stringCutter(data.message, 70));
       // Quick Fix to disable hyperlink
       streamItem.find(".streamAvatar").hover(function() {
         $(this).css("border-color","white");
         $(this).css("cursor","default");
       });
       streamItem.find('.streamLink').click(function(e) {
         e.preventDefault();
       });
     }
   });
  }
});
  
function stringCutter(str, length) {
  if(str.length >= length) str = str.slice(0,length-3) + "...";
  return str;
}
Do you want hide your ip address?Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup.