~autra/webapps-applications/deezer

« back to all changes in this revision

Viewing changes to src/FacebookMessenger/FacebookMessenger.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:
20
20
    return true;
21
21
}
22
22
 
 
23
function getMessageCountElement() {
 
24
    return document.getElementById('mercurymessagesCountValue');
 
25
}
 
26
 
 
27
function getNotificationCountElement() {
 
28
    return document.getElementById('notificationsCountValue');
 
29
}
 
30
 
 
31
function selfTest() {
 
32
    if (!getMessageCountElement()) {
 
33
        reportTestState('FAILED: getMessageCountElement is null');
 
34
        return;
 
35
    }
 
36
 
 
37
    if (!getNotificationCountElement()) {
 
38
        reportTestState('FAILED: getNotificationCountElement is null');
 
39
        return;
 
40
    }
 
41
 
 
42
    reportTestState('PASS SELF TEST');
 
43
}
 
44
 
23
45
function messagingIndicatorSetup() {
24
46
    if (!isCorrectPage()) {
25
47
        return;
26
48
    }
27
 
    var countElement = document.getElementById('mercurymessagesCountValue');
28
 
    var notificationElement = document.getElementById('notificationsCountValue');
 
49
    var countElement = getMessageCountElement();
 
50
    var notificationElement = getNotificationCountElement();
29
51
 
30
52
    function checkMessangesCount() {
 
53
        var indicators = [];
31
54
        function makeCallback(node) {
32
55
            return function () { launchClickEvent(node.parentNode); };
33
56
        }
34
 
        Unity.MessagingIndicator.showIndicator(_("Messages"), { count: countElement.textContent,
35
 
                                                                callback: makeCallback(countElement) });
36
 
        Unity.MessagingIndicator.showIndicator(_("Notifications"), { count: notificationElement.textContent,
37
 
                                                                     callback: makeCallback(notificationElement) });
 
57
        indicators.push({ name: _("Messages"),
 
58
                          count: countElement.textContent,
 
59
                          callback: makeCallback(countElement) });
 
60
        indicators.push({ name: _("Notifications"),
 
61
                          count: notificationElement.textContent,
 
62
                          callback: makeCallback(notificationElement) });
 
63
        return indicators;
38
64
    }
39
 
 
40
 
    setInterval(checkMessangesCount, 1000);
41
 
    checkMessangesCount();
 
65
    var indicatorsController = new Indicators(checkMessangesCount);
42
66
 
43
67
    if (document.location.hostname === 'apps.facebook.com') {
44
68
        var name = document.evaluate('//div[@role="contentinfo"]/div/span', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue.textContent;
45
69
        linkVisited(document.location.toString(), name);
46
70
    }
 
71
 
 
72
    selfTest();
47
73
}
48
74
 
49
75
if (document.getElementById('email')) {