~autra/webapps-applications/deezer

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// ==UserScript==
// @include       http://www.linkedin.com/*
// @include       http://www.linkedin.com
// @require       utils.js
// ==/UserScript==

window.Unity = external.getUnityObject(1);

/**
 * User script self validation
 * 
 * Called by the testing framework to make sure that
 * the page layout seems ok.
 */
function selfTest() {
    if (!getComposeNewMessageClickTargetNode()) {
        return;
    }

    // We are done
    reportTestState('PASS SELF TEST');
}

function getComposeNewMessageClickTargetNode() {
    return document.evaluate('//li[@id="nav-primary-inbox"]/ul/li[3]/a',
                             document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
};

function isCorrectPage() {
    var i, ids = ['header'];

    for (i = 0; i < ids.length; i++) {
        if (!document.getElementById(ids[i])) {
            return false;
        }
    }

    return true;
}

function doMatrixIntegration() {
    function integrateSubMenu(parent) {
        var i, snapshot = document.evaluate('ul/li/a',
                                            parent, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
        for (i = 0; i < snapshot.snapshotLength; i++) {
            var node = snapshot.snapshotItem(i);
            var text = node.textContent;
            var link = node.href;
            console.log(text);
            Unity.addAction('/' + text, makeRedirector(link));
        }
    }
    var i, snapshot = document.evaluate('//div[@id="header"]/div[2]/div/ul/li',
                                        document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

    for (i = 0; i < snapshot.snapshotLength; i++) {
        var node = snapshot.snapshotItem(i);
        var text = node.getElementsByTagName('a')[0].getElementsByTagName('span')[0].textContent;
        var link = node.getElementsByTagName('a')[0].href;

        console.log(text);
        Unity.addAction('/' + text, makeRedirector(link));
        integrateSubMenu(node);
    }
}

function messagingIndicatorSetup() {
    function checkMessagesCount() {
        var count = document.getElementById('header-messages-count');

        if (count) {
            count = count.textContent.match(/\d+/)[0];
        } else {
	    count = '0';
        }
        return [{ name: _("Inbox"),
		  count: count,
                  callback: makeRedirector('http://www.linkedin.com/inbox/messages/received?trk=hb_tab_inbox_top') }];
    }
    var indicatorsController = new Indicators(checkMessagesCount);

    function composeNewMessage() {
        var node = getComposeNewMessageClickTargetNode();
        launchClickEvent(node);
    }
    Unity.Launcher.addAction(_("Compose New Message"),
			     wrapCallback(composeNewMessage));

    doMatrixIntegration();

    selfTest();
}

if (isCorrectPage()) {
    Unity.init({ name: 'LinkedIn',
		 domain: 'linkedin.com',
		 homepage: 'http://www.linkedin.com',
                 iconUrl: 'icon://unity-webapps-linkedin',
                 onInit: wrapCallback(messagingIndicatorSetup) });
}