Jump to content

User:JackSchmidt/JS Watchlist.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.
// Add to watchlist Queue

// (c) 2007 Jack Schmidt, available under GPL, BSD, or CC-SA

// Code to add huge swath of pages to watchlist using ajax
// If possible, you should do this using your edit raw watchlist
// instead.
JS_Watchlist = { list: [], position: 0, running: false };
JS_Watchlist.Add = function ( pagename ) {
  for( var i=0; i < JS_Watchlist.list.length ; i++ ) {
    if( JS_Watchlist.list[i] == pagename ) return true;
  }
  JS_Watchlist.list[JS_Watchlist.list.length] = pagename;
  if( ! JS_Watchlist.running ) JS_Watchlist.Run();
}
JS_Watchlist.Run = function() {
  if( JS_Watchlist.running ) return;
  JS_Watchlist.running = true;
  JS_Watchlist.Callback(null,null);
}
JS_Watchlist.Callback_ = function(id,txt) {
  return JS_Watchlist.Callback(id,txt);
}
JS_Watchlist.Callback = function(id,txt) {
  if( JS_Watchlist.list.length <= JS_Watchlist.position ) {
    JS_Watchlist.running = false;
    return;
  }
  var pagename = JS_Watchlist.list[ JS_Watchlist.position ];
  JS_Watchlist.position ++;
  JS_INDEX( [["action", "ajax"], ["rs", "wfAjaxWatch"],
    ["rsargs[]", pagename], ["rsargs[]","w"]], pagename,
    JS_Watchlist.Callback_ );
}