Utenti:.anaconda/monobook.js

Dâ Wikipedia, la nciclupidìa lìbbira.

Nota: doppu aviri sarvatu, hai a puliri la cache di lu tò browser pi vìdiri li canciamenti: Mozilla: clicca supra reload (oppure ctrl-r), IE / Opera: ctrl-f5, Safari: cmd-r, Konqueror ctrl-r.

// <pre><nowiki>

// Cosa:
//   * aggiunge link agli edit del bot in p-personal
//   * aggiunge tab "ultima modifica" e "purge" nelle pagine

// Based on [[it:Utente:Helios89/monobook.js]]
// Licensed under the cc-by-sa-2.5-it, when applicable. Original work is licensed under the GFDL+GPL

// Initialize on window load
if (window.addEventListener)
    window.addEventListener("load", myLoadFuncs,false);
else if (window.attachEvent)
    window.attachEvent("onload", myLoadFuncs);
else
{
    window.previousLoadFunction = window.onload;
    window.onload = function()
    {
        window.previousLoadFunction();
        myLoadFuncs();
    }
}

// Load custom functions
function myLoadFuncs()
{
    // Add something here...
}

if (document.createElement && window.addEventListener)
{
    function SoFixItInit() // pre-load, (don't want to slow down loading of article's content, though)
    {
    }

    function SoFixItLoad() // post-load
    {
        UserMenu = new PortletMenu('p-personal');
        PageMenu = new PortletMenu('p-cactions');

        function GetByClass(sElem, sClass)
        {
            var i, a2 = [], a = document.getElementsByTagName(sElem);
            for (i = 0; i < a.length; i++)
                if (a[i].className == sClass)
                    a2.push(a[i]);
            return a2;
        }

        var a, td = GetByClass('td', 'diff-otitle');
        if ((td = td[0]) && (a = td.getElementsByTagName('a')[0]))
            a.href = a.href + '&action=edit'; // need to change text, later

        UserMenu.insertBefore('pt-logout', 'pt-botcontris', 'edit del bot', '/wiki/Special:Contributions/.anacondabot');

        // Article's tabs
        if (PageMenu['ca-history']) // If there's no history, then there's no last diff...
        {
            // tab "ultima modifica"
            PageMenu.insertBefore('ca-move', 'ca-lastdiff', 'ultima modifica', PageMenu.getHref('ca-history').replace(/action=history/, 'diff=0'));
            // tab "purge"
            PageMenu.append('ca-purge', 'purge', PageMenu.getHref('ca-history').replace(/action=history/, 'action=purge'));
        }
    }

    function PortletMenu(id)
    {
        this.menu = document.getElementById(id);
        this.list = this.menu.getElementsByTagName('ul')[0]; // bypass "<h5>Views</h5>", etc.

        // sigh...as far as I can figure, there is empty whitespace being treated
        // as TextNodes....
        var LIs = this.list.getElementsByTagName('li');

        for (var i = 0; i < LIs.length; i++)
        {
            this[LIs[i].id] = LIs[i];
        }

        this.newItem = function(id, txt, url)
        {
            var li = document.createElement('li');
            li.id = id;
            var  a = document.createElement('a');
            a.href = url;
            a.appendChild(document.createTextNode(txt));
            li.appendChild(a);
            this[id] = li; // watch this!!!
            return li;
        }

        this.append = function(id, txt, url)
        {
            this.list.appendChild(this.newItem(id, txt, url));
        }

        this.insertBefore = function(old, id, txt, url)
        {
            this.list.insertBefore(this.newItem(id, txt, url), this[old]);
        }

        // the ByTagName here is a bit annoying, but in Safari, I was picking
        // up TextNodes by using this[id].firstChild.firstChild
        this.getText = function(id) { return this[id].getElementsByTagName('a')[0].firstChild.data }
        this.setText = function(id, txt) { this[id].getElementsByTagName('a')[0].firstChild.data = txt }
        this.getHref = function(id) { return this[id].getElementsByTagName('a')[0].href }
        this.setHref = function(id, url) { this[id].getElementsByTagName('a')[0].href = url }
    }

    SoFixItInit();
    window.addEventListener('load', SoFixItLoad, false);
}

// Returns: <li><a href="url">name</a></li>
function addlilink(url, name)
{
    var na = document.createElement('a');
    na.setAttribute('href', url);
    var txt = document.createTextNode(name);
    na.appendChild(txt);
    var li = document.createElement('li');
    li.appendChild(na);
    return li;
}

// </nowiki></pre>