User:Nastoshka/vector.js

/*jshint undef:true */ /*global mw, jQuery */ // NECtie: tie NEC to redlinks

// copied from User:Kephir/gadgets/nectie.js

mw.loader.using(['mediawiki.Title', 'mediawiki.Uri'], function {

var rxPage = new RegExp('^' + mw.config.get('wgArticlePath').replace(/([.+*?[\]$^])/g, '\\$1').replace('\\$1', '(.*)') + '$'); // hax

function processLink(link) { if (!/^https?:/.test(link.href)) return; var m, title, url = new mw.Uri(link.href); if (url.getAuthority === location.hostname) { if ((url.path === mw.config.get('wgScript')) && (url.query.redlink === '1') && !('editintro' in url.query)) { title = new mw.Title(url.query.title); if (title.namespace === 0) { link.href = url.extend({ 'editintro': 'User:Yair_rand/usenec' }); }		}		if (link.classList.contains("partlynew") && (m = rxPage.exec(url.path))) { title = new mw.Title(decodeURIComponent(m[1])); if (title.namespace === 0) { var qs = url.getQueryString; qs = qs && ('&' + qs); link.href = mw.config.get('wgScript') + '?action=edit&section=new&editintro=User:Yair_rand/usenec&title=' + encodeURIComponent(title.getPrefixedDb) + qs + (url.fragment ? '#' + url.fragment : ''); }		}	} }

var links = document.getElementsByTagName('a'); for (var i = 0; i < links.length; ++i) { processLink(links[i]); }

if ((mw.config.get('wgArticleId') === 0) && (mw.config.get('wgNamespaceNumber') === 0)) { var editlink = document.getElementById('ca-edit'); editlink = editlink && editlink.getElementsByTagName('a')[0]; if (editlink) editlink.href += '&editintro=User:Yair_rand/usenec'; }

var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;

if (MutationObserver) { var mo = new MutationObserver(function (events) {		for (var i = 0; i < events.length; ++i) {			if (events[i].type === 'childList') {				for (var j = 0; j < events[i].addedNodes.length; ++j) {					if (events[i].addedNodes[j].tagName === 'A')						processLink(events[i].addedNodes[j]);					if (!events[i].addedNodes[j].getElementsByTagName)						continue;					var links = events[i].addedNodes[j].getElementsByTagName('a');					for (var k = 0; k < links.length; ++k) {						processLink(links[k]);					}				}			}			if ((events[i].type === 'attributes') && (events[i].target.tagName === 'A') && (events[i].attributeName === 'href')) {				processLink(events[i].target);			} else if ((events[i].type === 'attributes') && (events[i].target.tagName === 'A') && (events[i].attributeName === 'class')) {				processLink(events[i].target);			}		}	});

mo.observe(document, {		attributes: true,		attributeFilter: ['class', 'href'],		childList: true,		subtree: true	}); }

if ((mw.config.get('wgNamespaceNumber') === 0) && (mw.config.get('wgArticleId') !== 0)) { mw.util.addPortletLink(		'p-cactions', mw.util.getUrl(mw.config.get('wgPageName'), { 'action': 'edit', 'section': 'new', 'editintro': 'User:Yair rand/usenec' }),		'+L2', 'newl2', 'Add new language heading using NEC', '+', document.getElementById('ca-history')	); }

}); // greenify by User Ruakh importScript( 'User:Ruakh/Tbot.js' ); // Backlink: User:Ruakh/Tbot.js importScript( 'w:en:User:קיפודנחש/TemplateParamWizard.js' ); // Backlink: w:en:User:קיפודנחש/TemplateParamWizard.js