Skip to content

Instantly share code, notes, and snippets.

@halfdan
Created July 7, 2015 10:52
Show Gist options
  • Save halfdan/5895df3b461270ba8906 to your computer and use it in GitHub Desktop.
Save halfdan/5895df3b461270ba8906 to your computer and use it in GitHub Desktop.
LiveCodingTV Stats
// ==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 <halfdan@xnorfz.de>
// @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