~autra/webapps-applications/deezer

« back to all changes in this revision

Viewing changes to src/LiveMail/LiveMail.user.js

  • Committer: autra
  • Date: 2013-04-11 12:34:24 UTC
  • mfrom: (406.1.108 trunk)
  • Revision ID: autra@autra-optiplex-380-20130411123424-3b0xa9ppaytxx3hr
sync from parent

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
// ==/UserScript==
6
6
 
7
7
window.Unity = external.getUnityObject(1);
 
8
function isOutlook() {
 
9
    return document.getElementById('folderListControlUl');
 
10
}
 
11
 
 
12
function getOutlookInboxCountNode() {
 
13
    return document.evaluate('//ul[@id="folderListControlUl"]/li[1]', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
 
14
}
 
15
 
 
16
function getHotmailInboxCountNode() {
 
17
    return document.getElementById('c_murc');
 
18
}
 
19
 
 
20
function getHotmailMessagesCountNode() {
 
21
    return document.getElementById('c_mocc');
 
22
}
 
23
 
 
24
function getMailDataForPage () {
 
25
    var inboxCount = '0';
 
26
    var messageCount = '0';
 
27
 
 
28
    try {
 
29
        if (isOutlook()) {
 
30
            inboxCount = getOutlookInboxCountNode().getAttribute('count');
 
31
        }
 
32
        else {
 
33
            inboxCount = getHotmailInboxCountNode().textContent.match(/\d+/)[0];
 
34
            messageCount = getHotmailMessagesCountNode().textContent.match(/\d+/)[0];
 
35
        }
 
36
    }
 
37
    catch (x) {}
 
38
 
 
39
    return {
 
40
        inbox: inboxCount,
 
41
        messages: messageCount
 
42
    };
 
43
}
 
44
 
 
45
function listenToChanges(handler) {
 
46
    if (isOutlook()) {
 
47
        getOutlookInboxCountNode().addEventListener('DOMSubtreeModified', handler, false);
 
48
    }
 
49
    else {
 
50
        getHotmailInboxCountNode().addEventListener('DOMSubtreeModified', handler, false);
 
51
        getHotmailMessagesCountNode().addEventListener('DOMSubtreeModified', handler, false);
 
52
    }
 
53
}
8
54
 
9
55
function isCorrectPage() {
10
 
    var i, ids = ['c_murc', 'c_mocc'];
11
 
 
12
 
    for (i = 0; i < ids.length; i++) {
13
 
        if (!document.getElementById(ids[i])) {
14
 
            return false;
15
 
        }
16
 
    }
17
 
 
18
 
    return true;
 
56
    if (isOutlook())
 
57
        return getOutlookInboxCountNode();
 
58
 
 
59
    // fall back on hotmail
 
60
    return getHotmailMessagesCountNode() && getHotmailInboxCountNode();
19
61
}
20
62
 
21
63
function messagingIndicatorSetup() {
22
 
    var inboxCountElement = document.getElementById('c_murc');
23
 
    var messengerCountElement = document.getElementById('c_mocc');
24
 
    var checkMessangesCount = wrapCallback(function () {
25
 
        var count = inboxCountElement.textContent.match(/\d+/)[0];
26
 
 
27
 
        Unity.MessagingIndicator.showIndicator("Inbox", { count: count });
28
 
 
29
 
        count = '0';
30
 
        if (messengerCountElement.textContent.length) {
31
 
            count = messengerCountElement.textContent.match(/\d+/)[0];
32
 
        }
33
 
 
34
 
        Unity.MessagingIndicator.showIndicator("Messenger", { count: count });
 
64
    var checkMessagesCount = wrapCallback(function () {
 
65
        var d = getMailDataForPage();
 
66
        Unity.MessagingIndicator.showIndicator("Inbox", { count: d.inbox });
 
67
        Unity.MessagingIndicator.showIndicator("Messenger", { count: d.messages });
35
68
    });
36
69
 
37
 
    inboxCountElement.addEventListener('DOMSubtreeModified', checkMessangesCount, false);
38
 
    messengerCountElement.addEventListener('DOMSubtreeModified', checkMessangesCount, false);
 
70
    checkMessagesCount();
39
71
 
40
 
    checkMessangesCount();
 
72
    listenToChanges(checkMessagesCount);
41
73
}
42
74
 
43
75
setTimeout(function self() {
44
 
    var i, ids = ['c_murc', 'c_mocc'];
 
76
    if (!isCorrectPage()) {
 
77
        setTimeout(self, 1000);
 
78
        return;
 
79
    }
45
80
 
46
 
    for (i = 0; i < ids.length; i++) {
47
 
        if (!document.getElementById(ids[i])) {
48
 
            setTimeout(self, 1000);
49
 
            return;
50
 
        }
51
 
    }
52
81
    Unity.init({ name: "live.com",
53
82
                 domain: 'mail.live.com',
54
83
                 homepage: 'http://mail.live.com',