User:Technical 13/Scripts/teahouseTalkbackLink.js

// function teahouseTalkbackLink { if($("#mw-content-text").length > 0) { var $nodeList = $('a[title^="User talk:"]'), pdne = ' (page does not exist)'; if($nodeList !== null) { var i;			for( i = 0; i < $nodeList.length; i++) { var $link = $($nodeList[i]); $newLink = $('TB'); $newLink.click(function(e) {					talkbackSubmit($(this).attr('href').substr(1), this.id)				}); $($link).after($newLink); $($link).after($('C')); $($link).after("|"); }		}	$('a[title="Send a talkback!"]').tipsy({html: true}).before("|").after("|"); } } function talkbackSubmit(page, id) { var sectionTitle = $('#' + id).parentsUntil('div#thq-content').prev('h2').find('span.mw-headline').text; var questionTitle = prompt("Please enter the title of the question you're replying to (or just leave it blank):", sectionTitle), sectionTitle = "{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse/Questions|"; if (questionTitle === null) { $("#"+id).attr("title", 'You canceled the talkback!').tipsy("show"); return; }	else if (questionTitle === "") { sectionTitle += "ts=~}}"; } 	else { sectionTitle += questionTitle + "|ts=~}}"; }	var data = { format : 'json', action : 'edit', minor : false, title : page, text : sectionTitle, section : 'new', summary : "Teahouse talkback: you've got messages!", token : mw.user.tokens.get('editToken') };	$.ajax({		url : mw.util.wikiScript('api'),		type : 'POST',		dataType : 'json',		data : data,		success : function(data) {			if(data && data.edit && data.edit.result && data.edit.result === 'Success') {				//window.location = mw.util.getUrl(page);                               alert("Talkback posted!");			} else {				$("#"+id).attr("title", 'There was an error requesting the page edit. Code: ' + data.error.code + '": ' + data.error.info).tipsy("show");			}		},		error : function {			$("#"+id).attr("title", 'There was an error using AJAX to edit the page.').tipsy("show");		}	}); } if(mw.config.get('wgPageName') === "Wikipedia:Teahouse/Questions") {	mw.loader.using( 'jquery.tipsy', function { $(teahouseTalkbackLink); } );} //