User:Firedance/chat.js

//TabBlink

//Based on the code of NewMessageCount by OneTwoThreeFall. I claim no ownership.

importScriptURI('raw.githubusercontent.com/heyman/jquery-titlealert/master/jquery.titlealert.js&ctype=text/javascript'); (function {    'use strict';    if (mw.config.get('wgCanonicalSpecialPageName') !== 'Chat' || window.loadedNewMessageCount) {        return;    }    window.loadedNewMessageCount = true;    var checkForChatInit;    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;            $.titleAlert("New chat message!");        }    }    window.addEventListener('blur', startWatch, false);    window.addEventListener('focus', stopWatch, false);    checkForChatInit = setInterval(function  { if (window.mainRoom) { clearInterval(checkForChatInit); mainRoom.socket.bind('chat:add', messageReceived); }   }, 523); });