Last active
July 16, 2021 18:01
-
-
Save exegeteio/c0881edf4a8bbb379807 to your computer and use it in GitHub Desktop.
Twitch online status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://code.jquery.com/jquery-2.1.3.js"></script> | |
<script> | |
var checkStatus = function(streamer, $span) { | |
jQuery.getJSON('https://api.twitch.tv/kraken/streams/' + streamer + '/?callback=?', function(json) { | |
if (json.stream) { | |
$span.html($span.attr('data-twitch-online')); | |
} else { | |
$span.html($span.attr('data-twitch-offline')); | |
} | |
}); | |
setTimeout(recheckStatus(streamer, $span), 5000); | |
}; | |
var recheckStatus = function(streamer, $span) { | |
return function() { | |
checkStatus(streamer, $span); | |
} | |
}; | |
jQuery(function() { | |
jQuery('[data-twitch-status]').each(function(c, o) { | |
$span = jQuery(o); | |
checkStatus($span.attr('data-twitch-status'), $span); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<span data-twitch-status="professorbroman" data-twitch-online="Online!" data-twitch-offline="Not Online"></span> | |
<br/> | |
<span data-twitch-status="giantwaffle" data-twitch-online="ONLINE!" data-twitch-offline="OFFLINE">Offline</span> | |
</body> | |
</html> |
This was a quick proof of concept which was never terribly successful. I'm sure there are better implementations out there.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you give us an update? It doesn´t work :-/