Amm_

Twitch streaming detection

Jun 11th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. //Inside of the head tags
  2. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  3.  
  4.  
  5. //Put this wherever you want the on/offline images to be
  6. <a src="http://twitch.tv/casy_nuf">
  7. <img id="nm" src="http://i.imgur.com/xNCtOBk.png"> //This image is the default, I suggest offline
  8. </a>
  9.  
  10.  
  11. //Just before the closing body tag (</body>)
  12. <script>
  13. ur = 'https://api.twitch.tv/kraken/streams/casy_nuf';
  14. $.ajax({
  15. url: ur,
  16. dataType: 'jsonp',
  17. type: 'get',
  18. success: function(data) {
  19. if(data.stream === null) {
  20. document.getElementById("nm").src='http://i.imgur.com/xNCtOBk.png'; //offline image
  21. } else {
  22. document.getElementById("nm").src='http://i.imgur.com/JU80pML.png'; //online image
  23. }
  24. },
  25. });
  26. </script>
Add Comment
Please, Sign In to add comment