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:17, 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"};
    oldestPage = null;

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

      if (data['query-continue'] != undefined) {
        requestParams.gwrcontinue = data['query-continue'].watchlistraw.gwrcontinue;
        luasog.request(requestParams, callback);
      }
      else if (oldestPage)
      {
        var hideMe = document.getElementById('hide-me');
        hideMe.parentNode.removeChild(hideMe);
        var result = document.createElement("span");
        result.id = "reverse-watchlist";
        var date = new Date(oldestPage.timestamp).toDateString();
        result .innerHTML = date.substring(date.indexOf(' ') + 1) + ' <a href="/wiki/' + escape(oldestPage.title) + '">' + oldestPage.title + '</a>';
        document.getElementById('bodyContent').appendChild(result);
      }
    }

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