MediaWiki:SectionWatchLinks.js

// /* To use this, add this line:

importScript('MediaWiki:SectionWatchLinks.js');

* to . */

$(function {  if(mw.config.get('wgAction') !== 'view')    return;

var prevTitle = ''; var prevH = '';

var links = $('span.mw-editsection > a'); var relevantLinks = []; for(var i = 0; i < links.length; ++i) {   var link = links[i]; if(! /^[hH][1-6]$/.test(link.parentNode.parentNode.nodeName)) continue; var title = /\/w\/index.php\?title=([^&]+)&action=edit&section=T-\d+$/.exec(link.href); if(title === null) continue; title = title[1]; if(title === prevTitle) {     if(link.parentNode.parentNode.nodeName > prevH) continue; }   else {     prevTitle = title; prevH = link.parentNode.parentNode.nodeName; }   relevantLinks.push(link); }

var watchMsg = 'watch'; var unwatchMsg = 'unwatch';

for(var i = 0; i < relevantLinks.length; ++i) {   var link = relevantLinks[i]; var title = link.getAttribute('title'); var pagename = /\/w\/index.php\?title=([^&]+)/.exec(link.href)[1];

var nodes = [     newNode('a', { href: '/w/index.php?title='+pagename+'&action=watch', title: title }, watchMsg), document.createTextNode(' \xB7 '), newNode('a', { href: '/w/index.php?title='+pagename+'&action=unwatch', title: title }, unwatchMsg), document.createTextNode(' \xB7 ') ];

for(var j = 0; j < nodes.length; ++j) link.parentNode.insertBefore(nodes[j], link); } });