Jump to content

User:Parent5446/MediaWiki/AdahLinks.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function openAdahLinks(kk)
{
  var as = document.getElementsByTagName('a');
  var k = 0;
  for (n=0; n<as.length; n++) {
    if (as[n].innerHTML == 'diff') {
      if (k <= kk) {
        window.open(as[n].href, '_blank');
      }
      k++;
    }
  }
}

function addAdahLinks() 
{
  if (wgCanonicalNamespace == 'Special' && wgCanonicalSpecialPageName == 'Watchlist') {
    var as = document.getElementsByTagName('a');
    var k = 0;
    for (n=0; n<as.length; n++) {
      if (as[n].innerHTML == 'diff') {
        var tn = document.createTextNode(') (');
        var link = document.createElement('a');
        link.href = 'javascript:openAdahLinks(' + (k++) + ')';
        link.appendChild(document.createTextNode('adah'), null);
        as[n].parentNode.insertBefore(tn , as[n].nextSibling.nextSibling);
        as[n].parentNode.insertBefore(link , as[n].nextSibling.nextSibling);
      }
    }
  }
}

addOnloadHook(addAdahLinks);