User:Falkirksnh/messages.js

//standard onloadhook $(document).ready(messageMenu);

function messageMenu {

if ( mw.config.get( 'wgCanonicalNamespace' ) === 'User_talk') { //Continue only on User_talk pages. { var welcomeLink = mw.util.addPortletLink("p-cactions", "#", "Welcome", "mw-welcome", "Add a welcome message", null, "#ca-move"); $(WelcomeLink).click(postWelcome); } } function postWelcome { invitationBody = " "; //If you want to change what the invitation section is titled, edit the words below within the doublequote (but don't take out the doublequote!) invitationSectionTitle = "Welcome!"; var linkArray = document.getElementById("mw-content-text").getElementsByTagName("a"); var i;	for(i = 0; i < linkArray.length; i++) {		if(linkArray[i].href.search("Wikipedia:Teahouse") > -1) {			if(confirm("Someone may have already invited this person to the Teahouse!\n\nAre you sure you want to continue?")) {				break; }			else return; }	}	var data = { format : 'json', action : 'edit', minor : false, title : getURL, text : invitationBody, section : 'new', summary : invitationSectionTitle, 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.wikiGetlink(page);                               alert("Done.");			} 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");		}	}); }