Wikipedia:WikiProject User scripts/Scripts/Unwatch: Difference between revisions
Content deleted Content added
fix bug in enhanced mode |
Amorymeltzer (talk | contribs) m Remove legacy globals per phab:T72470 (via WP:JWB) |
||
(16 intermediate revisions by 6 users not shown) | |||
Line 1:
/
Other versions:
* [[User:Ilmari_Karonen/unwatch.js]] (''legacy script'')
* [[User:Quarl/watchlist.js]]
* [[user:js/watchlist]]
* [[Bugzilla:424]] (if implemented)
*/
addOnloadHook(function () {
//
if (!mw.config.get('wgCanonicalSpecialPageName') || mw.config.get('wgCanonicalSpecialPageName') != "Watchlist") return;
var headings = document.getElementById('content').getElementsByTagName('h4');▼
if (!document.forms[0] || !document.forms[0].namespace) return;
// Unwatch links go back to watchlist with "Removing requested items from watchlist..." message
for (var i = 0; i < headings.length; i++) {▼
var query_prefix = "title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=submit&remove=1&id[]=";
var div = headings[i].nextSibling;▼
// ...or...
// Unwatch links go to "Removed from watchlist" page
//var query_prefix = "action=unwatch&title=";
// get list of all links in content:
// make a static copy of the nodelist and lose the original for speed
var unwatch = document.createElement('a');▼
// while we're at it, prune the uninteresting links from the list
var linksCopy = new Array ();
unwatch.title = "Unwatch "+pagename;▼
unwatch.appendChild(document.createTextNode("unwatch"));▼
if (/[?&]action=history([&#]|$)/.test(links[i].href)) linksCopy.push(links[i]);
div.insertBefore(unwatch, node.nextSibling);▼
div.insertBefore(document.createTextNode("; "), unwatch);▼
}▼
for (var j = 0; j < items.length; j++) {▼
}
links = linksCopy;
});▼
// create unwatch link and append it after history link
unwatch.href = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?" + query_prefix + encodeURIComponent(links[i].title);
// insert a delimiter between the two links
delimText = (delim.nodeType == 3 ? delim.nodeValue : ""); // kluge to handle case where "diff" is unlinked
delim = document.createTextNode(delimText.replace(/^.*diff/, ""));
▲});
|