MediaWiki:Gadget-Unwatch.js

Wikibooks, manuali e libri di testo liberi.

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

  • Firefox / Safari: tenere premuto il tasto delle maiuscole Shift e fare clic su Ricarica, oppure premere Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premere Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer: tenere premuto il tasto Ctrl e fare clic su Aggiorna, oppure premere Ctrl-F5
  • Opera: Vai nel Menu → Impostazioni (Opera → Preferenze su un Mac) e poi in Privacy & sicurezza → Pulisci dati del browser → Immagini e file nella cache.
if (mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist' && mw.config.get('wgAction') == 'view')
(function($){
 
var unWatchLinks = [];
var watchMsg = window.wgAjaxWatch ? wgAjaxWatch.watchMsg : 'Segui';
var unwatchMsg = window.wgAjaxWatch ? wgAjaxWatch.unwatchMsg : 'Non seguire';
var wlForm;
var inProgress = null;
var timeoutID = null;
 
$(document).ready(function() {
    if (!(wlForm = document.forms[0]) || !wlForm.namespace) return;
    var links = document.getElementById('content').getElementsByTagName('a');
    for (var i = 0; i   links.length; i++){ //append (x) links after history links
        if (!links[i].href.match(/[?&]action=history([&#]|$)/)) continue;
        var unwatch = document.createElement('a');
    unwatch.href = 'javascript:;';
        unwatch.title = wgServer+wgScript+'?action=unwatch&title='+encodeURIComponent(links[i].title);
        unwatch.onclick = onClick;
        unWatchLinks.push(unwatch);
        var nextEl = links[i].nextSibling.nextSibling; //item after )
        nextEl.parentNode.insertBefore(document.createTextNode(' ('), nextEl);
        nextEl.parentNode.insertBefore(unwatch, nextEl);
        nextEl.parentNode.insertBefore(document.createTextNode(') '), nextEl);
        setUnwatchLink(unwatch, false);
    }
});
 
 
function setUnwatchLink (unwatchLink, state) {
    unwatchLink.innerHTML = state ? 'segui' : 'non seguire';
}
 
function getPgName (unwatchLink){
    return decodeURIComponent(unwatchLink.title.match(/&title=(.+)/)[1]);
}
 
function onClick(e) {
    if (inProgress) return false;
    if (!e) var e = window.event;
    if (e.target) var targ = e.target; else if (e.srcElement) var targ = e.srcElement;
    inProgress = getPgName(targ);
    //call server
    var action = (targ.innerHTML == 'non seguire') ? 'u' : 'w';
 
  var response;
 
    var name = inProgress, name2 = name, state, prefix, idx, ns = 0, pg, i, el; 
 
  if (targ.innerHTML == 'non seguire')
  {
    response = $.ajax({
      url: "//it.wikibooks.org/w/api.php",
      data: ({title : inProgress, action : 'watch', unwatch : 'unwatch', format : 'xml'}),
      dataType: "xml",
      async:false,
      error: function(msg){
       return;
      }
    }).responseText;
 
    state = true;
  }
  else
  {
    response = $.ajax({
      url: "//it.wikibooks.org/w/api.php",
      data: ({title : inProgress, action : 'watch', format : 'xml'}),
      dataType: "xml",
      async:false,
      error: function(msg){
       return;
      }
    }).responseText;
 
    state = false;
  }
 
    inProgress = null;
 
    //find the name of "other page"
    if ((idx = name.indexOf(':')) != -1){ //not main namespace
        prefix = name.substring(0,idx);
        name2 = name.substring(idx + 1)
        for (i=2; i   wlForm.namespace.options.length; i++)
            if (wlForm.namespace.options[i].text == prefix)
                ns = i - 1;
        if (ns == 0) name2 = name; // guess : was a  part of the page name
    }
 
    if (ns % 2)    ns--; else ns++; //switch to  "other" namespace
    if (ns   0) name2 = wlForm.namespace.options[ns+1].text + ':' +  name2;
 
    //now mark all pages that are either name or name2
    for (i=0; i unWatchLinks.length; i++)
        if ((pg = getPgName(unWatchLinks[i])) && (pg==name || pg==name2)) {
            setUnwatchLink (unWatchLinks[i], state);
            el = unWatchLinks[i]; //now mark the whole line
            while ((el=el.previousSibling) && (el.nodeName!='DIV') && (el.nodeName!='BR')) 
                if (el.style) el.style.textDecoration = state ? 'line-through' : '';
        }
}
 
})(jQuery);