Saltar para o conteúdo

Usuário:ChristianH/desvigiar.js

Origem: Wikipédia, a enciclopédia livre.

Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5.
//Adds "unwatch" links to watchlist and recentchanges.
//Seems good for FF; not tested elsewhere.
//Todo: Add links for watchlist's log-entry lines also. (Difficulty is finding the right pagename.)
function unwatchlinks() {
 aitchone = document.getElementById('firstHeading').firstChild.nodeValue;
 switch(aitchone){
  case 'My watchlist':
   lists=document.getElementsByTagName('ul');
   for (i=0;i<lists.length;i++) {
    if (lists[i].hasAttribute('class')) {
     if (lists[i].getAttribute('class')=='special') {//It's a day's watchlist.
      items=lists[i].childNodes;//li elements and whitespace
      for (j=items.length-1;j>-1;j--) {
       if (items[j].nodeType>1) continue;//li elements, not whitespace
       difflink=items[j].firstChild;
       while (difflink.nodeType>1) difflink=difflink.nextSibling;//first element sub the li
       diffurl=difflink.getAttribute('href');// /w/index.php?title=TITLE&amp;OTHERPARAMS if not a log entry
       if (diffurl.indexOf('/wiki/')) {//not a log entry
        title=diffurl.split('=')[1];
        title=title.split('&')[0];//pagename of the watchlist item
        newurl='/wiki/'+title+'?action=unwatch';
        anch=document.createElement('a');
        anch.setAttribute('href',newurl);
        anch.appendChild(document.createTextNode('unwatch'));
        items[j].insertBefore(anch,difflink);
        spacer=document.createTextNode(') (');
        items[j].insertBefore(spacer,difflink);
       }//end if indexOf
      }//end for j
     }//end if special
    }//end if hasAttr
   };//end for i
  break;//case 'My watchlist'
  case 'Recent changes':
   strongs=document.getElementsByTagName('strong');
   for (i=0;i<strongs.length;i++) {
    strong=strongs[i];
    if (strong.getAttribute('class')=='mw-watched') {//page is on watchlist
     children=strong.childNodes;//a element and whitespace
     for (j=0;j<children.length;j++) {
      if (children[j].nodeType>1) continue;//elements only, so a element
      pageurl=children[j].getAttribute('href');// /wiki/TITLE
      unwatchurl=pageurl+'?action=unwatch';
      anch=document.createElement('a');
      anch.setAttribute('href',unwatchurl);
      anch.appendChild(document.createTextNode('(unwatch)'));
      strong.parentNode.insertBefore(anch,strong);
      spacer=document.createTextNode(' ');
      strong.parentNode.insertBefore(spacer,strong);
      break;//for j, don't look at subsequent whitespace
     }//end for j
    }//end if mw-watched
   }//end for i
  break;//case 'Recent changes'
 }//end switch
};//end function
$(unwatchlinks);