MediaWiki:BlinkingTabAlert.js

//BlinkingTabCount - Count of Howard

//Credit goes to OneTwoThreeFall and Dorumin for their "NewMessageCount" and "PrivateMessageAlert" scripts, which comprised the bulk of this code.

//This was a simple adaptation on my part.

(function {    'use strict';

if (mw.config.get('wgCanonicalSpecialPageName') !== 'Chat' || window.loadedNewMessageCount) { return; }   window.loadedNewMessageCount = true;

var checkForChatInit; var newMessages = 0; var originalTitle = document.title; var newTitle; var timeoutId = null; var watchingForMessages = false;

function startWatch { watchingForMessages = true; }

function stopWatch { watchingForMessages = false; newMessages = 0; document.title = originalTitle; newTitle; clearInterval(timeoutId); timeoutId = null; }

function flashingTab { document.title = document.title == newTitle ? originalTitle : newTitle; }

function messageReceived { if (watchingForMessages) { newMessages += 1; newTitle = newMessages.toString + ' New Messages'; if (!timeoutId) { timeoutId = setInterval(flashingTab, 500); }       }    }

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); });