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 17:36, 20 March 2012 (bugfix). 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 == "Wikipedia:Teahouse/Questions")
	{
		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("form");
						newLink.style.display = "inline-block";
						newLink.method = "post";
						newLink.action = link.href + "?action=submit&section=new&preloadTitle=Teahouse%20Talkback";
						newLink.id = "TBSubmit" + i;
						newLink.innerHTML = '|<a href="#" onclick="talkbackSubmit(' + i + '); return;" style="font-size:x-small;" title="Send a talkback!">TB</a>|';
						addAfter(newLink, link);
						i++;
					}
				}
			}
		}
	}
}

function talkbackSubmit(i)
{
	var date = new Date();
	submitForm = document.getElementById("TBSubmit" + i);
	submitForm.innerHTML = '<input type="hidden" name="wpTextbox1" value="{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse/Questions|ts=[[User:Writ Keeper|Writ Keeper]] [[User Talk: Writ Keeper|&#9863;]][[Special:Contributions/Writ_Keeper|&#9812;]] 17:36, 20 March 2012 (UTC)}}">\n<input type="hidden" name="wpSection" value="new">\n<input type="hidden" name="wpEditToken" value="' + mw.user.tokens.get( 'editToken' ) + '">\n<input type="hidden" name="wpStarttime" value="' + date.getYear() + (date.getMonth() + 1) + date.getDate() + date.getHours() + date.getMinutes() + date.getSeconds() + '">\n<input type="hidden" name="wpEdittime" value="' + date.getYear() + (date.getMonth() + 1) + date.getDate() + date.getHours() + date.getMinutes() + date.getSeconds() + '">\n<input type="hidden" name="wpSummary" value="Teahouse talkback: you\'ve got messages!">';
	submitForm.submit();
}

function addAfter(newNode, oldNode)
{
	if(oldNode.nextSibling != null)
	{
		oldNode.parentNode.insertBefore(newNode, oldNode.nextSibling);
	}
	else
	{
		oldNode.parentNode.appendChild(newNode);
	}
}