~ubuntu-branches/ubuntu/trusty/unity-webapps-twitter/trusty

« back to all changes in this revision

Viewing changes to Twitter.user.js

  • Committer: Alexandre Abreu
  • Date: 2012-09-20 19:48:21 UTC
  • Revision ID: alexandre.abreu@canonical.com-20120920194821-36ct26mox3oi00gx
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ==UserScript==
 
2
// @include       https://twitter.com/*
 
3
// @require       utils.js
 
4
// ==/UserScript==
 
5
 
 
6
window.Unity = external.getUnityObject(1);
 
7
 
 
8
function isCorrectPage() {
 
9
    var i, ids = ['doc', 'banners', 'page-outer', 'global-nav-home', 'global-new-tweet-button'];
 
10
 
 
11
    for (i = 0; i < ids.length; i++) {
 
12
        if (!document.getElementById(ids[i])) {
 
13
            return false;
 
14
        }
 
15
    }
 
16
 
 
17
    return true;
 
18
}
 
19
 
 
20
function messagingIndicatorSetup() {
 
21
    function checkMessangesCount() {
 
22
        var title;
 
23
        var search = document.getElementsByClassName('flex-table-input search-query js-search-header-query')[0];
 
24
        if (search) { // stream for #tag
 
25
            title = search.value;
 
26
        }
 
27
        if (document.getElementsByClassName('module mini-profile component')[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);
 
44
}
 
45
 
 
46
if (isCorrectPage()) {
 
47
    var prefix = 'https://twitter.com/';
 
48
 
 
49
    var profileLink = document.evaluate('//a[@data-nav="profile"]', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
 
50
    var login = profileLink.href;
 
51
 
 
52
    if (login.substr(0, prefix.length) === prefix) {
 
53
        login = login.substr(prefix.length);
 
54
    } else {
 
55
        login = null;
 
56
    }
 
57
 
 
58
    Unity.init({ name: "Twitter",
 
59
                 login: login,
 
60
                 domain: 'twitter.com',
 
61
                 homepage: 'https://twitter.com/',
 
62
                 iconUrl: "icon://twitter",
 
63
                 onInit: wrapCallback(messagingIndicatorSetup) });
 
64
}