Jump to content

User:Svick/reverseWatchlist.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Svick (talk | contribs) at 18:34, 21 August 2010. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
importScript('User:Luasóg bot/framework.js');

addOnloadHook(function() {
  if (wgPageName == 'Wikipedia:Reverse_Watchlist')
  {
    var hideMe = document.getElementById('hide-me');
    hideMe.parentNode.removeChild(hideMe);

    document.getElementById('bodyContent').innerHTML += '<div id="hide-me">Loading …</div>';

    var luasog = new Luasog("http://en.wikipedia.org/w/api.php");

    var requestParams = {action:"query", generator: "watchlistraw", prop: "info|revisions", rvprop: "timestamp", gwrlimit: "max"/*, gwrnamespace: "0"*/};
    pages = new Array();

    var callback = function(data) {
      for (var pageId in data.query.pages) {
        var page = data.query.pages[pageId];
        if (page.missing == undefined && page.redirect == undefined)
          pages.push({title: page.title, timestamp: new Date(page.revisions[0].timestamp)});
      }

      if (data['query-continue'] != undefined) {
        requestParams.gwrcontinue = data['query-continue'].watchlistraw.gwrcontinue;
        luasog.request(requestParams, callback);
      } else {
        var hideMe = document.getElementById('hide-me');
        hideMe.parentNode.removeChild(hideMe);
        var result = document.createElement("ol");
        result.id = "reverse-watchlist";

        pages.sort(function(a, b) { return a.timestamp - b.timestamp; });
        for (var i = 0; i < pages.length; i++) {
          var page = pages[i];
          var date = page.timestamp.toDateString();
          result.innerHTML += '<li>' + date.substring(date.indexOf(' ') + 1) + ' <a href="/wiki/' + escape(page.title) + '">' + page.title + '</a></li>';
        }
        document.getElementById('bodyContent').appendChild(result);
      }
    }

    luasog.request(requestParams, callback);
  }
});