Wikipedia:WikiProject User scripts/Scripts/Watchlist since: Difference between revisions

Content deleted Content added
major rewrite, works with tabbed browsing too
change source to syntaxhighlight
 
(9 intermediate revisions by 6 users not shown)
Line 1:
// Adds a "Changes since last load" link to your watchlist. <pre><nowikisyntaxhighlight lang="Javascript">
 
addOnloadHook(function () {
if (!mw.config.get('wgCanonicalSpecialPageName') || mw.config.get('wgCanonicalSpecialPageName') != "Watchlist") return;
if (unescape(window.___location.href).indexOf("Special:Watchlist") < 0) return;
if (!document.forms[0] || !document.forms[0].namespace) 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');
Line 17 ⟶ 12:
var fixLinkHref = function () {
var url = window.___location.href.split('#')[0];
var days = (( +(new Date()) - then ) + (60 * 1000)) / (1000 * 3600 * 24);
if (url.match(/[?&]days=/))
this.href = url.replace(/([?&]days=)[^&]*/, '$1'+days);
Line 27 ⟶ 22:
link.onmousedown = fixLinkHref; // react to middle clicks too
 
wlNotePara.appendChild(var frag = document.createElementcreateDocumentFragment('br'));
wlNoteParafrag.appendChild(linkdocument.createTextNode(' | '));
frag.appendChild(link);
link.appendChild(document.createTextNode('Changes'));
wlNoteParafrag.appendChild(document.createTextNode(' since last load.'));
 
// just one little ID attribute would be _so_ nice...
var wlNoteParansSelectForm = document.getElementsByTagName('hrform')[0];
nsSelectForm.parentNode.insertBefore(frag, nsSelectForm);
});
 
//</nowiki></presyntaxhighlight>