Jump to content

User:Writ Keeper/Scripts/teahouseTalkbackLink.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Writ Keeper (talk | contribs) at 14:30, 19 March 2012 (addAfter). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
addOnloadHook(teahouseTalkbackLink);

function teahouseTalkbackLink()
{
	if(wgPageName == "User:Writ_Keeper/sandbox")
	{
		var contentBody = document.getElementById("mw-content-text");
		if(contentBody != null)
		{
			var nodeList = contentBody.getElementsByTagName("a");
			
			if(nodeList != null)
			{
				var i;
				for(i = 0; i < nodeList.length; i++)
				{
					var link = nodeList[i];
					if(link.href.substring(28,39) == "/User_talk:" && link.href.lastIndexOf("/") == 28)
					{
						var newLink = document.createElement("a");
						newLink.href = link.href;
						newLink.innerHTML = "TB";
						newLink.style.fontSize = "x-small";
						addAfter(newLink, link);
						i++;
					}
				}
			}
		}
	}
}
function addAfter(newNode, oldNode)
{
	if(oldNode.nextSibling != null)
	{
		oldNode.parentNode.insertBefore(newNode, oldNode.nextSibling);
	}
	else
	{
		oldNode.parentNode.appendChild(newNode);
	}
}