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>
 
There are two variations, depending on whether the "Enhanced recent changes" option is selected in your user preferences.
 
__TOC__
 
== No enhanced recent changes ==
 
<pre><nowiki>
// Unwatch link: No enhanced recent changes
// Add Unwatch to watch list
// from [[User:Matthewmayer/monobook.js]]
addOnloadHook(function () {
if (window.___location.href.indexOf("Special:Watchlist")!=-1) {
//correct page, so retrieve watchlist items
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;
//create 'unwatch' element
unwatchelt=document.createElement('a');
unwatchelt.setAttribute('href','/w/index.php?title='+pagename+'&action=unwatch');
unwatchelt.setAttribute('title','Unwatch '+pagename);
unwatchelt.appendChild(document.createTextNode('(unwatch)'));
//add the 'unwatch' element
items[i].appendChild(unwatchelt);
}
}
}
);
//</nowiki></pre>
 
== Enhanced recent changes ==
 
<pre><nowiki>
// Unwatch link: Enhanced recent changes
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.toLowerCase() != 'div') continue;
 
if (div.tagName.toLowerCase() == 'div') { // enchanced recent changes
var pagename = "";
// this is all tag soup, we just have to wade through it :-(
for (var node = div.firstChild; node; node = node.nextSibling) {
var pagename = "";
 
//for grab(var thenode title= ofdiv.firstChild; thenode; firstnode link= onnode.nextSibling) each line{
//what isgrab the title of thisthe first link on each page?line
if (!pagename && node.tagName && node.tagName.toLowerCase() == 'a')
if (!pagename =&& node.title;tagName && node.tagName.toLowerCase() == 'a')
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)
 
// add the if (unwatch)pagename link&& afternode.nodeType diff== and3 hist&& node.nodeValue.substring(look0, for5) distinctive== text") node. .") {
if (pagename && node.nodeType == 3 && node.nodeValue ==var ")unwatch .= document. "createElement('a') {;
unwatch.href = "/w/index.php?title=Special:Watchlist&action=submit&remove=1&id[]="+encodeURIComponent(pagename);
unwatchelt unwatch.setAttribute('title',' = "Unwatch '"+pagename);
unwatchelt unwatch.appendChild(document.createTextNode('("unwatch)'"));
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 items =document.getElementById('bodyContent') div.getElementsByTagName('li');
for (var ij = 0;i j < items.length;i j++) {
pagename var links = items[ij].getElementsByTagName('a')[0].title;
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"));
divitems[j].insertBefore(document.createTextNode("; ")unwatch, nodelinks[1].nextSibling);
divitems[j].insertBefore(unwatchdocument.createTextNode(") ("), nodeunwatch);
}
}
// XXX: might want to double check that pagename is null here, but I'll ignore it for now
}
});