~autra/webapps-applications/deezer

« back to all changes in this revision

Viewing changes to src/Twitter/Twitter.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
 
6
6
window.Unity = external.getUnityObject(1);
7
7
 
 
8
/**
 
9
 * Validates the page for functional tests.
 
10
 * 
 
11
 */
 
12
function selfTest() {
 
13
    if (!getProfileLinkNode() || !getProfileLinkNode().href) {
 
14
        return;
 
15
    }
 
16
    if (!checkMessagesCount().length) {
 
17
        return;
 
18
    }
 
19
 
 
20
    reportTestState('PASS SELF TEST');
 
21
};
 
22
 
 
23
function getProfileLinkNode() {
 
24
    return document.evaluate('//a[@data-nav="profile"]', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
 
25
}
 
26
 
8
27
function isCorrectPage() {
9
28
    var i, ids = ['doc', 'banners', 'page-outer', 'global-nav-home', 'global-new-tweet-button'];
10
29
 
17
36
    return true;
18
37
}
19
38
 
 
39
var currentIndicator = '';
 
40
 
 
41
function checkMessagesCount() {
 
42
    var indicators = [];
 
43
    var title;
 
44
    var search = document.getElementsByClassName('search-query')[0];
 
45
    if (search) { // stream for #tag
 
46
        title = search.textContent;
 
47
    }
 
48
    if (document.getElementsByClassName('module mini-profile')[0]) { // home screen
 
49
        title = _("Tweets");
 
50
    }
 
51
 
 
52
    if (title) {
 
53
        var count = '0';
 
54
        var countElement = document.getElementsByClassName('new-tweets-bar js-new-tweets-bar')[0];
 
55
        if (countElement) {
 
56
            count = countElement.textContent.match(/\d+/)[0];
 
57
        }
 
58
        reportTestState(title + count);
 
59
        // empty callback raise current tab
 
60
        indicators.push({ name: title, count: count, callback: function () {} });
 
61
        currentIndicator = title;
 
62
    }
 
63
    return indicators;
 
64
}
 
65
 
20
66
function messagingIndicatorSetup() {
21
 
    function checkMessangesCount() {
22
 
        var title;
23
 
        var search = document.getElementsByClassName('search-query')[0];
24
 
        if (search) { // stream for #tag
25
 
            title = search.textContent;
26
 
        }
27
 
        if (document.getElementsByClassName('module mini-profile')[0]) { // home screen
28
 
            title = _("Tweets");
29
 
        }
30
 
 
31
 
        if (title) {
32
 
            var count = '0';
33
 
            var countElement = document.getElementsByClassName('new-tweets-bar js-new-tweets-bar')[0];
34
 
            if (countElement) {
35
 
                count = countElement.textContent.match(/\d+/)[0];
36
 
            }
37
 
            // empty callback raise current tab
38
 
            reportTestState(title + count);
39
 
            Unity.MessagingIndicator.showIndicator(title, { count: count,
40
 
                                                            callback: function () {} });
41
 
        }
42
 
    }
43
 
    setInterval(wrapCallback(checkMessangesCount), 3000);
 
67
    var indicatorsController = new Indicators(checkMessagesCount, true);
 
68
    indicatorsController.visited(currentIndicator);
44
69
}
45
70
 
46
71
var login;
48
73
if (isCorrectPage()) {
49
74
    var prefix = 'https://twitter.com/';
50
75
 
51
 
    var profileLink = document.evaluate('//a[@data-nav="profile"]', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
52
 
    login = profileLink.href;
 
76
    var profileLink = getProfileLinkNode();
 
77
    if (profileLink && profileLink.href) {
 
78
        login = profileLink.href;
53
79
 
54
 
    if (login.substr(0, prefix.length) === prefix) {
55
 
        login = login.substr(prefix.length);
56
 
    } else {
57
 
        login = null;
 
80
        if (login.substr(0, prefix.length) === prefix) {
 
81
            login = login.substr(prefix.length);
 
82
        } else {
 
83
            login = null;
 
84
        }
58
85
    }
 
86
 
59
87
    callback = wrapCallback(messagingIndicatorSetup);
 
88
 
 
89
    selfTest();
60
90
}
61
91
Unity.init({ name: "Twitter",
62
92
             login: login,