Last active
September 22, 2015 01:58
-
-
Save zjrosen1/f35edefae5876abe0aec to your computer and use it in GitHub Desktop.
LiveCoding Stats
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
// ==UserScript== | |
// @name LiveCoding Stats | |
// @namespace http://your.homepage/ | |
// @version 0.1 | |
// @description Shows your channel stats (live viewers, total viewers) in the chat window | |
// @author Fabian Becker <[email protected]> | |
// @match https://www.livecoding.tv/chat/* | |
// @grant none | |
// ==/UserScript== | |
console.log("This is chat"); | |
$(document).ready(function() { | |
var el = $('.chat-heading > div'); | |
el.append('<span class="live-stat"></span>'); | |
updateLiveData(); | |
setInterval(updateLiveData, 10000); | |
}); | |
function updateLiveData() { | |
var path = window.location.pathname, | |
userName, | |
url; | |
// Remove trailing slash | |
path = path.replace(/\/$/, ""); | |
// Get username | |
username = path.replace(/.*\//, '').toLowerCase(); | |
url = 'https://www.livecoding.tv/livestreams/' + username + '/stats.json'; | |
$.ajax(url).done(handleResponse); | |
} | |
function handleResponse(data) { | |
var text = ", Live Viewers: {{LIVE}}, Total Viewers: {{TOTAL}}"; | |
text = text.replace('{{LIVE}}', data.views_live); | |
text = text.replace('{{TOTAL}}', data.views_overall); | |
$('.live-stat')[0].innerHTML = text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment