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 23:37, 20 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 (wgCanonicalSpecialPageName == "Watchlist")
  {
    var luasog = new Luasog("http://en.wikipedia.org/w/api.php");

    var requestParams = {action:"query", generator: "watchlistraw", prop: "revisions", rvprop: "timestamp", gwrlimit: "max"};
    oldestPage = null;

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

      if (oldestPage)
      {
        var firstHeading = document.getElementsByTagName("h4")[0];
        var message = document.createElement("p");
        message.class = "reverse-watchlist";
        message.innerHTML = oldestPage.timestamp + ' <a href="/wiki/' + escape(oldestPage.title) + '">' + oldestPage.title + '</a>';
        firstHeading.parentNode.insertBefore(message, firstHeading);
      }
    }

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