User:Gerbrant/edit/linksInDiff.js

From OpenWetWare
Jump to: navigation, search
hookEvent("load", function()
{
	var d = document.getElementById("wikiDiff"), i, t;
	if(!d && document.getElementById("difference"))
		d = document.getElementById("bodyContent");
	if(d)
	{
		d = d.getElementsByTagName("TABLE").item(0);
		if(d && d.className == "diff")
		{
			d = d.getElementsByTagName("TD");
			for(i = 0; i < d.length; i++)
			{
				t = d.item(i);
				switch(t.className)
				{
				case "diff-context":
				case "diff-deletedline":
				case "diff-addedline":
					t.innerHTML = t.innerHTML.replace(/\[\[((.*?)(?:\|.*?)?)\]\]/g,	function(a, b, p)
					{
						var h = /<[^>]*>/g;
						var o = '<a href="' + wgArticlePath.replace("$1", p.replace(h, "")) + '">';
						var c = '</a>';
						return "[[" + o + b.replace(h, c + "$&" + o) + c + "]]";
					});
				}
			}
		}
	}
});