Usuário:Brandizzi/goahead.js

Origem: Wikipédia, a enciclopédia livre.

Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Internet Explorer / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
/* Indo diretamente para a página a partir da qual se logou. Autor: [[Usuário:Brandizzi]] */ 
/* Should go back?  */
function aheadShouldGo() {
    return wgCanonicalNamespace == "Special" && 
        wgCanonicalSpecialPageName == "Userlogin" &&
        (wgAction == "submitlogin" || wgAction == "view");
}
 
/* If so, let us go! */
function aheadGo() {
    if (aheadShouldGo()) {
        var destination = aheadGetNextPage();
        if (destination) {
            window.location = destination;
        }
    }
}
 
/* To where? Here! */
 
function aheadGetNextPage() {
    var elements = document.getElementsByTagName('link');
    var returnPage = getParamValue('returnto');

    if (!returnPage) {
        for (var i = 0; i < elements.length; i++) {
            var element = elements[i];
            var relAttribute = element.getAttribute('rel');
            if (relAttribute == 'next') {
                returnPage = element.getAttribute('href');
            }
        }
    } else {
        returnPage = '/wiki/'+decodeURI(returnPage.replace(/\+/g,' '));
    }
    return returnPage;
}

function addOnloadHookIfAvailable(f) {
    if (typeof addOnloadHook == "undefined") { 
        console.info("addOnloadHook not available");
        return;
    }
    addOnloadHook(f);
}

addOnloadHookIfAvailable(aheadGo);