Skip to content

Instantly share code, notes, and snippets.

@exegeteio
Last active July 16, 2021 18:01
Show Gist options
  • Save exegeteio/c0881edf4a8bbb379807 to your computer and use it in GitHub Desktop.
Save exegeteio/c0881edf4a8bbb379807 to your computer and use it in GitHub Desktop.
Twitch online status
<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>
@exegeteio
Copy link
Author

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