User:AoV2/importScript links

From Wikipedia, the free encyclopedia

This provides a link to the source page of an importScript(), for ease of navigation. Needless to say it only works if the parameter is a string literal. ―AoV² 11:11, 27 March 2010 (UTC)

function importScript_links(){
	pre = getElementsByClassName(document, "pre", "source-javascript");
	for(i = 0; i < pre.length; i++) {
		par = getElementsByClassName(pre[i], "span", "br0");
		for(j = 0; j < par.length; j++) {
			if(par[j].innerHTML != "(") continue;
			o = par[j].previousSibling;
			if(o.nodeType != 3) continue;
			if(!o.data.match(/\bimportScript\s*$/)) continue;
			s = par[j].nextSibling;
			if(s.className != "st0") continue;
			else if(s.innerHTML.match(/^"[^"]+"$/)) q = "\"";
			else if(s.innerHTML.match(/^'[^']+'$/)) q = "\'";
			else continue;
			p = encodeURIComponent(s.childNodes[0].data.replace(q, "", "g").replace(/[_\s]+/g, "_")).replace(/%2F/g, "/");
			s.innerHTML = q + '<a href="' + wgArticlePath.replace("$1", p) + '">' + s.innerHTML.replace(q, "", "g") + '</a>' + q;
			}
		}
	}

addOnloadHook(importScript_links);