User:Tom29739/TWLresponses.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Tom29739/TWLresponses. |
// <pre><nowiki>
/*
TWLresponses - Makes it easier to respond to TWL resource requests.
Created by User:Tom29739.
Based on https://en.wikipedia.org/wiki/User:MusikAnimal/responseHelper.js by User:MusikAnimal.
Licenced under CC BY-SA 3.0.
*/
(function() {
var responses = {}, inline = false, indentation = ":", templateName = "", defaultPrompt = "", anew = false, spi = false, unresolved;
// show shortcuts if not editing
if (!mw.config.get('wgEditMessage')) {
mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:OUP', "WP:OUP");
mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Newspapers.com', "WP:Newspapers.com");
return;
}
if (/Wikipedia:OUP/.test(mw.config.get('wgPageName')) || /Wikipedia:Newspapers.com/.test(mw.config.get('wgPageName'))) {
templateName = "User:Tom29739/TWLresponses";
inline = true;
indentation = "#:";
defaultPrompt = "Additional comments";
responses = {
"Approved" : {
code : "a",
summary : "Approved."
},
"Not approved" : {
code : "u",
prompt: "Please provide a reason for not approving",
summary : "Not approved."
},
"On hold" : {
code : "h",
prompt: "Please provide a reason for putting on hold",
summary : "On hold."
},
"In progress" : {
code : "p",
summary : "In progress."
}
};
}
var respondFn = function (e) {
var response = e.data.response;
var code = response.code, comment = "", value = "";
if (code.indexOf("|X") !== -1) {
value = prompt((response.prompt ? response.prompt : defaultPrompt) + " (optional, hit OK to omit)");
if (value === null) return false;
code = code.slice(0,(value.length ? -1 : -2)) + value;
} else if (response.prompt) {
value = prompt(response.prompt + " (optional, hit OK to omit)");
if (value === null) return false;
if (value.length) comment = " " + value;
}
var $textarea = $("#wpTextbox1");
var currentText = $textarea.val();
var responseStr = indentation + "{{" + (templateName ? templateName + "|" : "") + code + "}}" + comment + " ~~~~";
if (inline) {
var caretPos = $textarea[0].selectionStart;
$textarea.val(currentText.substring(0, caretPos) + responseStr + currentText.substring(caretPos));
} else if (spi) {
$textarea.val(
currentText.replace(/(\n----<\!---|$)/, responseStr + "\n$&")
);
} else {
$textarea.val(currentText + responseStr);
}
if (anew && !unresolved) {
var textArray = $textarea.val().split("\n");
$textarea.val(
textArray[0].replace('(Result: )','(Result: ' + (response.summary[0].toUpperCase() + response.summary.slice(1) + value).trim() + ')') +
'\n' + $textarea.val().split("\n").splice(1).join("\n")
);
}
$("#wpSummary").val($("#wpSummary").val() + (response.summary + " " + value).trim() + " (using [[User:Tom29739/TWLresponses|TWLresponses]])");
};
for (var response in responses) {
var id = responses[response].id || responses[response].code.replace(/\W/g, '');
mw.util.addPortletLink('p-navigation', 'javascript:', "(" + response + ")", "rh-" + id, responses[response].summary);
$("#rh-"+id).click({
response : responses[response]
}, respondFn);
}
}());
// </nowiki></pre>