Skip to content

Instantly share code, notes, and snippets.

@meeech
Created March 9, 2011 07:06
Show Gist options
  • Save meeech/861805 to your computer and use it in GitHub Desktop.
Save meeech/861805 to your computer and use it in GitHub Desktop.
//Update the forrst title bar evey 5 seconds with the
//count of users in the chat room.
//uses some jq
(function(){
var title = $('title'),
originalTitleText = title.html(),
messageCountFrom = false;
var getUserCount = function() {
return $('#users-online').children().length;
};
//Guess right now, simplest way
//If window in focus,
var getMessageCount = function() {
if(false === messageCountFrom) {
return '*';
}
//Tried caching $(topic-messsages) but seems i need to call it live eachtime
return $('#topic-messages').children().length - messageCountFrom;
};
var updateTitle = function(){
title.html('('+getUserCount()+'/'+getMessageCount()+') '+ originalTitleText);
};
//No good dom/id hooks right now, but you get the idea...
$(window).blur(function() {
messageCountFrom = $('#topic-messages').children().length;
});
$(window).focus(function() {
messageCountFrom = false;
updateTitle();
});
updateTitle();
setInterval(updateTitle, 3000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment