User:Ilmari Karonen/deletereasonlisthack.js

// 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; }    }); }