MediaWiki:Gadget-CatWatch.js

Wikibooks, manuali e libri di testo liberi.

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.
/*<noinclude>
Il "Controllo categorie" (grazie a [[:en:User:ais523]] che per primo ha avuto l'idea) aggiunge elementi alla watchlist se una pagina viene aggiunta ad una categoria (ed e' ancora presente al momento del controllo). Questo evento apparira' solo se un'altra pagina della watchlist e' stata modificata quel giorno (se l'aggiunta e' l'unica cosa successa non apparira').<br/>
La ricategorizzazione di una pagina  appartenente ad una categoria osservata verra' segnalata anche se la modifica riguardava  un'altra categoria (a meno che  quella osservata venga cancellata).<br/>
I cancellamenti dalla categoria controllata non verranno visualizzati.<br/>
L'ora delle modifiche si riferisce a quella dei server, potrebbe essere differente da quella locale.<br/>

Per ogni pagina aggiunta verranno mostrati i seguenti link:
* Alla relativa categoria
* Alla pagina aggiunta
* All'ultima modifica della pagina
* Alla cronologia della pagina
*/

//<source lang="javascript">

// End of [[WP:US]] quote

function cwOntoWatchlist(responseText, catName)
{
  var a=responseText;
  var c=catName;
  var i;
  var diag="";
  if(a.indexOf("<categorymembers/>")!=-1) return; //cat is empty, nothing to do here
  if(a.indexOf('title="')==-1) return; // this error happens sometimes, just do nothing here
  var temp, temp2;
  
  var pages=a.split('title="');
  var times=a.split('timestamp="');
  
  a=document.getElementsByTagName("h4"); //get dates in the watchlist
  var monthname=new Array();
  monthname['01']="gen";
  monthname['02']="feb";
  monthname['03']="mar";
  monthname['04']="apr";
  monthname['05']="mag";
  monthname['06']="giu";
  monthname['07']="lug";
  monthname['08']="ago";
  monthname['09']="set";
  monthname['10']="ott";
  monthname['11']="nov";
  monthname['12']="dic";

  // skip first element, it's unnecessary
  for (cicla=1; cicla<pages.length; cicla++)
  {
     pages[cicla] = pages[cicla].split('" timestamp=')[0];
     times[cicla] = times[cicla].split('" />')[0];
  
     // 2008-08-25
     times[cicla]=new String(times[cicla]);

     var mn1;

     // 25 ago 2008
     mn1=""+new Number(times[cicla].substr(8,2))+" "+monthname[times[cicla].substr(5,2)]+" "+times[cicla].substr(0,4);

     i=a.length;
     while(i--)
     {
       if(a[i].innerHTML==mn1)
       {
         diag+=a[i].innerHTML+":";
         temp=a[i].nextSibling.firstChild;
         if(temp==null) temp=a[i].nextSibling.nextSibling.firstChild;
         while(temp!=null)
         {
           diag+=temp.tagname+"!";
           if(temp.tagName!=null)
             if(temp.tagName.toLowerCase()=="li")
             {
               temp2=temp.innerHTML.match(/; ([0-9][0-9]):([0-9][0-9])(:[0-9][0-9])? \. \./);
               temp2=new Number(temp2[1])*100+new Number(temp2[2]);
               diag+=temp2+",";
               if(temp2<new Number(times[cicla].substr(11,2)+times[cicla].substr(14,2))) {temp2=temp; break;}
             }
           temp2=temp; temp=temp.nextSibling;
           if(temp==null) break;
         }
         temp=document.createElement("li");
         if(temp2==null) {return;}
         if(a[i].nextSibling.firstChild!=null) // IE-like whitespace handling
           a[i].nextSibling.insertBefore(temp,temp2);
         else // Firefox-like whitespace handling
           a[i].nextSibling.nextSibling.insertBefore(temp,temp2);

         temp.innerHTML='<span style="font-weight:bold;">'+"(diff) (<a href='//it.wikibooks.org/w/index.php?title="+encodeURI(pages[cicla])+
                        "&action=history'>cron</a>) . . <a "+
                        "href='//it.wikibooks.org/wiki/Categoria:"+
                        encodeURI(c)+
                        "'>Categoria:"+c+"</a>; "+times[cicla].substr(11,2)+":"+times[cicla].substr(14,2)+
                        " . . (+ <a "+
                        "href='//it.wikibooks.org/wiki/"+
                        encodeURI(pages[cicla])+"'>"+pages[cicla]+"</a> "+
                        "(<a href='//it.wikibooks.org/w/index.php?title="+encodeURI(pages[cicla])+
                        "&diff=last'>last</a>))</span>";
       }
     }
  }
}

var CategorieOsservate;

//An example of a query to check a category would be

////en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmcategory=Wikipedia%20protected%20edit%20requests&cmlimit=1&cmprop=title|timestamp&cmsort=timestamp&cmdir=desc&format=xml
if(mw.config.get('wgPageName')=="Speciale:OsservatiSpeciali")
jQuery(document).ready(function($){
  //DHTMLloadscript( '//en.wikipedia.org/w/index.php?title=User:'+wgUserName
  //  +'/WatchedCategories.js&action=raw&ctype=text/javascript');
  $.ajax({
    url: "//it.wikibooks.org/w/index.php",
    data: ({title: "Utente:"+mw.config.get('wgUserName')+"/CategorieOsservate.js", action : 'raw', ctype : 'text/javascript'}),
    success: function(data){
      eval(data);
      if(typeof CategorieOsservate == 'undefined')
      {
        if(confirm("Ancora non hai una lista di categorie da controllare. Vuoi crearne una?"))
          location.href='//it.wikibooks.org/w/index.php?title=Utente:'+mw.config.get('wgUserName')+
          '/CategorieOsservate.js&action=edit&preload=MediaWiki:Gadget-CatWatch.js/Template';
      }
      else
      {
        $.each(CategorieOsservate, function(i, cat){
          $.ajax({
            url: "//it.wikibooks.org/w/api.php",
            data: ({action : "query", list : 'categorymembers', cmtitle : 'Category:'+cat, cmlimit : '100', cmprop : "title|timestamp", cmsort : "timestamp", cmdir : "desc", format : "xml"}),
            dataType: "text",
            success: function(data){
               cwOntoWatchlist(data, cat);
            }
          });
        });
      }
    }
  });
});