MediaWiki:FasiAvanzamento.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.
/* <pre> */
// Stato avanzamento
function cercaAvz()
{
   cercatoreAvanzamento = new avanzoCatcher();
   cercatoreAvanzamento.onAvanzoCatched = inserisciAvz;
   var avanzamenti = getElementsByClass('avanzamento', 'span', document); // Prende tutti gli elementi che hanno come classe "avanzamento"
   var i;
   for(i in avanzamenti)
   {
       if(avanzamenti[i].firstChild.className == 'avz_placeholder')
       {
           //prendo il titolo della pagina sostituendo gli spazi con degli underscore
           var page = avanzamenti[i].firstChild.innerHTML.replace(/\s/g,'_');
           avanzamenti[i].firstChild.className='avz_' + page;
           avanzamenti[i].firstChild.innerHTML='';
           cercatoreAvanzamento.aggiungiPagina(page);
       }
   }
   cercatoreAvanzamento.avanzaCoda();
}

function inserisciAvz(page, avanzamento, data)
{
   var elms = getElementsByClass('avz_' + page, 'span', document); // Becca gli elementi corrispondenti a quel libro
   var elm;
   var i;
   for(i=0; i<elms.length; i++)
   {
       elm = elms[i];
       var statusImg = document.createElement('img');
       var image = "";
       var imagePath = "";
       if(avanzamento == "0" || avanzamento == "00" ) { // Switcha tra le fasi di avanzamento
            imagePath = '//upload.wikimedia.org/wikipedia/commons/thumb/d/d6/00%25.svg/9px-00%25.svg';
            text = '<p><b><a href="/wiki/Aiuto:Livello_SAL_da_segnalare" title="Aiuto:Livello SAL da segnalare">Livello SAL da segnalare</a></b> <span style="position:relative; overflow:hidden; width:9px; height:9px; z-index:2"><a href="/wiki/Immagine:00%25.svg" class="image" title="00%.svg"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/d6/00%25.svg/9px-00%25.svg" width="9" height="9" border="0" /></a>&nbsp;<small>(' + data + ')</small> <span style="position:absolute; top:0; left:0; padding-top:3px; z-index:3; text-decoration:none"><a href="/wiki/Aiuto:Livello_SAL_da_segnalare" title="Aiuto:Livello SAL da segnalare"><span style="float:left; width:9px; height:9px; font-size:9px; line-height:9px; word-spacing:9px; cursor:pointer; text-decoration:none">&#160; &#160;</span></a></span></span></p><ul><li>Questo testo deve ancora entrare nel percorso di qualità di Wikisource</li></ul>'; }
       if(avanzamento == "25") {
            imagePath = '//upload.wikimedia.org/wikipedia/commons/thumb/3/34/25%25.svg/9px-25%25.svg';
            text = '<p><b><a href="/wiki/Aiuto:SAL_25%25" title="Aiuto:SAL 25%">SAL 25%</a></b> <span style="position:relative; overflow:hidden; width:9px; height:9px; z-index:2"><a href="/wiki/Immagine:25%25.svg" class="image" title="25%.svg"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/3/34/25%25.svg/9px-25%25.svg" width="9" height="9" border="0" /></a>&nbsp;<small>(' + data + ')</small> <span style="position:absolute; top:0; left:0; padding-top:3px; z-index:3; text-decoration:none"><a href="/wiki/Aiuto:SAL_25%25" title="Aiuto:SAL 25%"><span style="float:left; width:9px; height:9px; font-size:9px; line-height:9px; word-spacing:9px; cursor:pointer; text-decoration:none">&#160; &#160;</span></a></span></span></p><ul><li><b><a href="/wiki/Aiuto:Fonte" title="Aiuto:Fonte">Fonte</a></b>: fonte non indicata</li><li><b><a href="/wiki/Aiuto:Completezza_dei_testi" title="Aiuto:Completezza dei testi">Completezza</a></b>: testo incompleto</li><li><b><a href="/wiki/Aiuto:Formattazione" title="Aiuto:Formattazione">Formattazione</a></b>: testo non formattato</li></ul>'; }
       if(avanzamento == "50") {
            imagePath = '//upload.wikimedia.org/wikipedia/commons/thumb/c/c2/50%25.svg/9px-50%25.svg';
            text = '<p><b><a href="/wiki/Aiuto:SAL_50%25" title="Aiuto:SAL 50%">SAL 50%</a></b> <span style="position:relative; overflow:hidden; width:9px; height:9px; z-index:2"><a href="/wiki/Immagine:50%25.svg" class="image" title="50%.svg"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/c/c2/50%25.svg/9px-50%25.svg" width="9" height="9" border="0" /></a>&nbsp;<small>(' + data + ')</small> <span style="position:absolute; top:0; left:0; padding-top:3px; z-index:3; text-decoration:none"><a href="/wiki/Aiuto:SAL_50%25" title="Aiuto:SAL 50%"><span style="float:left; width:9px; height:9px; font-size:9px; line-height:9px; word-spacing:9px; cursor:pointer; text-decoration:none">&#160; &#160;</span></a></span></span></p><ul><li><b><a href="/wiki/Aiuto:Fonte" title="Aiuto:Fonte">Fonte</a></b>: fonte indicata, ma tanto attendibile quanto inattendibile</li><li><b><a href="/wiki/Aiuto:Completezza_dei_testi" title="Aiuto:Completezza dei testi">Completezza</a></b>: testo completo</li><li><b><a href="/wiki/Aiuto:Formattazione" title="Aiuto:Formattazione">Formattazione</a></b>: testo non formattato</li></ul>'; }
       if(avanzamento == "75") {
           imagePath = '//upload.wikimedia.org/wikipedia/commons/thumb/4/49/75%25.svg/9px-75%25.svg';
           text = '<p><b><a href="/wiki/Aiuto:SAL_75%25" title="Aiuto:SAL 75%">SAL 75%</a></b> <span style="position:relative; overflow:hidden; width:9px; height:9px; z-index:2"><a href="/wiki/Immagine:75%25.svg" class="image" title="75%.svg"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/4/49/75%25.svg/9px-75%25.svg.png" width="9" height="9" border="0" /></a>&nbsp;<small>(' + data + ')</small> <span style="position:absolute; top:0; left:0; padding-top:3px; z-index:3; text-decoration:none"><a href="/wiki/Aiuto:SAL_75%25" title="Aiuto:SAL 75%"><span style="float:left; width:9px; height:9px; font-size:9px; line-height:9px; word-spacing:9px; cursor:pointer; text-decoration:none">&#160; &#160;</span></a></span></span></p><ul><li><b><a href="/wiki/Aiuto:Fonte" title="Aiuto:Fonte">Fonte</a></b>: fonte indicata e attendibile</li><li><b><a href="/wiki/Aiuto:Completezza_dei_testi" title="Aiuto:Completezza dei testi">Completezza</a></b>: testo completo</li><li><b><a href="/wiki/Aiuto:Formattazione" title="Aiuto:Formattazione">Formattazione</a></b>: testo formattato correttamente</li><li><b><a href="/wiki/Aiuto:Riletture" title="Aiuto:Riletture">Riletture</a></b>: testo da rileggere</li></ul>'; }
       if(avanzamento == "100") {
           imagePath = '//upload.wikimedia.org/wikipedia/commons/thumb/c/ce/100%25.svg/9px-100%25.svg.png';
           text = '<p><b><a href="/wiki/Aiuto:SAL_100%25" title="Aiuto:SAL 100%">SAL 100%</a></b> <span style="position:relative; overflow:hidden; width:9px; height:9px; z-index:2"><a href="/wiki/Immagine:100%25.svg" class="image" title="100%.svg"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/c/ce/100%25.svg/9px-100%25.svg" width="9" height="9" border="0" /></a>&nbsp;<small>(' + data + ')</small> <span style="position:absolute; top:0; left:0; padding-top:3px; z-index:3; text-decoration:none"><a href="/wiki/Aiuto:SAL_100%25" title="Aiuto:SAL 100%"><span style="float:left; width:9px; height:9px; font-size:9px; line-height:9px; word-spacing:9px; cursor:pointer; text-decoration:none">&#160; &#160;</span></a></span></span></p><ul><li><b><a href="/wiki/Aiuto:Fonte" title="Aiuto:Fonte">Fonte</a></b>: fonte indicata e attendibile</li><li><b><a href="/wiki/Aiuto:Completezza_dei_testi" title="Aiuto:Completezza dei testi">Completezza</a></b>: testo completo</li><li><b><a href="/wiki/Aiuto:Formattazione" title="Aiuto:Formattazione">Formattazione</a></b>: testo formattato correttamente</li><li><b><a href="/wiki/Aiuto:Riletture" title="Aiuto:Riletture">Riletture</a></b>: testo riletto usando la fonte citata</li><li><b><a href="/wiki/Aiuto:Blocco_della_pagina" title="Aiuto:Blocco della pagina">Blocco</a></b>: testo bloccato</li></ul>'; }
       if(avanzamento == "101") {
           imagePath = '//upload.wikimedia.org/wikisource/it/7/73/101%25.png';
           text = '<p><b><a href="/wiki/Aiuto:Edizioni_Wikisource" title="Aiuto:Edizioni Wikisource">Edizioni Wikisource</a></b> <span style="position:relative; overflow:hidden; width:9px; height:9px; z-index:2"><a href="/wiki/Immagine:101%25.svg" class="image" title="101%.svg"><img alt="" src="//upload.wikimedia.org/wikisource/it/thumb/9/90/101%25.png/9px-101%25.svg.png" width="9" height="9" border="0" /></a>&nbsp;<small>(' + data + ')</small> <span style="position:absolute; top:0; left:0; padding-top:3px; z-index:3; text-decoration:none"><a href="/wiki/Aiuto:Edizioni_Wikisource" title="Aiuto:Edizioni Wikisource"><span style="float:left; width:9px; height:9px; font-size:9px; line-height:9px; word-spacing:9px; cursor:pointer; text-decoration:none">&#160; &#160;</span></a></span></span></p><ul><li><b><a href="/wiki/Aiuto:Fonte" title="Aiuto:Fonte">Fonte</a></b>: fonte indicata e attendibile</li><li><b><a href="/wiki/Aiuto:Completezza_dei_testi" title="Aiuto:Completezza dei testi">Completezza</a></b>: testo completo</li><li><b><a href="/wiki/Aiuto:Formattazione" title="Aiuto:Formattazione">Formattazione</a></b>: testo formattato correttamente</li><li><b><a href="/wiki/Aiuto:Riletture" title="Aiuto:Riletture">Riletture</a></b>: testo riletto usando la versione cartacea</li><li><b><a href="/wiki/Aiuto:Blocco_della_pagina" title="Aiuto:Blocco della pagina">Blocco</a></b>: testo bloccato</li></ul>'; }
       statusImg.setAttribute('src', imagePath);
       statusImg.setAttribute('alt', 'Avanzamento: ' + avanzamento + '%');
       if(elm.nextSibling) {
           if(data != null && data != '' && elm.nextSibling.className == 'dataAvanzamento') {
               dataText = document.createTextNode('(' + data + ')');
               elm.nextSibling.appendChild(dataText)
               elm.appendChild(statusImg);
           }
           if(elm.nextSibling.className == 'testoAvanzamento') {
               elm.innerHTML = text;
           }
       } else {
           elm.appendChild(statusImg);
       }
   }
}

