Wikipedia:WikiProject User scripts/Scripts/Unwatch

This is an old revision of this page, as edited by Omegatron (talk | contribs) at 16:06, 16 January 2007. 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. This version works regardless of whether you have the "Enhanced recent changes" option selected in your user preferences. By default the links take you back to your watchlist. If you'd prefer them to take you to a "Removed from watchlist" page like the unwatch links at the top of the watched pages, uncomment the second line in the function.

Other versions:

 */

addOnloadHook(function () {
    var query_prefix = "title=Special:Watchlist&action=submit&remove=1&id[]=";
    //var query_prefix = "action=unwatch&title=";

    if (window.___location.href.indexOf("Special:Watchlist") < 0) return;
    if (window.___location.href.indexOf("Special:Watchlist/edit") >= 0) return;

    var links = document.getElementById('content').getElementsByTagName('a');
    for (var i = 0; i < links.length; i++) {
        if (links[i].href.substring(links[i].href.length-15) != '&action=history')
            continue;
        var unwatch = document.createElement('a');
        unwatch.href = "/w/index.php?" + query_prefix + encodeURIComponent(links[i].title);
        unwatch.title = "Unwatch "+links[i].title;
        unwatch.appendChild(document.createTextNode("unwatch"));
        links[i].parentNode.insertBefore(unwatch, links[i].nextSibling);
        // kluge to handle case where "diff" is unlinked:
        var delim = links[i].previousSibling;
        delim = (delim.nodeType == 3 ? delim.nodeValue : "");
        links[i].parentNode.insertBefore(document.createTextNode(delim.replace(/^.*diff/, "")), unwatch);
    }
});

//