Twitch Vodder
HTML
<title>Twitch Vodder</title>
<p></p>
JavaScript
getData(getUser());
function getUser() {
return window.prompt("Username ?");
}
function timeSince(date) {
var seconds = Math.floor((new Date() - date) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval > 1) {
return interval + " years";
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
return interval + " months";
}
interval = Math.floor(seconds / 86400);
if (interval > 1) {
return interval + " days";
}
interval = Math.floor(seconds / 3600);
if (interval > 24) {
interval -=24;
return "1 day, " + interval + " hours";
}
if (interval > 1) {
return interval + " hours";
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
return interval + " minutes";
}
return Math.floor(seconds) + " seconds";
}
function getData(username) {
if (username) {
$.getJSON(`https://api.twitch.tv/kraken/users/${username}/follows/channels?limit=1000&sortby=last_broadcast`, function(data) {
})
.done(function(data) {
var follows = data.follows;
$.each(follows, function(i, j) {
$.getJSON(j.channel._links.videos+'?limit=3&broadcasts=true',function(data) {
})
.done(function(data) {
var videos = data.videos;
$("p").append(`<h1>${j.channel.name}</h1>`);
if(jQuery.isEmptyObject(videos)){
$("p").append(`No vods found :(<br>`);
}
else{
$.each(videos, function(b, c) {
$("p").append(`<h4><a href=${c.url} target="_blank">${c.title}</a><br></h4>`);
$("p").append(`<a href=${c.url} target="_blank"><img src=${c.preview}></a><br>`);
...