User:Ilmari Karonen/deletereasonlisthack.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. |
Documentation for this user script can be added at User:Ilmari Karonen/deletereasonlisthack. |
// Make the MediaWiki builtin deletion reason list work more like ^demon's CSD AutoReason script
if (mw.config.get('wgAction') == 'delete' && typeof(csdDeleteForm) == 'undefined') {
var csdDeleteForm = new Object (); // disable current code is Sysop.js
addOnloadHook(function () {
var wpReason = document.getElementById("wpReason");
var wpDeleteReasonList = document.getElementById("wpDeleteReasonList");
if (!wpReason || !wpDeleteReasonList) return;
addHandler(wpDeleteReasonList, "change", function () {
if (wpDeleteReasonList.selectedIndex > 0)
wpReason.value = wpDeleteReasonList.value; // copy selected value to text box
});
var fakeReason = document.createElement('input');
fakeReason.type = 'hidden';
fakeReason.name = wpDeleteReasonList.name;
fakeReason.value = 'other'; // special value which is ignored by MediaWiki
wpDeleteReasonList.parentNode.appendChild(fakeReason);
wpDeleteReasonList.name += '_disabled'; // prevent double deletion summary
// change labels to match new functionality:
var newLabels = [
{ "rowID": "wpDeleteReasonRow",
"for": "wpReason",
"newHTML": "Reason for deletion:"
},
{ "rowID": "wpDeleteReasonListRow",
"for": "wpDeleteReasonList",
"newHTML": "Common deletion reasons"
},
];
for (var i = 0; i < newLabels.length; i++) {
var row = document.getElementById(newLabels[i].rowID);
if (!row) continue;
var label = row.getElementsByTagName("label")[0];
if (label && newLabels[i].for == label.getAttribute("for"))
label.innerHTML = newLabels[i].newHTML;
}
});
}