Wikipedia:WikiProject User scripts/Scripts/Unwatch

This is an old revision of this page, as edited by Ilmari Karonen (talk | contribs) at 02:10, 5 January 2006 (doesn't work :-( — replace with version that does). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

// This script adds an "unwatch" link to each entry in your watchlist.


addOnloadHook(function () {
    if (window.___location.href.indexOf("Special:Watchlist") == -1) return;

    // 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');

    for (var i = 0; i < headings.length; i++) {
        var div = headings[i].nextSibling;
        while (div && div.nodeType == 3) div = div.nextSibling;  // skip text nodes
        if (!div || div.tagName.toLowerCase() != 'div') continue;

        var pagename = "";
        for (var node = div.firstChild; node; node = node.nextSibling) {

            // grab the title of the first link on each line
            if (!pagename && node.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)
            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);
                unwatch.title = "Unwatch "+pagename;
                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
    }
});

//