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

Content deleted Content added
No edit summary
m Remove legacy globals per phab:T72470 (via WP:JWB)
 
(7 intermediate revisions by 4 users not shown)
Line 2:
 
Other versions:
* [[User:Ilmari_Karonen/unwatch.js]] (''legacy script'')
 
* [[User:Ilmari_Karonen/unwatch.js]]
* [[User:Omegatron/monobook.js/unwatch.js]]
* [[User:Quarl/watchlist.js]]
* [[user:js/watchlist]]
* [[User:Matthewmayer/monobook.js]]
* [[Bugzilla:424]] (if implemented)
 
*/
<pre><nowiki> */
 
addOnloadHook(function () {
var query_prefix = "title=Special:Watchlist&action=submit&remove=1&id[]=";
//var query_prefix = "action=unwatch&title=";
 
// Check if we're on the watchlist
if (window.___location.href.indexOf("Special:Watchlist") < 0) return;
if (!mw.config.get('wgCanonicalSpecialPageName') || mw.config.get('wgCanonicalSpecialPageName') != "Watchlist") return;
if (window.___location.href.indexOf("Special:Watchlist/edit") >= 0) return;
if (!document.forms[0] || !document.forms[0].namespace) return;
 
// Unwatch links go back to watchlist with "Removing requested items from watchlist..." message
var query_prefix = "title=Special:Watchlist"+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 links = document.getElementById('content').getElementsByTagName('a');
 
// 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 < links.length; i++) {
if (/[?&]action=history([&#]|$)/.test(links[i].href)) linksCopy.push(links[i]);
}
links = linksCopy;
 
for (var i = 0; i < links.length; i++) {
// create unwatch link and append it after history link
if (links[i].href.substring(links[i].href.length-15) != '&action=history')
continue;
var unwatch = document.createElement('a');
unwatch.href = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/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:
// insert a delimiter between the two links
var delim = links[i].previousSibling;
delimdelimText = (delim.nodeType == 3 ? delim.nodeValue : ""); // kluge to handle case where "diff" is unlinked
links[i].parentNode.insertBefore(delim = document.createTextNode(delimdelimText.replace(/^.*diff/, "")), unwatch);
links[i].parentNode.insertBefore(delim, unwatch);
}
});
 
// </nowiki></pre>