Jump to content

User:Ilmari Karonen/deletereasonlisthack.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
 // 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;
         }
     });
 }