Jump to content

User:Gerbrant/edit/linksInDiff.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$(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="' + mw.config.get('wgArticlePath').replace("$1", p.replace(h, "")) + '">';
						var c = '</a>';
						return "[[" + o + b.replace(h, c + "$&" + o) + c + "]]";
					});
				}
			}
		}
	}
});