Wikipedia:WikiProject User scripts/Scripts/Unwatch: Difference between revisions

Content deleted Content added
 
m Remove legacy globals per phab:T72470 (via WP:JWB)
 
(22 intermediate revisions by 6 users not shown)
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]]. By default the links take you back to [[Special:Watchlist|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.
<pre>
 
Other versions:
// from [[User:Matthewmayer/monobook.js]]
* [[User:Ilmari_Karonen/unwatch.js]] (''legacy script'')
addOnloadHook( function addUnwatch() {
* [[User:Quarl/watchlist.js]]
if (window.___location.href.indexOf("Special:Watchlist")!=-1) {
* [[user:js//correct page, so retrieve watchlist items]]
* [[Bugzilla:424]] (if implemented)
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;
addOnloadHook( function addUnwatch() {
//create 'unwatch' element
 
unwatchelt=document.createElement('a');
// Check if we're on the watchlist
unwatchelt.setAttribute('href','/w/index.php?title='+pagename+'&action=unwatch');
if (!mw.config.get('wgCanonicalSpecialPageName') || mw.config.get('wgCanonicalSpecialPageName') != "Watchlist") return;
unwatchelt.setAttribute('title','Unwatch '+pagename);
if (!document.forms[0] || !document.forms[0].namespace) return;
unwatchelt.appendChild(document.createTextNode('(unwatch)'));
 
//add the 'unwatch' element
// Unwatch links go back to watchlist with "Removing requested items from watchlist..." message
items[i].appendChild(unwatchelt);
var query_prefix = "title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=submit&remove=1&id[]=";
}
 
// ...or...
// Unwatch links go to "Removed from watchlist" page
//var query_prefix = "action=unwatch&title=";
 
// get list of all links in content:
var itemslinks = document.getElementById('bodyContentcontent').getElementsByTagName('lia');
 
// make a static copy of the nodelist and lose the original for speed
// while we're at it, prune the uninteresting links from the list
var linksCopy = new Array ();
for (var i = 0; i <items links.length; i++) {
if (/[?&]action=history([&#]|$)/.test(links[i].href)) linksCopy.push(links[i]);
}
links = linksCopy;
}
);
 
for (var i = 0; i < links.length; i++) {
</pre>
// create unwatch link and append it after history link
var unwatch = unwatchelt=document.createElement('a');
unwatch.href = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?" + query_prefix + encodeURIComponent(links[i].title);
unwatch.title = "Unwatch "+links[i].title;
unwatcheltunwatch.appendChild(document.createTextNode('("unwatch)'"));
links[i].parentNode.insertBefore(unwatch, links[i].nextSibling);
 
// insert a delimiter between the two links
var delim = links[i].previousSibling;
delimText = (delim.nodeType == 3 ? delim.nodeValue : ""); // kluge to handle case where "diff" is unlinked
delim = document.createTextNode(delimText.replace(/^.*diff/, ""));
links[i].parentNode.insertBefore(delim, unwatch);
}
});