User:DannyS712/TeahouseTB.js

//Copied from [[User:Abelmoschus Esculentus/TeahouseTB.js]

//

$(function() {

var namespace = mw.config.get('wgNamespaceNumber'),

pageName = mw.config.get('wgPageName'),

myUserName = mw.config.get('wgUserName'),

targetUserName = mw.config.get('wgRelevantUserName');

api = new mw.Api();

mw.loader.using( ['mediawiki.util'], function() {

if([-1,0,2,3].indexOf(namespace) !== -1 && myUserName != targetUserName && targetUserName != null) {

mw.util.addPortletLink(

'p-cactions', 'javascript:void(0)',

'Teahouse Talkback',

'aca-tb', 'Leave a message to the user when you have answered their question'

);

$('#aca-tb').on('click', function() {

var section = prompt( "Section (leave blank if you are too lazy to type it): ","");

if (section != null) {

templateUser(section);

}

});

}

});

function templateUser(section) {

api.postWithToken( "edit", {

action: "edit",

section: 'new',

watchlist: "unwatch",

sectiontitle: "Teahouse talkback: you've got messages!",

summary: "Notifying user (THTB)",

text: "{{WP:Teahouse/Teahouse talkback|WP:Teahouse|" + section + "|ts=~~~~}}",

title: "User talk:"+targetUserName

}).then(function(editData) {

alert("Successfully notified user");

},function(error) {

alert("An error occurred. Please try again.");

});

}

});

//