User:Supdiop/sandbox.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:Supdiop/sandbox. |
//from User:MusikAnimal/responseHelper.js
// <nowiki><pre>
(function() {
var responses = {}, inline = false, indentation = ":", templateName = "", defaultPrompt = "", anew = false, unresolved;
if(document.title.indexOf("Editing User talk:Supdiop") !== -1) {
indentation = "::";
templateName = "subst:RFPR";
defaultPrompt = "Admin's name?";
responses = {
"Done" : {
code : "d",
summary : "done"
},
"Already done" : {
code : "ad|X",
summary : "already done "
},
"Not done" : {
code : "nd",
summary : "not done ",
prompt : "Reason?"
},
"Not done (exp)" : {
code : "exp|X",
summary : "not done: mainspace edit count too low ",
prompt : "Number of mainspace edits?"
},
"Not done (rvw)" : {
code : "rvw",
summary : "not done: recently requested pending changes reviewer"
},
"Not done (nrb)" : {
code : "nrb",
summary : "not done: not what rollback is for"
}
};
} else
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 {
$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:MusikAnimal/responseHelper|responseHelper]])");
};
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>