Wikipedia:WikiProject User scripts/Scripts/Unwatch: Difference between revisions
Content deleted Content added
provide two variations |
This version works regardless of whether you have the "Enhanced recent changes" option selected in your user preferences. |
||
Line 1:
// This script adds an "unwatch" link to each entry in your watchlist. This version works regardless of whether you have the "Enhanced recent changes" option selected in your [[Special:Preferences|user preferences]]. <pre><nowiki>
var items=document.getElementById('bodyContent').getElementsByTagName('li');▼
for (var i=0;i<items.length;i++) {▼
//what is the title of this page?▼
pagename=items[i].getElementsByTagName('a')[0].title;▼
unwatchelt.setAttribute('title','Unwatch '+pagename);▼
unwatchelt.appendChild(document.createTextNode('(unwatch)'));▼
}▼
addOnloadHook(function () {
if (window.___location.href.indexOf("Special:Watchlist") == -1) return;
// look for h4 followed by div/ul▼
// this is all tag soup, we just have to wade through it :-(▼
▲ // look for h4 followed by div
var headings = document.getElementById('content').getElementsByTagName('h4');
Line 45 ⟶ 10:
var div = headings[i].nextSibling;
while (div && div.nodeType == 3) div = div.nextSibling; // skip text nodes
if (!div || !div.tagName
if (div.tagName.toLowerCase() == 'div') { // enchanced recent changes
var pagename = "";▼
▲ // this is all tag soup, we just have to wade through it :-(
▲ var pagename = "";
if (!pagename
pagename = node.title;
if (pagename && node.tagName && node.tagName.toLowerCase() == 'br') pagename = "";
// add the (unwatch) link after diff and hist (look for distinctive text node)
unwatch.href = "/w/index.php?title=Special:Watchlist&action=submit&remove=1&id[]="+encodeURIComponent(pagename);
div.insertBefore(document.createTextNode("; "), node);
div.insertBefore(unwatch, node);
}
}
// XXX: might want to double check that pagename is null here, but I'll ignore it for now▼
▲ }
else if (div.tagName.toLowerCase() == 'ul') { // unenchanced recent changes
var pagename = links[0].title;
var unwatch = document.createElement('a');
unwatch.href = "/w/index.php?title=Special:Watchlist&action=submit&remove=1&id[]="+encodeURIComponent(pagename);
unwatch.title = "Unwatch "+pagename;
unwatch.appendChild(document.createTextNode("unwatch"));
}
}
▲ // XXX: might want to double check that pagename is null here, but I'll ignore it for now
}
});
|