Utente:Salvatore Ingala/commandline.js

Versione del 17 dic 2006 alle 23:56 di Salvatore Ingala (discussione | contributi) (Nuova pagina; testo: '<pre><nowiki>: *** Command Line Start ***: //Funzioni di Timendum //Segna "modifica minore" function TimenME() { document.getElementById("wpMinoredit").checked=1;...')
(diff) ← Versione meno recente | Versione attuale (diff) | Versione più recente → (diff)

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> */

/**** Command Line Start ****/


//Funzioni di Timendum
//Segna "modifica minore"
function TimenME() {
  document.getElementById("wpMinoredit").checked=1;
}
//Aggiungi all'oggetto
function TimenSA(text) {
  var summ=document.getElementById("wpSummary");
  if (summ == null)
    return;
  summ.value=summ.value+text;
}
//Aggiungi testo prima
function TimenPr(text) {
  wpTextbox1=document.getElementById("wpTextbox1");
  wpTextbox1.value=text+wpTextbox1.value;
}
//Aggiungi testo dopo
function TimenDp(text) {
  wpTextbox1=document.getElementById("wpTextbox1");
  wpTextbox1.value=wpTextbox1.value+text;
}

function mese(){
  var today = new Date();
  return (new Array("gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto",
                      "settembre","ottobre","novembre","dicembre"))[today.getMonth()];
}

function anno(){
  var today = new Date(); return today.getYear()+1900;
}

//Comandi
//cmd['nome comando'] = [funzione, 'commento'];
cmd = new Object();
cmd['a']             = [cmd_a, 'Da aiutare; richiede motivo e argomento'];
cmd['c']             = [cmd_c, 'Da aiutare; richiede motivo e argomento'];
cmd['e']             = [cmd_e, 'Avviso enciclopedicità dubbia; richiede motivo e argomento'];
cmd['p']             = [cmd_p, 'Avviso nNPOV; richiede motivo e argomento'];
cmd['w']             = [cmd_w, 'Da wikificare; richiede argomento'];
cmd['s']             = [cmd_s, 'Stub; richiede argomento (opzionale)'];
cmd['categorizzare'] = [cmd_categorizzare, 'Da categorizzare'];
cmd['unire']         = [cmd_unire, 'Da unire; richiede la voce simile'];
cmd['purge']         = [cmd_purge, 'Aggiorna la cache'];
cmd['fixformat']     = [cmd_fixformat, 'Sostituzioni automatiche'];
cmd['replace']       = [cmd_replace, 'Cerca e sostituisci'];
cmd['benvenuto']     = [cmd_benvenuto, 'Messaggio di benvenuto'];
cmd['save']          = [cmd_save, 'Simula la pressione del tasto di salvataggio'];
cmd['preview']       = [cmd_preview, 'Simula la pressione del tasto "Visualizza anteprima"'];
cmd['diff']          = [cmd_diff, 'Simula la pressione del tasto "Mostra cambiamenti"'];

//Preleva un argomento dalla commandline se possibile, altrimenti preleva tramite prompt()
function getArg(text)
{
  if (cmdline_command_array[cmdline_next_argument] != null)
    return cmdline_command_array[cmdline_next_argument++];
  else
    return prompt(text);
}


