MediaWiki:NewMessageCount.js

/* NewMessageCount - show new message count in the Chat window title */

/*jslint browser, single */ /*global window, mw, mainRoom */

(function {    'use strict';

// only run in chat + double-run protection if (mw.config.get('wgCanonicalSpecialPageName') !== 'Chat' || window.loadedNewMessageIndicator) { return; }   window.loadedNewMessageIndicator = true;

var originalTitle = document.title; var watchingForMessages = false; var newMessages = 0;

function startWatch { watchingForMessages = true; }

function stopWatch { watchingForMessages = false; newMessages = 0; document.title = originalTitle; }

function messageReceived { if (watchingForMessages) { newMessages += 1; document.title = '(' + newMessages.toString + ') ' + originalTitle; }   }

window.addEventListener('blur', startWatch, false); window.addEventListener('focus', stopWatch, false); mainRoom.socket.bind('chat:add', messageReceived); });