function avanzoCatcherStatoCambiato()
{
   cercatoreAvanzamento.processa();
}

function avanzoCatcher()
{
   this.coda = new Array();
   this.xhttpreq = null;
   this.currentPage = null;
   this.createRequest = createRequest;
   this.aggiungiPagina = addPage;
   this.avanzaCoda = initRequest;
   this.processa = processRequest;
   this.onAvanzoCatched = null;

   function createRequest()
   {
       try {
           this.xhttpreq = new XMLHttpRequest();
       } catch(exc) {
           try {
               this.xhttpreq = new ActiveXObject('Msxml2.XMLHTTP');
           } catch(exc) {
               try {
                   this.xhttpreq = new ActiveXObject('Microsoft.XMLHTTP');
               } catch(exc) {
                   this.xhttpreq = null;
               }
           }
       }
   }

   function addPage(inputPage)
   {
       if(arrayContains(inputPage, this.coda)) return; // Se l'ho già messa, la salto!
       this.coda.push(inputPage);
   }

   function initRequest()
   {
       if(this.coda.length == 0) return;
       this.createRequest();
       this.xhttpreq.open('GET', '/w/index.php?title=' + this.coda[0] + '&action=raw&ctype=text/x-wiki', true);
       this.xhttpreq.onreadystatechange = avanzoCatcherStatoCambiato;
       this.xhttpreq.send('');
       this.currentPage = this.coda[0];
       this.coda.shift();
   }

   function processRequest()
   {
       if(this.xhttpreq.readyState == 4) {
           var txtresp = this.xhttpreq.responseText;
		   
           //cerca il Template:Qualità...
           var avanzoregexp = /\{\{[Qq]ualità\|avz=(\d{1,3})%(\|data=(.*?))?(\|arg=.*?)?\}\}/;
           var match = avanzoregexp.exec(txtresp);
           if(match)
           {
               var avanzamento = match[1];
               var data = null;
               if(match.length == 5)
               {
                   data = match[3];
               }
               this.onAvanzoCatched(this.currentPage, avanzamento, data);
           } else {
               //...se non lo trova cerca il parametro |Qualità=
               avanzoregexp = /\|Qualità=(\d{1,3})%/;
               match = avanzoregexp.exec(txtresp);
               if(match)
               {
                   var avanzamento = match[1];
                   this.onAvanzoCatched(this.currentPage, avanzamento, null);
               }
               //se non c'è nessuno dei due mette qualità 0
               else {
                   this.onAvanzoCatched(this.currentPage, "0", null);
               }
           }
           this.avanzaCoda();
       }
   }
}

addLoadEvent(cercaAvz);

/* </pre> */