//Template:A
function cmd_a(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  TimenPr('{{A|motivo='+(getArg("Motivo"))+'|argomento='+(getArg("Argomento"))+'|mese='+mese()+' '+anno()+'|firma=~~~~}}\n');
  TimenSA('+da aiutare; '); TimenME();
}
//Template:W
function cmd_w(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  TimenPr('{{W|argomento='+(getArg("Argomento"))+'|mese='+mese()+' '+anno()+'|firma=~~~~}}\n');
  TimenSA('+wikificare; '); TimenME();
}
//Template:E
function cmd_e(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  TimenPr('{{E|'+(getArg("Motivo"))+'|'+(getArg("Argomento"))+'|'+mese()+' '+anno()+'|~~~~}}\n');
  TimenSA('+avviso enciclopedicità dubbia; '); TimenME();
}
//Template:P
function cmd_p(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  TimenPr('{{P|motivo='+(getArg("Motivo"))+'|argomento='+(getArg("Argomento"))+'|mese='+mese()+' '+anno()+'|firma=~~~~}}\n');
  TimenSA('+avviso nNPOV; '); TimenME();
}
//Template:C
function cmd_c(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  TimenPr('{{C|motivo='+(getArg("Motivo"))+'|argomento='+(getArg("Argomento"))+'|mese='+mese()+' '+anno()+'|firma=~~~~}}\n');
  TimenSA('+da controllare; '); TimenME();
}
//Template {{S}}
function cmd_s(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  var argomento = getArg("Argomento");
  TimenPr('{{S' + (((argomento != null)&&(argomento!='')) ? ('|' + argomento + '}}\n') : '}}\n'));
  TimenSA('+stub; '); TimenME();
}
//Template {{categorizzare}}
function cmd_categorizzare(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  TimenDp('{{Categorizzare}}\n'); TimenSA('da categorizzare; '); TimenME();
}
//Template {{Da unire}}
function cmd_unire(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  TimenPr('{{Da unire|' + getArg("Voce:") + '}}\n');
  TimenSA('+da unire; '); TimenME();
}

//Benvenuto ai nuovi utenti
function cmd_benvenuto(){
  TimenDp('{{benve|nome={{subst:PAGENAME}}|~~~ ~~~~~}}'); TimenSA('Benvenuto su it.wiki!'); TimenME();
}

//Aggiorna cache
function cmd_purge(){
    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];
    ___location.href=x.href.replace(/action=history/g, "action=purge");
}

