User:Gerbrant/edit/linksInDiff.js

From OpenWetWare

Jump to: navigation, search

Note - After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

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 + "]]";
					});
				}
			}
		}
	}
});
Personal tools