// <nowiki>
$(() => {
var porty;
var tbAd = " (using [[:b:en:User:JJPMaster/talkback.js|talkback]])";
$("#bodyContent").append(`
<div id="tbDialog">
Which talkback template would you like to add?
<select name="tbName" id="tbName">
<option>Select the template</option>
<option id="Talkback">Talkback</option>
<option id="You've got mail">You've got mail</option>
</select><br />
<button type="button" id="tbUser">Add talkback</button></div>
`);
$("#tbDialog").hide();
if (mw.config.get("wgRelevantUserName") !== null) {
porty = mw.util.addPortletLink('p-cactions', '#', 'Talkback', 'pt-tb', 'Add a talkback template');
}
else return;
$(porty).click(() => $("#tbDialog").dialog({ title: "Add talkback"} ));
$("#tbUser").click(function() {
var mySelect = document.getElementById("tbName");
var critValue = mySelect.options[tbName.selectedIndex].id;
if (critValue == "Talkback") {
var talkPage = prompt("What is the name of the page with the new messages? Note: If you don't include the namespace, it will assume that the page is a user talk page.");
if (!talkPage) return;
var section = prompt("What is the section with the new messages?");
var params = {
action: 'edit',
appendtext: `\n== Talkback ==\n{{${critValue}|${talkPage}|${section}}} ~~~~\n`,
title: `User_talk:${mw.config.get("wgRelevantUserName")}`,
summary: `Adding {{${critValue}}}` + tbAd,
format: 'json'
},
api = new mw.Api();
api.postWithToken( 'csrf', params ).done( function ( data ) {
console.log( data );
} );
}
else {
params = {
action: 'edit',
appendtext: `\n== You've got mail! ==\n{{${critValue}|sig=~~~~}}\n`,
title: `User_talk:${mw.config.get("wgRelevantUserName")}`,
summary: `Adding {{${critValue}}}` + tbAd,
format: 'json'
},
api = new mw.Api();
api.postWithToken( 'csrf', params ).done( function ( data ) {
console.log( data );
} );
}
mw.notify("Talkback:\nThe talkback has been added. Redirecting to the user's talk page...");
setTimeout(() => window.location.href = window.location.href.replace(mw.config.get("wgPageName"), `User_talk:${mw.config.get("wgRelevantUserName")}`) , 2000);
});
});
// </nowiki>