Wikibooks:Monobook.js/MonobookCompleto.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
versione 4.5 con command line
prova
Riga 11:
* Dual licensed under the GFDL and GPL
*/
 
/**** Command Line Start ****/
 
arrayArgument = new Array("aeronautica", "agricoltura", "allevamento", "alpinismo", "animali", "animanga", "antropologia", "antroponimi", "archeologia", "architettura", "arte", "arti divinatorie", "arti marziali", "astronomia", "atletica", "automobilismo", "aziende", "baseball", "biografie", "biologia", "blues", "botanica", "buddismo", "calcio", "canottaggio", "cattolicesimo", "chimica", "ciclismo", "cinema", "classica", "cristianesimo", "cucina", "curling",
"danza", "diritto", "ebraismo", "ecologia", "economia", "editoria", "educazione", "F1", "filosofia", "fisica", "fotografia", "fumetti", "funghi", "gastronomia", "GDR", "geografia", "giochi", "golf", "guerra", "hockey", "informatica", "ingegneria", "hip hop", "jazz",
"letteratura", "LGBT", "lingue", "linguistica", "matematica", "meccanica", "medicina", "metal", "mitologia", "motociclismo", "musei", "musica", "nautica", "neopaganesimo", "numismatica", "nuoto", "paleontologia", "pallacanestro", "pallamano", "pallanuoto", "pallavolo", "pattinaggio", "pesca sportiva", "piante", "politica", "Pokémon", "psicologia", "pugilato", "punk", "radio", "religione", "rock", "rugby", "scacchi", "scienza", "scherma", "sci",
"skeleton", "sociologia", "sport", "stadi", "storia", "subacquea", "teatro", "telecomunicazioni", "televisione", "tennis", "tiro con l'arco", "trasporti", "turismo", "vela", "videogiochi", "vini","voci comuni", "wrestling", "zoologia");
 
//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;
}
 
//Prova a completare string usando dict come dizionario.
//Restituisce -1 se c'è ambiguità, 0 se non trova nessuna corrispondenza, o la stringa completa se trova una sola occorrenza
//Versione per dizionario object
function autoComplete1(dict, string){
var found = ''
var done = false;
for (var x in dict)
if (x.indexOf(string) == 0)
if (found == '')
found = x;
else {
return -1;
}
if (found != '')
return found;
return 0;
}
 
//Versione per dizionario array
function autoComplete2(dict, string){
var found = ''
var done = false;
var i;
for (i = 0; i < dict.length; i++)
if (dict[i].indexOf(string) == 0)
if (found == '')
found = dict[i];
else {
return -1;
}
if (found != '')
return found;
return 0;
}
 
 
//Prova ad auto-completare l'argomento usando arrayArgument[] come dizionario;
//In caso di fallimento restituisce arg
function autoCompleteArgument(arg){
var completed = autoComplete2(arrayArgument, arg);
if ((completed == -1) || (completed == 0))
return arg;
else
return completed;
}
 
//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{
var retval = prompt(text);
if (retval == null)
return "";
else
return retval;
}
}
 
 
//Template:A
function cmd_a(){
wpTextbox1=document.getElementById("wpTextbox1");
if (wpTextbox1 == null) return;
TimenPr('{{A|motivo='+(getArg("Motivo"))+'|argomento='+(autoCompleteArgument(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='+(autoCompleteArgument(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"))+'|'+(autoCompleteArgument(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='+(autoCompleteArgument(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='+(autoCompleteArgument(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 = autoCompleteArgument(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){
if ((command == null)||(command == ""))
return;
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 completed = autoComplete1(cmd, command)
if ((completed != 0)&&(completed != -1))
cmd[completed][0](); //tutto a posto, eseguiamo
}
}
 
function showCommandLine(){
runCommand(prompt("Comando:"));
}
 
function addCommandLine(){
var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
var na = document.createElement('a');
na.href = "javascript:showCommandLine()";
na.appendChild(document.createTextNode('Command line'));
var li = document.createElement('li');
li.id = 'tb-cmdline';
li.appendChild(na);
tb.appendChild(li);
 
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 ****/
 
/** VARIABILI GLOBALI **/
Line 1 138 ⟶ 1 510:
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
// </nowiki></pre>
 
// script "Command line"<br/>
// Vedi [[Utente:Salvatore_Ingala/commandline.js]] di [[Utente:Salvatore_Ingala]]
// <pre><nowiki>
if (toLoad.indexOf(" cmd ")!=-1)
document.write('<script type="text/javascript" src="'
+ 'http://it.wikipedia.org/w/index.php?title=Utente:Salvatore_Ingala/commandline.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
// </nowiki></pre>