User:JJPMaster/talkback.js
Appearance
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
- Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
- Konqueror: simply click the Reload button, or press F5;
- Opera users may need to completely clear their cache in Tools→Preferences.
Warning: Malicious code can compromise your account. Page preview will cause your web browser to execute this page's content as code under some skins, including Monobook. If you have any questions about any code you plan to add, you can ask at the appropriate reading room. |
Documentation for this user script can be added at User:JJPMaster/talkback. |
// <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>