// <pre>

function addPatrolLinks() {
  if ( wgCanonicalSpecialPageName == "Recentchanges" || wgCanonicalSpecialPageName == "Watchlist") {
    var elinks = document.getElementsByTagName("a");
    for (var i = 0; i < elinks.length; i++) {
      var myRcidSearchPos = elinks.href.indexOf('rcid=');
      if (myRcidSearchPos != -1) {
    	  // Find the rcid
    	  var myRcid = elinks.href.substr(myRcidSearchPos+5);
    	  // Find the Title
    	  var myRcTitleStart = elinks.href.indexOf('title=');
    	  var myRcTitleEnd = elinks.href.indexOf('&', myRcTitleStart);
    	  var myRcTitle = elinks.href.substring(myRcTitleStart+6, myRcTitleEnd);
    	  // Now make the new link
    	  var myPatrolLink = document.createElement("a");
        myPatrolLink.className = 'patrollink';
        myPatrolLink.setAttribute('href', '/w/index.php?title='+myRcTitle+'&action=markpatrolled&rcid='+myRcid);
        var myPatrolText = document.createTextNode('(!)');
        myPatrolLink.appendChild(myPatrolText);
        // And add it before the old link
        elinks.parentNode.insertBefore(myPatrolLink, elinks);
        i++; //We added a new link, so to avoid recursion..
        // Just a safetyfeature to avoid looping forever in case of failure
        if (i>=2000) break;
      }
    }
  }
}
$(addPatrolLinks);

var wgStatNotMe = true; /* count me out */

// </pre>