Utente:Alex brollo/conteggiBabel.js

Da Wikisource.

Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
// estrae 500 utenti che abbiano edit a partire da aufrom
function utenti1(aufrom) {
    if (aufrom===undefined) aufrom="";
	var utenti=JSON.parse($.ajax({
    url:"/w/api.php?action=query&list=allusers&aulimit=500&format=json&auwitheditsonly=&aufrom="+aufrom,
    async: false
    }).responseText);
	var l=[];
	for (i=1;i<utenti.query.allusers.length; i+=1) {
		l.push("Utente:"+utenti.query.allusers[i].name);
	}
	if (utenti["query-continue"]!==undefined)  {
	    queryContinue=utenti["query-continue"].allusers.aufrom;
		}
	else {
		queryContinue=false;
		}
	return [l, queryContinue];
	}

// riceve una lista max 50 pagine utente e restituisce il contenuto di tag #Babel
function utenti2(lista) {
    var testi=JSON.parse($.ajax({
    url:"/w/api.php?action=query&prop=revisions&titles="+lista.join("|")+"&rvprop=content&format=json",
    async: false
    }).responseText);
	var listaId=Object.keys(testi.query.pages);
	var babel=[];
	console.log(listaId);
	for (i=0;i<listaId.length;i+=1) {
		if(listaId[i]*1>0) {
			testo=testi.query.pages[listaId[i]].revisions["0"]["*"];
			var x=find_stringa(testo,"{{#Babel:","}}",1);
			if (x!=="") babel.push(x);
		}
	}
	return babel;
}

// ricava la lista degli utenti con edit di wikisource chiamando ripetutamente utenti1()
function utentiConEdit() {
    var l=[];
	var x=["","*"];
	do {
		x=utenti1(x[1]);
		l=l.concat(x[0]);
	} while (x[1]);
	return l;
}