public
Description: A quick link to view your public profile from anywhere within odesk.com
Homepage: http://www.proven-corporation.com/software/quickodeskprofile
Clone URL: git://github.com/jhs/quickodeskprofile.git
quickodeskprofile / quickodeskprofile.user.js
100644 74 lines (65 sloc) 2.56 kb
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
/*
* Copyright 2008 Proven Corporation Co., Ltd., Thailand
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 dated June, 1991.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
 
// ==UserScript==
// @name quickoDeskProfile
// @namespace http://proven-corporation.com/
// @description A quick link to view your public profile from anywhere within oDesk
// @include http://www.odesk.com/*
// @include https://www.odesk.com/*
// ==/UserScript==
 
/* A simple wrapper for quick debug messages. */
function debug(message) {
    unsafeWindow.console.debug(message);
}
 
/* Conveniently search via XPath. If nothing matches,
* return null. For one match, return the element. For multiple matches,
* return an array of elements. The forceList option will force the
* function to return a list, regardless of the result.
*/
function xpath(path, forceList, node) {
    if(forceList === undefined)
        forceList = false;
    if(node === undefined)
        node = document
 
    var result = [];
    var nodes = document.evaluate(path, node, null,
                                  XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );
    for(var a = 0; a < nodes.snapshotLength; a++)
        result.push(nodes.snapshotItem(a));
    if(forceList)
        return result;
 
    if(result.length == 0)
        return null;
    else if(result.length == 1)
        return result[0];
    else
        return result;
}
 
/* This is the main program entry after the page loads completely. */
function main() {
    /* Add the config section after the "Logged in as..." stuff. */
    var greeting = xpath('//ul[@id="logline"]/li[1]');
    if(!greeting) {
        /* TODO disable this script because it seems to fail to work with the site's HTML. */
        debug("Cannot find greeting");
        return;
    }
    else {
        /* Insert a new list item with a link to my profile. */
        debug("Found greeting");
        var myHeading = xpath('strong', false, greeting);
        var myName = myHeading.innerHTML;
 
        myHeading.innerHTML = '<a style="font-weight: inherit;" href="/d/view_profile.php">' + myName + '</a>';
        debug('done');
    }
}
 
window.addEventListener('load', main, true);