Wikipedia:WikiProject User scripts/Scripts/Watchlist since

This is an old revision of this page, as edited by Ilmari Karonen (talk | contribs) at 17:50, 8 February 2006 (major rewrite, works with tabbed browsing too). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

// Adds a "Changes since last load" link to your watchlist.


addOnloadHook(function () {
    if (unescape(window.___location.href).indexOf("Special:Watchlist") < 0) return;

    // just one little ID attribute would be _so_ nice...
    var wlNotePara = document.getElementsByTagName('hr')[0];
    while (wlNotePara && !(wlNotePara.tagName && wlNotePara.tagName.toLowerCase() == 'p'))
        wlNotePara = wlNotePara.nextSibling;
    if (!wlNotePara) return;

    var link = document.createElement('a');
    link.id = 'listSince';
    link.href = '#listSince';  // must have a href to show as link!

    var then = +(new Date());
    var fixLinkHref = function () {
        var url = window.___location.href.split('#')[0];
        var days = ( +(new Date()) - then )/(1000 * 3600 * 24);
        if (url.match(/[?&]days=/))
            this.href = url.replace(/([?&]days=)[^&]*/, '$1'+days);
        else
            this.href = url + (url.indexOf('?') < 0 ? '?':'&') + 'days=' + days;
        return true;
    };
    link.onclick = fixLinkHref;
    link.onmousedown = fixLinkHref;  // react to middle clicks too

    wlNotePara.appendChild(document.createElement('br'));
    wlNotePara.appendChild(link);
    link.appendChild(document.createTextNode('Changes'));
    wlNotePara.appendChild(document.createTextNode(' since last load.'));
});

//