User:Casper2k3/Javascript/watchlistsince.js

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

// just one little ID attribute would be _so_ nice... var nsSelectForm = document.getElementById('namespace'); while (nsSelectForm && !(nsSelectForm.tagName && nsSelectForm.tagName.toLowerCase == 'form')) nsSelectForm = nsSelectForm.parentNode; if (!nsSelectForm) 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

var frag = document.createDocumentFragment; frag.appendChild(document.createTextNode(' | ')); frag.appendChild(link); link.appendChild(document.createTextNode('Changes')); frag.appendChild(document.createTextNode(' since last load.')); nsSelectForm.parentNode.insertBefore(frag, nsSelectForm); });