Orkut Navigator

By Brunolm Last update Jul 22, 2008 — Installed 230 times.
// ==UserScript==
// @name           Orkut Navigator
// @namespace      std
// @description    Navigate orkut using your keyboard
// @include        http://www.orkut.com*
// ==/UserScript==

/*
 * @author Bruno Leonardo Michels
 * @profile http://www.orkut.com/Profile.aspx?uid=11584069900845257050
 */

/**
 * System
 */
var _left = 37;
var _right= 39;

var _0 = 48;
var _1 = 49;
var _2 = 50;
var _3 = 51;
var _4 = 52;
var _5 = 53;
var _6 = 54;
var _7 = 55;
var _8 = 56;
var _9 = 57;

var _a = 65;
var _c = 67;
var _q = 81;
var _r = 82;
var _w = 87;
 
 /**
  * URLs
  */
var topicUrl = "/CommMsgs";
var postUrl = "/CommMsgPost";
var cmmsUrl = "/Communities";
var cmmUrl = "/Community";
var homeUrl = "/Home";
var scrapUrl = "/Scrapbook";
 
/**
 * Settings
 */
var isTopic = window.location.href.indexOf(topicUrl) == -1 ? false : true;
var isPostUrl = window.location.href.indexOf(postUrl) == -1 ? false : true;
var isCmmList = window.location.href.indexOf(cmmsUrl) == -1 ? false : true;
var isCmm = window.location.href.indexOf(cmmUrl) == -1 ? false : true;
 
function getXPATH(path)
{
    return document.evaluate(
        path,
        document,
        null,
        XPathResult.FIRST_ORDERED_NODE_TYPE,
        null
    ).singleNodeValue;
}

/**
 * Paths
 */
var firstPath = '/html/body/div[6]/div[3]/table/tbody/tr[2]/td/span/a';
var lastPath = '/html/body/div[6]/div[3]/table/tbody/tr[2]/td/span/a[4]';
var lastAPath = '/html/body/div[6]/div[3]/table/tbody/tr[2]/td/span/a[2]';
var prevPath = '/html/body/div[6]/div[3]/table/tbody/tr[2]/td/span/a[2]';
var nextPath = '/html/body/div[6]/div[3]/table/tbody/tr[2]/td/span/a[3]';
var nextAPath = '/html/body/div[6]/div[3]/table/tbody/tr[2]/td/span/a';
var cmmFromListPath = '/html/body/div[6]/div[4]/table[2]/tbody/tr/td/div[2]/table/tbody/tr[$]/td/a';
var cmmFromListPathA = '/html/body/div[6]/div[4]/table[2]/tbody/tr/td/div[2]/div[4]/table/tbody/tr[$]/td/a';
var topicFromCmm = '/html/body/div[6]/div[4]/table[3]/tbody/tr[2]/td/form/table/tbody/tr[$]/td[2]/a';

var f =
    function (e)
    {
        // Arrow navigation
        if (isTopic)
        {
            var first = getXPATH(firstPath);
            var prev = getXPATH(prevPath);
            var next = getXPATH(nextPath);
            var last = getXPATH(lastPath);
            if (!next)
                next = getXPATH(nextAPath);
            if (!last)
                last = getXPATH(lastAPath);

            switch (e.keyCode)
            {
                case _left: // left
                    if (e.shiftKey && first)
                    {
                        window.location.href = first.href;
                        break;
                    }
                    if (prev)
                        window.location.href = prev.href;
                    break;
                case _right: // right
                    if (e.shiftKey && last)
                    {
                        window.location.href = last.href;
                        break;
                    }
                    if (next)
                        window.location.href = next.href;
                    break;
                case _r: // r
                    if (e.altKey)
                    {
                        window.location.href = postUrl + "?" + window.location.href.match(/cmm.*/i);
                    }
                    break;
                case _1: // 1
                    if (e.altKey)
                    {
                        var cmmId = window.location.href.match(/cmm=(\d+)/i)[1];
                        if (cmmId)
                            window.location.href = cmmUrl + "?cmm=" + cmmId;
                    }
                    break;
            }
        }

        // Communities list navigation
        if (isCmmList)
        {
            if (e.altKey)
            {
                if (e.keyCode >= _0 && e.keyCode <= _9)
                {
                    var n = (e.keyCode - 48);
                    if (n == 0) n = 10;
                    var go = getXPATH(cmmFromListPath.replace("$", n));
                    if (!go)
                        go = getXPATH(cmmFromListPathA.replace("$", n));
                    if (!go) return;
                    window.location.href = go.href;
                }
            }
        }
        
        // Community navigation
        if (isCmm)
        {
            if (e.altKey)
            {
                switch (e.keyCode)
                {
                    case _1: // 1
                        var go = getXPATH(topicFromCmm.replace("$", "2"));
                        if (!go) return;
                        window.location.href = go.href;
                        break;
                    case _2: // 2
                        var go = getXPATH(topicFromCmm.replace("$", "3"));
                        if (!go) return;
                        window.location.href = go.href;
                        break;
                    case _3: // 3
                        var go = getXPATH(topicFromCmm.replace("$", "4"));
                        if (!go) return;
                        window.location.href = go.href;
                        break;
                    case _4: // 4
                        var go = getXPATH(topicFromCmm.replace("$", "5"));
                        if (!go) return;
                        window.location.href = go.href;
                        break;
                    case _5: // 5
                        var go = getXPATH(topicFromCmm.replace("$", "6"));
                        if (!go) return;
                        window.location.href = go.href;
                        break;
                }
            }
        }
        
        // Global Navigation
        if (e.altKey)
        {
            switch (e.keyCode)
            {
            
                case _c: // c (communities)
                    window.location.href = cmmUrl;
                    break;
                case _a: // a (home)
                    window.location.href = homeUrl;
                    break;
                case _w: // w (scraps)
                    window.location.href = scrapUrl;
                    break;
            }
        }
    };
window.addEventListener("keydown", f, false);