Skip to content

Instantly share code, notes, and snippets.

@marcuszierke
Last active October 19, 2017 17:46
Show Gist options
  • Save marcuszierke/a6e9615967a287d2a6a062c4a04a636f to your computer and use it in GitHub Desktop.
Save marcuszierke/a6e9615967a287d2a6a062c4a04a636f to your computer and use it in GitHub Desktop.
Free Code Camp - TwitchTV
<html>
<head>
<meta charset="utf-8">
<title>Twitch.tv - Viewer</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style type="text/css">
<link href="https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet">
body {
padding-top: 20px;
background-color: white;
font-family: 'Catamaran', sans-serif;
}
ul {
display: block;
justify-content: space-;
}
ul li {
color: #000;
width: 33.33333333%;
font-size: 16px;
display: inline-block;
padding: 5px 0;
background-color: #b08fed;
}
#search {
padding-left: 20px;
}
a {
color: black;
}
input {
width: 340px;
border-radius: 10px;
padding-left: 10px;
border: none;
padding-top: 5px;
padding-bottom: 5px;
}
img {
height: 80px;
width: 80px;
border-radius: 50%;
}
div {
padding-top: 10px;
}
.container {
background-color: #6495ED;
width: 380px;
}
.name {
font-weight: 700;
margin-top: 30px;
text-align: center;
}
.nON {
font-weight: 700;
margin-top: 0px;
text-align: center;
}
.info {
font-weight: 400;
}
.status {
height: 40px;
width: 40px;
margin-top: 10px;
margin-left: -15px;
}
.ON {
height: 40px;
width: 40px;
margin-top: 10px;
margin-left: -20px;
}
</style>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="twitchTVJS.js"></script>
</head>
<body>
<div class="container">
<div id="search" class="row">
<input type="search" placeholder="Search by username ...">
</div>
<div class="result"></div>
</div>
</body>
</html>
$(document).ready(function() {
var following = [];
var followerURL = "https://wind-bow.glitch.me/twitch-api/users/freecodecamp/follows/channels";
$.getJSON(followerURL, function(data1) {
//find the accounts that follow FREECODECAMP and put them in the FOLLOWING arr
for (var i = 0; i < data1.follows.length; i++) {
var displayName = data1.follows[i].channel.display_name;
following.push(displayName);
}
following.push("comster404", "brunofin", "ESL_SC2", "freecodecamp");
//loop through the arr to check if the ...
for (var j = 0; j < following.length; j++) {
var userURL = "https://wind-bow.glitch.me/twitch-api/channels/" + following[j] + "/?callback=?";
$.getJSON(userURL).done(function(data2) {
var name;
var logo;
var status;
var info;
//.../users/... url if the don't exist
//if (data2.error) {
//logo = "https://workinfo.info/images/modules/directory/listings/thumbs/no_logo.jpg";
//name = data2.message.slice(34, -1);
//status = "https://www.polyvore.com/cgi/img-thing?.out=jpg&size=l&tid=50711229";
//$(".result").append("<div class='row'>" + "<div class='online'>" + "<div class='logo col-md-3'>" +
//"<img src='" + logo + "'>" +
//"</div>" + "<div class='nON col-md-7'><br>" + name + "</div>" + "<div class='col-md-2'>" + "<img class='ON' src='" + status + "'>" + "</div></div></div>");
//}
//.../users/... url if they are OFFLINE
if(data2.partner == false) {
logo = data2.logo;
if(logo === null) {
logo = "https://workinfo.info/images/modules/directory/listings/thumbs/no_logo.jpg";
}
name = data2.display_name;
status = "http://tecfa.unige.ch/guides/svg/ex/html5/svg-import/huge-red-circle.svg";
$(".result").append("<div class='row' data-filter data-filter-name='" + name + "'>" + "<div class='online'>" + "<div class='logo col-md-3'>" +
"<a href='https://www.twitch.tv/" + data2.name + "' target='_blank'><img src='" + logo + "'></a>" +
"</div>" + "<div class='nON col-md-7'>" + "<a href='https://www.twitch.tv/" + data2.name + "' target='_blank'>" + name + "</a><br>" + info + "</div>" + "<div class='col-md-2'>" + "<img class='ON' src='" + status + "'>" + "</div></div></div>");
}
//.../users/... url if they are ONLINE
if(data2.partner) {
logo = data2.logo;
if(logo === null) {
logo = "https://workinfo.info/images/modules/directory/listings/thumbs/no_logo.jpg";
}
name = data2.display_name;
status = "http://www.pros.com/wp-content/uploads/2015/10/img-checkmark.svg";
info = data2.status;
$(".result").append("<div class='row' data-filter data-filter-name='" + name + "'>" + "<div class='online'>" + "<div class='logo col-md-3'>" +
"<a href='https://www.twitch.tv/" + data2.name + "' target='_blank'><img src='" + logo + "'></a>" +
"</div>" + "<div class='nON col-md-7'>" + "<a href='https://www.twitch.tv/" + data2.name + "' target='_blank'>" + name + "</a><br>" + info + "</div>" + "<div class='col-md-2'>" + "<img class='ON' src='" + status + "'>" + "</div></div></div>");
}
});
//Defining the search bar
$("#search").keyup(function() {
var username = $("#search").val().toLowerCase();
var filterItems = $("[data-filter]");
if (username != "") {
filterItems.addClass("hidden");
$("[data-filter][data-filter-name='" + name + "']").removeClass("hidden");
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment