Utente:Alec/vector.js

Versione del 31 mag 2006 alle 12:04 di Alec (discussione | contributi) (toolbar timendum)

Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.


Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.

/* <pre><nowiki> */

/**
 * Derivato dal monobook.js di [[:en:User:Wayward]], basato su [[:en:User:Alphax/monobook.js]]
 * Necessita dell'apposito monobook.css
 * Testato solo su Firefox
 * Contiene codice preso dagli script di [[Utente:Paulatz]], [[Utente:Helios89]], [[Utente:Timendum]]
 * Forked from [[User:ABCD/monobook.js]] around April 2005
 * Dual licensed under the GFDL and GPL
 */

/** VARIABILI GLOBALI **/
arrayArgument = new Array("antropologia", "archeologia", "architettura", "biografie", "biologia", "calcio", "chimica", "cinema",
                "diritto", "economia", "fantascienza", "filosofia", "fisica", "fumetti", "geografia", "giochi", "informatica", "ingegneria",
                "letteratura", "matematica", "meccanica", "medicina", "musei", "musica", "politica", "religione", "scienza", 
                "sociologia", "sport", "storia", "teatro", "televisione", "wrestling");

arrayMese = new Array("gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", 
                      "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre");

var curTemplate;

/**** Inizializzazione ****/

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();
    }
}

/**** Carica le funzioni personalizzate ****/

function myLoadFuncs()
{
    addPurge();        // aggiunge pulsante "purge"
    changeLinks();     // modifica il menu personale
    add_tabs();        // aggiunge i tab
    addToolBoxLinks(); // aggiunge i link nel portlet "strumenti"
    addNavBarLinks();  // aggiunge i link nel portlet "navigazione"
    ta['pt-logout'] = ['x', 'Logout (esci)']; //cambia l'accesskey per "logout"
    akeytt();    
}

// Functions auxFicus and Ficus
function auxFicus(){
    Argument = document.getElementById('inlinePopupDiv').getElementsByTagName('select')[0].value;

    wpTextbox1 = document.getElementById("wpTextbox1");
    if (curTemplate == "W") 
        wpTextbox1.value="{{"+curTemplate+"|"+Argument+"|"+"{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}|~~~~}}"+wpTextbox1.value;
    else {
        Because = document.getElementById('inlinePopupDiv').getElementsByTagName('input')[0].value;
        wpTextbox1.value="{{"+curTemplate+"|"+Because+"|"+Argument+"|"+"{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}|~~~~}}"+wpTextbox1.value;
    }

    switch(curTemplate){
    case "A": var summary = "+Aiutare"; break;
    case "C": var summary = "+Controllare"; break;
    case "P": var summary = "+nNPOV"; break;
    case "W": var summary = "+Wikificare"; break;
    }

    summ=document.getElementById("wpSummary");
    summ.value=summ.value+summary;
    RemoveNode('inlinePopupDiv');
}

function Ficus(Template){
    switch(Template){
    case "A":
        Greeter = "Hai richiesto di inserire questa pagina nella Categoria <b>\"Da aiutare\"</b>\n." +
                  " Per favore scrivi una motivazione e scegli un argomento dalla lista";
        break;
    case "C":
        Greeter = "Hai richiesto di inserire questa pagina nella Categoria <b>\"Da controllare\"</b>\n." +
                  " Per favore scrivi una motivazione e scegli un argomento dalla lista";
        break;
    case "P":
        Greeter = "Hai richiesto di inserire questa pagina nella Categoria <b>\"Segnalazioni NPOV\"</b>\n." +
                  " Per favore scrivi una motivazione e scegli un argomento dalla lista";
        break;
    case "W":
        Greeter = "Hai richiesto di inserire questa pagina nella Categoria <b>\"Da wikificare\"</b>\n." +
                  " Per favore scegli un argomento dalla lista.";
        break;
    default: Greeter = "Qualcosa è andato storto, fai pure quello che vuoi: non ho idea di cosa succederà"
    }

    curTemplate = Template;

    var div = document.createElement('div');
        div.id = 'inlinePopupDiv';
        div.style.position = 'absolute';
        div.style.zIndex   = 1000;
        div.style.left     =  '5px';
        div.style.top      =  '5px';
        div.style.backgroundColor = '#FFFFFF';
        div.style.borderStyle     = 'solid';
        div.style.borderWidth     = ' medium';
        div.style.borderColor     = '#000000';

        var top = document.createElement('div');
            top.id = 'inlinePopupTop';
            top.style.textAlign = 'right';
            top.style.margin = '8px';
            top.style.backgroundColor = '#DDDDDD';

            var a = document.createElement('a');
                a.appendChild( document.createTextNode('Close'));
                a.href = "javascript:void RemoveNode('inlinePopupDiv')";
                a.style.margin = '8px';

            top.appendChild(a);

        div.appendChild(top);

        var greet = document.createElement('p');
        greet.innerHTML = Greeter;
        div.appendChild(greet);

        var form = document.createElement('form');
        form.name = "popupForm";
        var p = document.createElement('p');

            p.appendChild(document.createTextNode('Motivazione:'));
            if(Template != 'W'){
                var myedit = document.createElement('input');
                myedit.name = 'editReason';
                myedit.type = 'text';
                p.appendChild(myedit);
            }

            p.appendChild(document.createTextNode('Argomento:'));

            var sel = document.createElement('select');
            sel.name = 'popupSelect';
            sel.size = 1;
            var option;
            for (i = 0; i < arrayArgument.length; i++){
                option = new Option(arrayArgument[i],' ');
                option.value = arrayArgument[i];
                sel.options[sel.options.length] = option;
            }
            p.appendChild(sel);

            var button = document.createElement('input');
            button.value = 'OK';
            button.type = 'button';
            button.setAttribute('onclick', 'auxFicus()');
            p.appendChild(button);

        form.appendChild(p);
        div.appendChild(form);

    document.body.appendChild(div);
    div.getElementsByTagName('input')[0].focus();
}

/**** Personalizza i link della barra personale ****/

function changeLinks()
{
    if(!document.getElementById) return;

    // Modifica i link
    document.getElementById('pt-mytalk').firstChild.innerHTML = 'discussione';
    document.getElementById('pt-preferences').firstChild.innerHTML = 'preferenze';
    document.getElementById('pt-watchlist').firstChild.innerHTML = 'osservati speciali';
    document.getElementById('pt-mycontris').firstChild.innerHTML = 'contributi';

    // Aggiunge l'orologio
    var toplinks = document.getElementById('p-personal').getElementsByTagName('ul')[0];
    addlilink(toplinks, '#', '', 'utcdate');
    showtime();
}

/**** Aggiunge un generico tab ****/

function addlilink(tabs, url, name, id){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}

/**** Aggiunge un tab come menu ****/

function addlimenu(tabs, name, id)
{
    var na = document.createElement('a');
    na.href = '#';
    var mn = document.createElement('ul');
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.className = 'tabmenu';
    li.appendChild(na);
    li.appendChild(mn);
    tabs.appendChild(li);
    return li;
}

/**** Aggiunge il tab "purge" ****/

function addPurge()
{
    ta['ca-purge'] = ['g', 'Pulisci la cache'];
    if(!document.getElementById) return;
    var x = document.getElementById('ca-history');
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(!x) return;
    if(x.children) x = x.children[0];
    else x = x.childNodes[0];
    
    var pf = document.createElement('form');
    pf.action = '?action=purge';
    pf.method = 'POST';
    pf.id = 'pf';
    x.appendChild(pf);
    
    addlilink(tabs, 'javascript:document.getElementById("pf").submit();', 'aggiorna', 'ca-purge');
    akeytt();
}

function getParam(name){
    if(___location.search){
        for(var x in ___location.search.substring(1).split('&')){
            var eq = x.indexOf('=');
            if(x.substring(0, eq) == name) return x.substring(eq + 1);
        }
    }
    return '';
}

/**** Menu "strumenti vari" ****/

//Sostituzioni automatiche
function fixformat(){
    var form = document.editform;
    var txt = form.wpTextbox1;
    txt.value = txt.value
        .replace(/<\/?(b|strong)>/gi, "'''")
        .replace(/<\/?(i|em|var)>/gi, "''")
        .replace(/\’/g, "'")
        .replace(/E' /g, "È ")
        .replace(/É /g, "È ")
        .replace(/ pò/g, " po'")
        .replace(/ e'/g, " è")
        .replace(/ é/g, " è")
        .replace(/ nè /g, " né ")
        .replace(/ ne' /g, " né ")
        .replace(/piu'/g, "più")
        .replace(/ quà/g, " qua")
        .replace(/qual'è/g, "qual è")
        .replace(/affinchè/g, "affinché")
        .replace(/affinche'/g, "affinché")
        .replace(/benchè/g, "benché")
        .replace(/benche'/g, "benché")
        .replace(/perchè/g, "perché")
        .replace(/perche'/g, "perché")
        .replace(/poichè/g, "perché")
        .replace(/poiche'/g, "poiché")
        .replace(/ sè /g, " sé ")
        ;
    form.wpSummary.value += "formattazione";
    form.wpMinoredit.checked = true;
}

//Cerca e sostituisci
function replace(){
    var s = prompt("Search regexp?");
    if(s){
        var r = prompt("Replace regexp?");
        if(!r && r != '') return;
        var txt = document.editform.wpTextbox1;
        txt.value = txt.value.replace(new RegExp(s, "g"), r);
    }
}

/**** Funzioni per le pagine di discussione ****/

// Appends msg to the currently editted page, sets the summary to summ,
// marks or unmarks the "Watch this page" checkbox according to watch,
// and marks or unmarks the "Minor edit" checkbox
function edit_summary_watch(msg, summ, watch, minor)
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += msg;
  f.wpSummary.value = summ;
  f.wpWatchthis.checked = watch;
  f.wpMinoredit.checked = minor;
}

// Like the former one, but adds "msg" in the beginning and not after the end
function edit_summary_watch2(msg, summ, watch, minor)
{
  var f = document.editform, t = f.wpTextbox1;
  t.value = msg + '\n' + t.value;
  f.wpSummary.value = summ;
  f.wpWatchthis.checked = watch;
  f.wpMinoredit.checked = minor;
}

// Places perm block and name block tags at top of edit section,         
// marks or unmarks the "Watch this page" checkbox according to watch,
// and marks or unmarks the "Minor edit" checkbox 
function perm_name_block(msg, summ, watch, minor)                                
{                                                                          
  var f = document.editform, t = f.wpTextbox1;                            
  if (t.value.length > 0)                                                
      t.value += '\n';                                                  
  var temp = t.value;                                                    
  t.value = msg + '\n\n' + temp;                                                                                                            
  f.wpSummary.value = summ;                                                
  f.wpWatchthis.checked = watch; 
  f.wpMinoredit.checked = minor;
}

/**** Aggiunge i tab e i menu ****/

// adds various tabs and menu tabs
function add_tabs()
{
  var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];

  //Solo per le pagine di discussioni degli utenti
  if((document.title.indexOf("Modifica") != -1) && (document.title.indexOf("Discussioni utente") != -1))
  {
    addlimenu(tabs, 'Messaggi talk', 'talkm');
    var talkm = document.getElementById('talkm').getElementsByTagName('ul')[0];
    addlilink(talkm,'javascript:edit_summary_watch("{{subst:benve|~~~~}}", "Benvenuto", false, true)','welcome', 'pb-welcome');
    ta['pb-welcome'] = new Array('b', 'Da il benvenuto');
    addlilink(talkm,'javascript:edit_summary_watch("{{test}} ~~~~", "test", false, true)','Test', '');
    addlilink(talkm,'javascript:edit_summary_watch("{{vandalismo}} ~~~~", "Avviso vandalismo", false, true)','Vandal', '');
    addlilink(talkm,'javascript:edit_summary_watch("{{spam}} ~~~~", "spam", false, true)','Spam', '');
    addlilink(talkm,'javascript:edit_summary_watch("{{Avvisocopyviol|articolo=|url=}} ~~~~","avviso violazione di copyright",false,true)','avviso cv','');
 addlilink(talkm,'javascript:edit_summary_watch("{{Avvisocancellautente|wikilink=[[Titolo_pagina]]}}- ~~~~","avviso proposta di cancellazione",false,true)','avviso canc','');
  } 
  else if (document.title.indexOf("Modifica") != -1) // Solo durante le modifiche
  {
    addlimenu(tabs, 'strumenti vari', 'tools');
    var tools = document.getElementById('tools').getElementsByTagName('ul')[0];
    addlilink(tools,'javascript:fixformat()','format', '');
    addlilink(tools,'javascript:replace()','replace', '');
    addlilink(tools,'javascript:edit_summary_watch2("{{cancelcopy|firma=~~~|fonte=}}", "cancelcopy", false, true)','cancelcopy', '');
    addlilink(tools,'javascript:edit_summary_watch2("{{da cancellare}}", "cancellare", false, true)','da cancellare', '');
  }
}

/**** Aggiunge i link in "strumenti" ****/

function addToolBoxLinks()
{
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
    var cur_user=document.getElementById("pt-userpage").textContent;
    addlilink(tb, 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=itwiki_p&user=' + cur_user, 'Edit count', '');
    username_a = document.URL.match(/:.*:(.*)/);
    username=username_a[1];
    addlilink(tb, 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=itwiki_p&user='+username,'User\'s edit count', '');
    addlilink(tb, '/wiki/Speciale:Log', 'Log', '');
}

/**** Aggiunge i link in "navigazione" ****/

function addNavBarLinks()
{   
    var navbar = document.getElementById('p-navigation').getElementsByTagName('ul')[0];
    var username=document.getElementById("pt-userpage").textContent;
    addlilink(navbar, '/wiki/Speciale:Newpages', 'Pagine nuove', '');   
    addlilink(navbar, '/w/index.php?title=Utente:' + username + '/monobook.js&action=edit', 'monobook.js', '');   
    addlilink(navbar, '/w/index.php?title=Utente:' + username + '/monobook.css&action=edit', 'monobook.css', ''); 
}

/**** L'orologio che si aggiorna automaticamente ****/

function showtime()
{
    var timerID;
    var now = new Date();
    var timeValue = now.toUTCString().replace(/GMT/, "UTC");
    document.getElementById('utcdate').firstChild.innerHTML = timeValue;
    timerID = setTimeout('showtime()', 100);
}

/**** Aggiunge il link "unwatch" nella watchlist ****/

addOnloadHook(function () {
    var query_prefix = "title=Speciale:Watchlist&action=submit&remove=1&id[]=";
    var query_prefix = "action=unwatch&title=";

    if (window.___location.href.indexOf("Speciale:Watchlist") == -1) return;
    var links = document.getElementById('content').getElementsByTagName('a');
    for (var i = 0; i < links.length; i++) {
        if (links[i].href.substring(links[i].href.length-15) != '&action=history')
            continue;
        var unwatch = document.createElement('a');
        unwatch.href = "/w/index.php?" + query_prefix + encodeURIComponent(links[i].title);
        unwatch.title = "Unwatch "+links[i].title;
        unwatch.appendChild(document.createTextNode("non seguire"));
        links[i].parentNode.insertBefore(unwatch, links[i].nextSibling);
        // kluge to handle case where "diff" is unlinked:
        var delim = links[i].previousSibling;
        delim = (delim.nodeType == 3 ? delim.nodeValue : "");
        links[i].parentNode.insertBefore(document.createTextNode(delim.replace(/^.*diff/, "")), unwatch);
    }
});

/**** Funzioni varie ****/

//Elimina un Node
function RemoveNode(id){
    var node = document.getElementById(id)
    node.parentNode.removeChild(node);
}

//Crea un portlet vuoto che può essere riempito con
//le successive chiamate a AddToPortlet.
//PARAMS:
//*      title: Top label of the portlet
//*      newid: The id of the new portlet, needed to call addToPortlet
//* beforewhat: The name of an existing portlet; the new portlet is placed before it.
//              If void or invalid, the portlet is added after all the other ones.
function createPortlet(title, newid, beforewhat)
{
    var y;
    var z;
    var f = document.getElementById("column-one");

    var portlet = document.createElement('div');

    var pos;
    if (beforewhat) pos = document.getElementById(beforewhat);

    portlet.className = "portlet";
    portlet.id = newid;
    y = document.createElement('h5');
    y.appendChild(document.createTextNode(title));

    portlet.appendChild(y);

    y = document.createElement('div');
    y.className= "pBody";

    portlet.appendChild(y);

    if (beforewhat) f.insertBefore(portlet, pos);
    else f.appendChild(portlet);
   
}

//Aggiunge qualcosa ad un portlet.
//PARAMS:
//*  id: The id of the portlet.
//* obj: The object to be added. 
function addToPortlet(id, obj)
{
    var f = document.getElementById(id);

    f = f.getElementsByTagName("div")[0];
    f.appendChild(obj);
}

/**** Aggiunge il pulsante "Allpages" nel portlet "ricerca" ****/

function allpages_button_click(){
    var inputs = document.getElementById("p-search").getElementsByTagName('input');
    var i;
    for (i = 0; i < inputs.length; ++i)
      if (inputs[i].type == "text")
        top.___location.href = 'http://it.wikipedia.org/wiki/Speciale:Allpages/' + inputs[i].value;
}

function setup_allpages_button(){
    var button = document.createElement('input');
    button.type = "button";
    button.value = "Allpages";
    button.setAttribute('onClick', 'allpages_button_click()');

    addToPortlet("p-search", document.createElement("hr"));
    addToPortlet("p-search", button);

}
addOnloadHook(setup_allpages_button);



/**** Personalizzazione della ToolBar ****/

function addToolbarButton(id, href, src, alt, title)
{
  var toolbar = document.getElementById("toolbar");
  var today = new Date();
  var anno= today.getYear()+1900;
  var mese = arrayMese[today.getMonth()];

  var tmp = document.createElement("a");
  tmp.id = id;
  tmp.href = href;
  var imag = document.createElement("img");
  imag.setAttribute('src', src);
  imag.setAttribute('alt', alt);
  imag.setAttribute('title', title);
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);
}

function addText(text, summary, n)
{
  wpTextbox1=document.getElementById("wpTextbox1");
  if (n == 0)
    wpTextbox1.value=text + "\n" +wpTextbox1.value;
  else
    wpTextbox1.value=wpTextbox1.value + text;
  summ=document.getElementById("wpSummary");
  summ.value=summ.value+summary;
  document.getElementById("wpMinoredit").checked=1
}

// ToolbarButton
// Vedi [[Utente:Timendum/Javascript]]
// <nowiki>
var dell = "gra cor lin ext == img med mat now sig hr";
var agg = "sign strk under sml pre tt tmpl ttl comm typo voto cat gall vedi wik stu aiu cate uni red dsmb cncp del ctrcp bloc ben adel vand test avcpy spam licim";
var wikisign_pre = '~~~~';
var wikisign_post = '';
document.writeln('<script type="text/javascript" src="/w/index.php?title=Utente:Timendum/Toolbar.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
// </nowiki>

/**** Fine ****/

/* </nowiki></pre> */