Jump to content

User:DatRoot/Skins/Skin2.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DatRoot (talk | contribs) at 23:32, 14 November 2007. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function addLink(parent, link)
{
    if(typeof(link) == "string") link = document.getElementById(link);
    if(!link) return;
    if(typeof(parent) == "string") parent = document.getElementById(parent);
    if(!parent) return;
    
    for(parent = parent.firstChild; parent != null; parent = parent.nextSibling)
    {
        if(parent.className == "pBody")
        {
            for(parent = parent.firstChild; parent != null; parent = parent.nextSibling)
            {
                if(parent.nodeName == "UL")
                {
                    parent.appendChild(link);
                    return link;
                }
            }
        }
    }
}
            
/*
 *  Set up the elements for the skin
 */ 
addOnloadHook(function () 
{
    // Add "Actions" label unless in a namespace that won't have them
    if(wgNamespaceNumber >= 0)
    {
        var actionsLabel = document.createElement("li");
        actionsLabel.className = "cactionsLabel";
        actionsLabel.innerHTML = "Actions>";
        var firstAction = document.getElementById("ca-edit");
        if(!firstAction) firstAction = document.getElementById("ca-viewsource");
        if(firstAction) firstAction.parentNode.insertBefore(actionsLabel, firstAction);
    }
    
    // Rename edit link from "Edit this page" to "Edit"
    var editLink = document.getElementById("ca-edit");
    if(editLink) editLink.firstChild.innerHTML = "Edit";

    // Rename add section link from "+" to "Add section"
    var addSectionLink = document.getElementById("ca-addsection");
    if(addSectionLink) addSectionLink.firstChild.innerHTML = "Add section";
    
    // Add all page-related links to 'p-cations'
    if(wgNamespaceNumber >= 0)
    {
        var cactions = document.getElementById("p-cactions");
        addLink(cactions, document.createElement("br"));
        var relatedLabel = document.createElement("li");
        relatedLabel.className = "cactionsLabel";
        relatedLabel.innerHTML = "Related>";
        addLink(cactions, relatedLabel);
        addLink(cactions, "ca-history");
        addLink(cactions, "t-contributions");
        addLink(cactions, "t-recentchangeslinked");
        addLink(cactions, "t-whatlinkshere");
        addLink(cactions, "t-emailuser");
        addLink(cactions, "t-permalink");
        addLink(cactions, "t-print");
        addLink(cactions, "t-cite");
    }
    
    // Add some links to toolbox and move it to above search
    var toolbox = document.getElementById("p-tb");
    addLink(toolbox, "n-recentchanges");
    addLink(toolbox, "n-randompage");
    toolbox.parentNode.insertBefore(toolbox, document.getElementById("p-navigation"));

    // Move search to above navigation
    var search = document.getElementById("p-search");
    search.parentNode.insertBefore(search, document.getElementById("p-navigation"));
    
    
/* 
    if(wgNamespaceNumber == 0) 
        addLinkElem(pageLinksElem, "t-log", "logs", "/w/index.php?title=Special:Log&page=" + wgPageName);
    else 
        addLinkElem(pageLinksElem, "t-log", "logs", "");
 
    // Re-order portlets
    var columnOneElem = document.getElementById("column-one");
    columnOneElem.insertBefore(document.getElementById("p-navigation"), columnOneElem.firstChild);
    columnOneElem.insertBefore(document.getElementById("p-search"), columnOneElem.firstChild);
    columnOneElem.insertBefore(toolboxElem, columnOneElem.firstChild);
*/
});