Advertisement
Guest User

CTL Twitch Script

a guest
May 26th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. <style>
  2. .online, .offline {
  3. border-radius: 5px;
  4. display: inline-block;
  5. height: 10px;
  6. width: 10px;
  7. }
  8.  
  9. .online {
  10. background: green;
  11.  
  12. }
  13.  
  14. .offline {
  15. background: red;
  16.  
  17. }
  18. </style>
  19. <body>
  20. <div id="sc2">
  21. <span id="sc2header" style="display: none">StarCraft II Streams:</span><br />
  22. </div>
  23. <div id="otherGame" style="display: none"></div>
  24. <script>
  25.  
  26. var sc2GameName = "StarCraft II: Heart of the Swarm";
  27.  
  28. //These are the names that are ALWAYS SHOWN. Add in the following manner ["Forum Name","Twitch Name", "Race (T/Z/P/R)"]
  29. var alwaysOn = [
  30. ["ChoboTeamLeague","ChoboTeamLeague","n"]
  31. , ["Relentless Heroes","rhgamingcom","n"]
  32. , ["All-Inspiriation","allinspiration","n"]
  33. , ["Team UnRivaled","teamunrivaled","n"]
  34. , ["tbham","tbham","z"]
  35. , ["Couchie","couchie14","t"]
  36. ];
  37.  
  38. //These are the names that are NOT ALWAYS SHOWN.
  39. var notAlwaysOn = [
  40.  
  41. ["Roxas","callmeroxas","t"]
  42. , ["Bozz","jonbozz","z"]
  43. , ["Seeker","SeekerSC2","t"]
  44. // !!! Reminder: remember to update StreamersTest as well !!!
  45. ];
  46.  
  47.  
  48.  
  49. var string = " ";
  50. var twitch = " ";
  51. var api_key= "seg30bf5k0rbnbq1z8qyb9usxyp5a34";
  52.  
  53. //Check for streams that should always be shown
  54. for (var q=0; q<alwaysOn.length;q++)
  55. {
  56. //window.alert(alwaysOn[q][0]+' '+ alwaysOn[q][1]+' '+alwaysOn[q][2]);
  57. checkStreamCast(alwaysOn[q][0], alwaysOn[q][1], alwaysOn[q][2], true);
  58. //window.alert(alwaysOn[q][0]+' '+ alwaysOn[q][1]+' '+alwaysOn[q][2]);
  59. }
  60.  
  61. //Check for streams that will not always be shown.
  62. for (var j=0; j<notAlwaysOn.length;j++)
  63. {
  64. checkStreamCast(notAlwaysOn[j][0], notAlwaysOn[j][1], notAlwaysOn[j][2], false);
  65. // window.alert(alwaysOn[j][0]+' '+ alwaysOn[j][1]+' '+ alwaysOn[j][2]);
  66.  
  67. }
  68. //Check to see if Twitch stream is live
  69. //ForumID = CTL Forum ID of the streamer
  70. //TwitchID = Twitch ID / Stream name of the streamer
  71. //Shows = True - will always show, False - only shows if live.
  72.  
  73. function checkStreamCast(ForumID, TwitchID, Race, Shows)
  74. {
  75. //api_key = "seg30bf5k0rbnbq1z8qyb9usxyp5a34";
  76.  
  77. $.getJSON('https://api.twitch.tv/kraken/streams/' + TwitchID + '?client_id=' + api_key + '&callback=?', function(data) {
  78. if (data.stream)
  79. {
  80. streamViewers = data['stream']['viewers'];
  81. streamTitle = htmlEscape(data['stream']['channel']['status']);
  82. streamGame = data['stream']['channel']['game'];
  83. twitch = "<a href='http://www.twitch.tv/" + TwitchID +"' target='blank' title='" + streamTitle + "'>" + ForumID + "</a>";
  84. string = "<span class='online'></span>&nbsp;<img src='http://files.enjin.com/217407/" + Race + ".png'>" + twitch + " <font color='a3a3a3'>(" + streamViewers+ ")</font><br>";
  85. CreateSpan(ForumID, string, streamGame);
  86. } else {
  87. if(Shows){
  88. //offline do nothing!
  89. twitch = "<a href='http://www.twitch.tv/" + TwitchID +"' target='blank'>" + ForumID + "</a>";
  90. string = "<span class='offline'></span>&nbsp;<img src='http://files.enjin.com/217407/" + Race + ".png'>" + twitch + "<br>";
  91. CreateSpan(ForumID, string, sc2GameName);
  92. }
  93. }
  94. });
  95.  
  96. }
  97.  
  98. function CreateSpan(strSpanID, strHTML, strGame)
  99. {
  100. var spanTag = document.createElement("span");
  101. spanTag.id = strSpanID;
  102. spanTag.innerHTML = strHTML
  103. //document.body.appendChild(spanTag);
  104. if (sc2GameName.toLowerCase() == (strGame).toLowerCase()) {
  105. $('#sc2').append(spanTag);
  106. } else {
  107. var gameDivId = '#' + htmlAndSpaceEscape(strGame);
  108. if ($(gameDivId).length == 0) {
  109. var gameDiv = document.createElement("div");
  110. gameDiv.id = htmlAndSpaceEscape(strGame);
  111. gameDiv.className = 'game';
  112. gameDiv.appendChild(spanTag);
  113.  
  114. $('#otherGame').append(gameDiv);
  115. $(gameDivId).prepend($('<span />').text(strGame + ":").append("<br />"));
  116. } else {
  117. $(gameDivId).append(spanTag);
  118. }
  119. }
  120. if ($('#otherGame .game').length > 0) {
  121. $('#sc2header').show();
  122. $('#otherGame').show();
  123. }
  124. }
  125.  
  126. function htmlEscape(str) {
  127. return String(str)
  128. .replace(/&/g, '&amp;')
  129. .replace(/"/g, '&quot;')
  130. .replace(/'/g, '&#39;')
  131. .replace(/</g, '&lt;')
  132. .replace(/>/g, '&gt;')
  133. .replace(/:/g, '')
  134. .replace(/;/g, '');
  135. }
  136.  
  137.  
  138. function htmlAndSpaceEscape(str) {
  139. return String(str)
  140. .replace(/&/g, '&amp;')
  141. .replace(/"/g, '&quot;')
  142. .replace(/'/g, '&#39;')
  143. .replace(/</g, '&lt;')
  144. .replace(/>/g, '&gt;')
  145. .replace(/:/g, '')
  146. .replace(/;/g, '')
  147. .split(' ').join('');
  148. }
  149.  
  150. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement