JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
<body>
<div class="content">
<div class="container" id="container">
<h1><i class="fa fa-twitch"></i> TwitchBox</h1>
<div class="menu">
<div class="buttons" id="all-button">All</div>
<div class="buttons" id="online-button">Online</div>
<div class="buttons" id="offline-button">Offline</div>
<!-- channels go here-->
</div>
</div>
</div>
<footer class="footer">
<div>
<div class="icons">
<a href="https://www.freecodecamp.com/chazmcgrill">
<i class="fa fa-free-code-camp" aria-hidden="true"></i>
</a>
<a href="https://twitter.com/charlietdev">
<i class="fa fa-twitter" aria-hidden="true"></i>
</a>
<a href="https://github.com/chazmcgrill">
<i class="fa fa-github" aria-hidden="true"></i>
</a>
<a href="https://www.linkedin.com/in/charlie-taylor-941434134/">
<i class="fa fa-linkedin" aria-hidden="true"></i>
</a>
<a href="https://codepen.io/chazmcgrill/">
<i class="fa fa-codepen" aria-hidden="true"></i>
</a>
</div>
<p>designed and coded by <a href="http://www.hurricanecharlie.co.uk">charlie taylor</a></p>
</div>
</footer>
</body>
@import url('https://fonts.googleapis.com/css?family=Roboto+Mono:500,700');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-family: 'Roboto Mono', monospace;
font-weight: 500;
height: 100%;
}
body {
min-height: 100%;
display: flex;
flex-direction: column;
background: #0AB2AA;
}
.content {
flex: 1;
}
h1 {
text-align: center;
margin-bottom: 20px;
}
a {
font-weight: 700;
text-decoration: none;
color: black;
}
img {
height: 40px;
border-radius: 50%;
}
img,
.title,
.status {
display:inline-block;
}
.title,
.status {
margin-left: 10px;
}
.title {
width: 130px;
}
.container {
width: 340px;
margin: 40px auto;
background: white;
padding: 30px;
border-radius: 5px;
box-shadow: 1px 1px 5px #888888;
}
.row {
display: flex;
align-items: center;
margin-bottom: 20px;
padding: 5px 20px;
border-radius: 5px;
justify-content: space-between;
}
.menu {
display: flex;
margin-bottom: 20px;
border-bottom: 2px solid black;
border-top: 2px solid black;
}
.buttons {
text-align: center;
width: 100px;
padding: 20px;
cursor: pointer;
}
.buttons:hover,
a:hover {
color: #0AB2AA;
}
.fa-times {
color: red;
}
.fa-check {
color: green;
}
.fa-exclamation {
color: orange;
padding-right: 3px;
}
.handle {
display: none;
}
/*footer*/
p {
font-size: 10px;
}
.icons {
width: 150px;
margin: 0 auto 10px auto;
display: flex;
justify-content: space-between;
}
.footer {
display: flex;
justify-content: space-around;
height: 70px;
text-align: center;
}
.footer i:hover,
.footer a:hover {
color: #fff;
}
document.addEventListener("DOMContentLoaded", function() {
var channelArray = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "brunofin", "comster404"];
var url = "https://wind-bow.glitch.me/twitch-api/"
var channels = document.getElementById("container");
// loop through all default channels in array
channelArray.forEach(function(item){
var status = "";
var iconClass = "";
var channelName = "";
var channelUrl = "";
var currentStream = "";
// status information request
var requestStatus = new XMLHttpRequest();
requestStatus.open('GET', url + 'streams/' + item, true);
requestStatus.onload = function() {
if (this.status >= 200 && this.status < 400){
var dataStatus = JSON.parse(this.response);
if(dataStatus.stream === null){
status = "offline";
iconClass = "fa-times";
currentStream = "Currently offline"
} else {
status = "online";
iconClass = "fa-check";
currentStream = dataStatus.stream.channel.status;
}
fetchData(item); // call rest of data once status collected.
} else {
console.log("ERROR FETCHING DATA");
}
};
requestStatus.onerror = function() {
console.log("ERROR CONNECTING TO SERVER");
};
requestStatus.send();
// Channel data request
function fetchData(item){
var requestChannel = new XMLHttpRequest();
requestChannel.open('GET', url + 'channels/' + item, true);
requestChannel.onload = function() {
if (this.status >= 200 && this.status < 400) {
var dataChannel = JSON.parse(this.response);
var row = document.createElement("div");
var img = document.createElement("img");
var imgUrl = "https://placeimg.com/40/40/tech/grayscale"
channels.appendChild(row);
row.className = "row";
channelName = dataChannel.display_name || item;
// channel not found check
if(dataChannel.display_name) {
channelUrl = dataChannel.url;
} else {
status = "not-found";
iconClass = "fa-exclamation";
channelUrl = "#"
currentStream = "Channel not found"
}
// add logo
if(dataChannel.logo) {
imgUrl = dataChannel.logo;
}
// build the rows with data
row.innerHTML = '<img src="' + imgUrl + '"><div class="title"><a href="' + channelUrl + '" target="_blank">' + channelName + '</a><br><p>' + currentStream + '</p></div><div class="status"><i class="fa ' + iconClass + '" aria-hidden="true"></i></div>';
row.className = 'row ' + status;
} else {
console.log("ERROR FETCHING DATA");
}
};
requestChannel.onerror = function() {
console.log("ERROR CONNECTING TO SERVER");
};
requestChannel.send();
}
});
// Button event listeners
document.getElementById("all-button").addEventListener("click", function(){
removeHandle();
});
document.getElementById("online-button").addEventListener("click", function(){
removeHandle();
addHandle('.offline');
addHandle('.not-found');
});
document.getElementById("offline-button").addEventListener("click", function(){
removeHandle();
addHandle('.online');
addHandle('.not-found');
});
// class manipulation functions
function removeHandle(){
var elements = document.querySelectorAll('.row');
for(var i = 0; i < elements.length; i++){
elements[i].classList.remove('handle');
}
}
function addHandle(selector){
var elements = document.querySelectorAll(selector);
for(var i = 0; i < elements.length; i++){
elements[i].classList.add('handle');
}
}
});
Also see: Tab Triggers