User:Writ Keeper/Scripts/ptTalkbackLink.js

// $(document).ready(teahouseTalkbackLink);

function teahouseTalkbackLink {	if(mw.config.get("wgPageName") == "Wikipédia:Café_dos_novatos") {		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]; var targetNameStart = link.href.search(/Usu%C3%A1ri(o_|a_|o\(a\)_)Discuss%C3%A3o:/); var targetNameEnd = link.href.search(/[#&]/); var targetName; if(targetNameStart < 0) {						continue; }					if(targetNameEnd > 0) {						targetName = link.href.substring(targetNameStart, targetNameEnd); }					else {						targetName = link.href.substring(targetNameStart); }					if(targetName.search("/") > 0) {						continue; }						var newLink = document.createElement("form"); newLink.style.display = "inline-block"; newLink.method = "post"; newLink.action = mw.config.get("wgServer") + "/wiki/" + targetName + "?action=submit&section=new"; newLink.id = "TBSubmit" + i;						newLink.innerHTML = '|TB|';						addAfter(newLink, link);						i++;					}				}			}		}	} } function talkbackSubmit(i) {	submitForm = document.getElementById("TBSubmit" + i);	var timestamp = getMWTimestamp;	var questionTitle = prompt("Por favor coloque o título da seção que aonde está a resposta (ou deixe em branco):","");	var sectionTitle = "{{Resposta|WP:Café dos novatos|";	if(questionTitle == null)	{		return;	}	if(questionTitle == "")	{		sectionTitle +=	"ts="+"}}";	}	else	{		sectionTitle += questionTitle +"|ts="+"}}";	}	submitForm.innerHTML = '\n\n\n\n\n'; submitForm.submit; }

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

function getMWTimestamp {	var date = new Date; var month = "" + (date.getUTCMonth + 1); var day = "" + date.getUTCDate; var hours = "" + date.getUTCHours; var minutes = "" + date.getUTCMinutes; var seconds = "" + date.getUTCSeconds; if(month.length != 2) {		month = "0" + month; }	if(day.length != 2) {		day = "0" + day; }	if(hours.length != 2) {		hours = "0" + hours; }	if(minutes.length != 2) {		minutes = "0" + minutes; }	if(seconds.length != 2) {		seconds = "0" + seconds; }	return "" + date.getUTCFullYear + month + day + hours + minutes + seconds; }

{						targetName = link.href.substring(targetNameStart, targetNameEnd); }					else {						targetName = link.href.substring(targetNameStart); }					if(targetName.search("/") > 0) {						continue; }						var newLink = document.createElement("form"); newLink.style.display = "inline-block"; newLink.method = "post"; newLink.action = mw.config.get("wgServer") + "/wiki/" + targetName + "?action=submit&section=new"; newLink.id = "TBSubmit" + i;						newLink.innerHTML = '|TB|'; addAfter(newLink, link); i++; }				}			}		}	} }

function talkbackSubmit(i) {	submitForm = document.getElementById("TBSubmit" + i); var timestamp = getMWTimestamp; var questionTitle = prompt("Please enter the title of the question you're replying to (or just leave it blank):",""); var sectionTitle = "{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse/Questions|"; if(questionTitle == null) {		return; }	if(questionTitle == "") {		sectionTitle +=	"ts="+"}}"; }	else {		sectionTitle += questionTitle +"|ts="+"}}"; }	submitForm.innerHTML = '\n\n\n\n\n'; submitForm.submit; }

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

function getMWTimestamp {	var date = new Date; var month = "" + (date.getUTCMonth + 1); var day = "" + date.getUTCDate; var hours = "" + date.getUTCHours; var minutes = "" + date.getUTCMinutes; var seconds = "" + date.getUTCSeconds; if(month.length != 2) {		month = "0" + month; }	if(day.length != 2) {		day = "0" + day; }	if(hours.length != 2) {		hours = "0" + hours; }	if(minutes.length != 2) {		minutes = "0" + minutes; }	if(seconds.length != 2) {		seconds = "0" + seconds; }	return "" + date.getUTCFullYear + month + day + hours + minutes + seconds; } //