User:Casper2k3/Javascript/watchlistsince.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Casper2k3/Javascript/watchlistsince. |
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);
});