User:SvickTest/vector.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 handywatch() {
 cont = confirm("Add all pages listed to your watchlist?");
 if (!cont) { return; }
 superconf = confirm("Continue without any prompting?");
 var allLinks, thisLink, ready;
 counter = 0;
allLinks = document.getElementsByTagName('a');
ready = false;
for (var i = 0; i < allLinks.length; i++) {
    thisLink = allLinks[i];
    if (ready) {
      if (thisLink.href.indexOf('http://en.wikipedia.org/wiki/') != -1) {
        if (thisLink.href == 'http://en.wikipedia.org/wiki/Wikipedia:Redirects_for_discussion/Log') { alert("Finished! " + counter + " pages added."); return; }
        counter = counter + 1;
        oldref = thisLink.href;
        thisLink.href = oldref.replace(/http:\/\/en.wikipedia.org\/wiki\//, 'http://en.wikipedia.org/w/index.php?action=watch&title=');
        req = new XMLHttpRequest();
        req.open('GET', thisLink.href, false); 
        req.send(null);
        if(req.status == 200) {
          if (!superconf && !confirm("done " + oldref.replace(/http:\/\/en.wikipedia.org\/wiki\//, '') + " (number " + counter + ") Continue?")) { return; }
        } else { alert("error " + thisLink.href); }
      }
    } else {
      if (thisLink.href == 'http://en.wikipedia.org/wiki/Wikipedia:Redirects_for_discussion') { ready = true; }
    }
} //for
} //function

if (document.title.indexOf('Wikipedia:Redirects for discussion/Log') == 0)
  if (window.addEventListener) 
    window.addEventListener('load', handywatch, false);
  else if (window.attachEvent) 
    window.attachEvent('onload', handywatch);