//Sostituzioni automatiche
function cmd_fixformat(){
  var form = document.editform;
  var txt = form.wpTextbox1;
  if (txt==null) return;
  txt.value = txt.value
    .replace(/\’/g, "'")
    .replace(/ '([\w\ ]+)' /g, ' "$1" ')
    .replace(/“/g,'"')
    .replace(/”/g,'"')
    .replace(/–/g, '-')
    .replace(/,,/g, ',')
    .replace(/ m2 /g, ' m² ')
    .replace(/a' /g, "à ")
    .replace(/([^p])o' /g, "$1ò ")
    .replace(/u' /g, "ù ")
    .replace(/i' /g, "ì ")
    .replace(/ anzich(è|e')/g, "anziché")
    .replace(/ affinch(è|e')/g, "affinché")
    .replace(/ bench(è|e')/g, " benché")
    .replace(/ cioé/g, " cioè")
    .replace(/ Dè /g, " De' ")
    .replace(/ dè /g, " de' ")
    .replace(/ dò/g, " do")
    .replace(/E' /g, "È ")
    .replace(/É /g, "È ")
    .replace(/ e' /g, " è ")
    .replace(/ é/g, " è")
    .replace(/ fà /g, " fa ")
    .replace(/ fè /g, " fe' ")
    .replace(/ Frà /g, " Fra' ")
    .replace(/ fù /g, " fu ")
    .replace(/ mò /g, " mo' ")
    .replace(/ nè /g, " né ")
    .replace(/ ne' /g, " né ")
    .replace(/ nonch(è|e')/g, " nonché")
    .replace(/ pè /g, " pe' ")
    .replace(/ perch(è|e')/g, " perché")
    .replace(/ per(ó|o') /g,' però ')
    .replace(/ piu' /g, " più ")
    .replace(/ pò/g, " po'")
    .replace(/ poich(è|e') /g, " poiché ")
    .replace(/ propio/g, "  proprio")
    .replace(/ (puo|puo') /gi,' può ')
    .replace(/ quì /gi, " qui ")
    .replace(/ quà /gi, " qua ")
    .replace(/ qual'è /gi, " qual è")
    .replace(/ sà /gi, " sa ")
    .replace(/ sè /gi, " sé ")
    .replace(/si' /g, "sì")
    .replace(/ sò /g, " so ")
    .replace(/ sù /g, " su ")
    .replace(/ tr(è|e'|é) /g, " tre ")
    .replace(/ sucessivo /gi, " successivo ")
    .replace(/</g,'<')
    .replace(/>/g,'>')
    .replace(/&/g,'&')
    .replace(/"/g,'"')
    .replace(/à/g,'à')
    .replace(/è/g,'è')
    .replace(/é/g,'é')
    .replace(/ì/g,'ì')
    .replace(/¡/g,'¡')
    .replace(/¢/g,'¢')
    .replace(/£/g,'£')
    .replace(/¥/g,'¥')
    .replace(/´/g,"'")
    .replace(/±/g,'±')
    .replace(/×/g,'×')
    .replace(/÷/g,'÷')
    .replace(/µ/g,'µ')
    .replace(/°/g,'°')
    .replace(/¼/g,'¼')
    .replace(/½/g,'½')
    .replace(/¾/g,'¾')
    .replace(/¹/g,'¹')
    .replace(/²/g,'²')
    .replace(/³/g,'³')
    .replace(/§/g,'§')
    .replace(/<\/?(b|strong)>/gi, "'''")
    .replace(/<\/?(i|em|var)>/gi, "''")
    .replace(/<br>\n\n/g,'\n\n')
    .replace(/<br>/gi,'<br />')
    .replace(/\n<hr[ \/]*>\n/gi, '\n----\n')
    .replace(/ +<hr[ \/]*> +/gi, '\n----\n')
    .replace(/<hr ([^>\/]+?)>/gi,'<hr $1 />')
    .replace(/\n *<h1> *([^<]+?) *<\/h1> *\n/gi,  "\n= $1 =\n")
    .replace(/\n *<h2> *([^<]+?) *<\/h1> *\n/gi,  "\n== $1 ==\n")
    .replace(/\n *<h3> *([^<]+?) *<\/h1> *\n/gi,  "\n=== $1 ===\n")
    .replace(/\n *<h4> *([^<]+?) *<\/h1> *\n/gi,  "\n==== $1 ====\n")
    .replace(/\n *<h5> *([^<]+?) *<\/h1> *\n/gi,  "\n===== $1 =====\n")
    .replace(/\n *<h6> *([^<]+?) *<\/h1> *\n/gi,  "\n====== $1 =======\n")
    ;
  TimenSA("Formattazione; "); TimenMe();
}

//Cerca e sostituisci
function cmd_replace(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  var s = getArg("Regexp da cercare?");
  if(s){
    var r = getArg("Sostituire con?");
    if(!r && r != '') return;
    var txt = wpTextbox1;
    txt.value = txt.value.replace(new RegExp(s, "g"), r);
  }
}

//Premi "Salva"
function cmd_save(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  document.getElementById("wpSave").click();
}
//Premi "Visualizza anteprima"
function cmd_preview(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  document.getElementById("wpPreview").click();
}
//Premi "Mostra cambiamenti"
function cmd_diff(){
  wpTextbox1=document.getElementById("wpTextbox1");
  if (wpTextbox1 == null) return;
  document.getElementById("wpDiff").click();
}


function runCommand(command){
  var commandline = command;
  //WARNING: variabile globale
  cmdline_command_array = commandline.split('#');

  //WARNING: variabile globale: indice del prossimo argomento da leggere
  cmdline_next_argument = 0;
  while((command = cmdline_command_array[cmdline_next_argument++]) != null){
    wpTextbox1=document.getElementById("wpTextbox1");
    if (cmd[command] != null){
      cmd[command][0]();
      continue;
    }

    //Cerchiamo se è prefisso univoco di un comando
    var found = ''
    for (var x in cmd)
      if (x.indexOf(command) == 0)
        if (found == '')
          found = x;
        else {
          alert("Comando ambiguo!");
          return;
        }
    if (found != '')
      cmd[found][0](); //tutto a posto, eseguiamo
  }
}

function showCommandLine(){
  runCommand(prompt("Comando:"));
}

function addCommandLine()
{
  var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
  addlilink(tb, "javascript:showCommandLine()", 'Command line', 'tb-cmdline');
  ta['ca-delete'] = [' ', 'Cancella questa pagina'];
  ta['tb-cmdline'] = ['d', 'Command line'];
  akeytt();
}
addOnloadHook(addCommandLine);

function fakeActionRunCommands(){
  if (getParamValue("fakeaction") == "runcommand"){
    var commandline = getParamValue("command");
    runCommand(commandline);
  }
}

/**** Command Line End ****/

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