summaryrefslogtreecommitdiff
path: root/static/away.js
blob: e9c6b2e4cc6830af730dbbe5d5718fe59ebeb8f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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, HasFocus ? 5000 : 2000);
}

setTimeout(titleUpdater, 10000);