User:Sakaros/chat.js

//TabBlink - Firedance //Base code from NewMessageCount by OneTwoThreeFall, Dev Wiki //Blinking plugin by pinouchon, http://stackoverflow.com/questions/7617106/how-to-make-a-title-blink-until-it-becomes-active-with-jquery //I claim no ownership. //Production notes: Attempts to integrate message counter with blinking tab failed, likly due to conflicting setInterval times. Feature has since been removed. (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;            var isOriginalTitle = true;            var newTitle = "New Messages";            var interval = null;            function changeTitle {                document.title = isOriginalTitle ? originalTitle : newTitle;                isOriginalTitle = !isOriginalTitle;            }            interval = setInterval(changeTitle, 523); $(window).focus(function {                clearInterval(interval);                $("title").text(originalTitle);            }); }   }    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); });