var UnseenMsgCounter = 0; var OrigTitle = $('title').text(); var HasFocus = true; function onFocus() { HasFocus = true; UnseenMsgCounter = 0; } function onBlur() { HasFocus = false; } $(window).blur(onBlur); $(window).focus(onFocus); function titleUpdater() { if (HasFocus || UnseenMsgCounter == 0 || $('title').text() != OrigTitle) { $('title').text(OrigTitle); } else { var plural = UnseenMsgCounter > 1 ? 's' : ''; $('title').text(UnseenMsgCounter + ' new dump' + plural + '! | ' + OrigTitle); } setTimeout(titleUpdater, 2000); } setTimeout(titleUpdater, 2000);